File tree 3 files changed +14
-2
lines changed
3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -564,6 +564,7 @@ public void TestCreateConversionEventNoAttributesWithInvalidValue()
564
564
{ "timestamp" , timeStamp } ,
565
565
{ "uuid" , guid } ,
566
566
{ "key" , "purchase" } ,
567
+ { "revenue" , 42 } ,
567
568
{ "tags" ,
568
569
new Dictionary < string , object >
569
570
{
Original file line number Diff line number Diff line change @@ -35,12 +35,16 @@ public void TestGetRevenueValue()
35
35
{
36
36
var expectedValue = 42 ;
37
37
var expectedValue2 = 100 ;
38
+ var expectedValueString = 123 ;
38
39
var validTag = new Dictionary < string , object > ( ) {
39
40
{ "revenue" , 42 }
40
41
} ;
41
42
var validTag2 = new Dictionary < string , object > ( ) {
42
43
{ "revenue" , 100 }
43
44
} ;
45
+ var validTagStringValue = new Dictionary < string , object > ( ) {
46
+ { "revenue" , "123" }
47
+ } ;
44
48
45
49
var invalidTag = new Dictionary < string , object > ( ) {
46
50
{ "abc" , 42 }
@@ -51,16 +55,22 @@ public void TestGetRevenueValue()
51
55
var invalidValue = new Dictionary < string , object > ( ) {
52
56
{ "revenue" , 42.5 }
53
57
} ;
58
+ var invalidTagNonRevenue = new Dictionary < string , object > ( )
59
+ {
60
+ { "non-revenue" , 123 }
61
+ } ;
54
62
55
63
// Invalid data.
56
64
Assert . Null ( EventTagUtils . GetRevenueValue ( null ) ) ;
57
65
Assert . Null ( EventTagUtils . GetRevenueValue ( invalidTag ) ) ;
58
66
Assert . Null ( EventTagUtils . GetRevenueValue ( nullValue ) ) ;
59
67
Assert . Null ( EventTagUtils . GetRevenueValue ( invalidValue ) ) ;
68
+ Assert . Null ( EventTagUtils . GetRevenueValue ( invalidTagNonRevenue ) ) ;
60
69
61
70
// Valid data.
62
71
Assert . AreEqual ( EventTagUtils . GetRevenueValue ( validTag ) , expectedValue ) ;
63
72
Assert . AreEqual ( EventTagUtils . GetRevenueValue ( validTag2 ) , expectedValue2 ) ;
73
+ Assert . AreEqual ( EventTagUtils . GetRevenueValue ( validTagStringValue ) , expectedValueString ) ;
64
74
}
65
75
66
76
[ Test ]
Original file line number Diff line number Diff line change @@ -10,13 +10,14 @@ public class EventTagUtils
10
10
11
11
public static object GetRevenueValue ( Dictionary < string , object > eventTags )
12
12
{
13
+ int result = 0 ;
13
14
if ( eventTags == null
14
15
|| ! eventTags . ContainsKey ( REVENUE_EVENT_METRIC_NAME )
15
16
|| eventTags [ REVENUE_EVENT_METRIC_NAME ] == null
16
- || ! ( eventTags [ REVENUE_EVENT_METRIC_NAME ] is int ) )
17
+ || ! int . TryParse ( eventTags [ REVENUE_EVENT_METRIC_NAME ] . ToString ( ) , out result ) )
17
18
return null ;
18
19
19
- return eventTags [ REVENUE_EVENT_METRIC_NAME ] ;
20
+ return result ;
20
21
}
21
22
22
23
public static object GetNumericValue ( Dictionary < string , object > eventTags , ILogger logger = null )
You can’t perform that action at this time.
0 commit comments