@@ -11,45 +11,126 @@ public class HttpRepositoryTests
1111 string applicationClientSecret = "testApplicationSecret" ;
1212 string tenant = "testTenant" ;
1313
14- [ Fact ( Skip = "Valid Client-Id and Client-Secret requried." ) ]
14+ [ Fact ]
1515 public async void GenericFluentEventQueryTest ( )
1616 {
17- var connection = new Connection ( applicationClientId , applicationClientSecret , tenant ) ;
18- var environment = connection . GetEnvironmentsAsync ( ) . Result . FirstOrDefault ( ) ;
17+ //var connection = new Connection(applicationClientId, applicationClientSecret, tenant);
18+ //var environment = connection.GetEnvironmentsAsync().Result.FirstOrDefault();
19+
20+ var environment = new Environment ( "TestFqdn" , "TestAccessToken" ) ;
1921
2022 var from = new DateTime ( 2017 , 12 , 23 , 12 , 0 , 0 , DateTimeKind . Utc ) ;
2123 var to = new DateTime ( 2018 , 10 , 23 , 12 , 0 , 0 , DateTimeKind . Utc ) ;
2224
23- var result = await new GenericFluentEventQuery < TestType1 > ( "Test" , Search . Span ( from , to ) , Limit . CreateLimit ( Limit . Take , 10 ) , environment , new EventWebSocketRepository ( new HttpRepository ( environment ) ) )
24- . Where ( x => x . Value == 10 )
25+ var result = await new GenericFluentEventQuery < EmailTest > ( "Test" , Search . Span ( from , to ) , Limit . CreateLimit ( Limit . Take , 10 ) , environment , new EventWebSocketRepository ( new MockHttpRepository ( _eventsResult ) ) ) //new HttpRepository(environment )
26+ . Where ( x => x . ip == "127.0.0.1" )
2527 . ExecuteAsync ( ) ;
2628
2729 Assert . NotNull ( result ) ;
2830 }
2931
30- [ Fact ( Skip = "Valid Client-Id and Client-Secret requried." ) ]
32+ [ Fact ]
3133 public async void AggregateQueryTest ( )
3234 {
33- var connection = new Connection ( applicationClientId , applicationClientSecret , tenant ) ;
34- var environment = connection . GetEnvironmentsAsync ( ) . Result . FirstOrDefault ( ) ;
35+ //var connection = new Connection(applicationClientId, applicationClientSecret, tenant);
36+ //var environment = connection.GetEnvironmentsAsync().Result.FirstOrDefault();
37+
38+ var environment = new Environment ( "TestFqdn" , "TestAccessToken" ) ;
3539
3640 var from = new DateTime ( 2017 , 12 , 23 , 12 , 0 , 0 , DateTimeKind . Utc ) ;
3741 var to = new DateTime ( 2018 , 10 , 23 , 12 , 0 , 0 , DateTimeKind . Utc ) ;
3842
39- var result = await new GenericFluentAggregateQuery < TestType1 > ( "Test" , Search . Span ( from , to ) , environment , new AggregateWebSocketRepository ( new HttpRepository ( environment ) ) )
40- . Select ( builder => builder . UniqueValues ( x => x . DataType , 10 ,
41- builder . DateHistogram ( x => x . Date , Breaks . InDays ( 1 ) ,
42- new
43- {
44- Maximum = builder . Maximum ( x => x . Value ) ,
45- Minmum = builder . Minimum ( x => x . Value )
46- } ) ) )
47- . Where ( x => x . Value > 5 )
43+ var result = await new GenericFluentAggregateQuery < EmailTest > ( "Test" , Search . Span ( from , to ) , environment , new AggregateWebSocketRepository ( new MockHttpRepository ( _aggregateResults ) ) ) //new HttpRepository(environment)
44+ . Select ( builder => builder . UniqueValues ( x => x . ip , 10 , new { Count = builder . Count ( ) } ) )
45+ . Where ( x => x . ip == "127.0.0.1" )
4846 . ExecuteAsync ( ) ;
4947
50- var uniqueValues = result . First ( ) ;
51-
52- Assert . NotNull ( uniqueValues ) ;
48+ Assert . NotNull ( result ) ;
5349 }
50+
51+ private string _eventsResult = @"{
52+ ""warnings"": [],
53+ ""events"": [
54+ {
55+ ""schema"": {
56+ ""rid"": 0,
57+ ""$esn"": ""source1"",
58+ ""properties"": [
59+ {
60+ ""name"": ""email"",
61+ ""type"": ""String""
62+ },
63+ {
64+ ""name"": ""ip"",
65+ ""type"": ""String""
66+ },
67+ {
68+ ""name"": ""useragent"",
69+ ""type"": ""String""
70+ }
71+ ]
72+ },
73+ ""$ts"": ""2018-10-18T11:30:36Z"",
74+ ""values"": [
75+ ""test1@mail.com"",
76+ ""127.0.0.1"",
77+ ""IE""
78+ ]
79+ },
80+ {
81+ ""schemaRid"": 0,
82+ ""$ts"": ""2018-10-18T11:30:36Z"",
83+ ""values"": [
84+ ""test2@mail.com"",
85+ ""127.0.0.1"",
86+ ""FF""
87+ ]
88+ },
89+ {
90+ ""schemaRid"": 0,
91+ ""$ts"": ""2018-10-18T11:30:36Z"",
92+ ""values"": [
93+ ""test3@mail.com"",
94+ ""127.0.0.1"",
95+ ""IE""
96+ ]
97+ }
98+ ]
99+ }" ;
100+
101+ private string _aggregateResults = @"{
102+ ""aggregates"": [
103+ {
104+ ""dimension"": [
105+ null,
106+ ""EmailOpened"",
107+ ""EmailSent""
108+ ],
109+ ""measures"": [
110+ [
111+ 10.0
112+ ],
113+ [
114+ 20.0
115+ ],
116+ [
117+ 200.0
118+ ]
119+ ]
120+ }
121+ ],
122+ ""warnings"": []
123+ }" ;
124+
125+ }
126+
127+ public class EmailTest
128+ {
129+ [ ChronologicalEventField ( "email" ) ]
130+ public string email { get ; set ; }
131+ [ ChronologicalEventField ( "ip" ) ]
132+ public string ip { get ; set ; }
133+ [ ChronologicalEventField ( "useragent" ) ]
134+ public string useragent { get ; set ; }
54135 }
55136}
0 commit comments