|
1 | 1 | using QueueIT.KnownUserV3.SDK.IntegrationConfig; |
2 | | -using Rhino.Mocks; |
3 | 2 | using System; |
4 | 3 | using System.Collections.Generic; |
5 | 4 | using System.Collections.Specialized; |
6 | | -using System.Web; |
7 | 5 | using Xunit; |
8 | 6 |
|
9 | 7 | namespace QueueIT.KnownUserV3.SDK.Tests.IntegrationConfig |
@@ -95,28 +93,28 @@ public void Evaluate_Test() |
95 | 93 | Operator = ComparisonOperatorType.Contains, |
96 | 94 | ValueToCompare = "1" |
97 | 95 | }; |
98 | | - var cookieCollection = new System.Web.HttpCookieCollection() { }; |
99 | | - Assert.False(CookieValidatorHelper.Evaluate(triggerPart, cookieCollection)); |
| 96 | + var request = new KnownUserTest.MockHttpRequest(); |
| 97 | + Assert.False(CookieValidatorHelper.Evaluate(triggerPart, request)); |
100 | 98 |
|
101 | | - cookieCollection.Add(new System.Web.HttpCookie("c5", "5")); |
102 | | - cookieCollection.Add(new System.Web.HttpCookie("c1", "1")); |
103 | | - cookieCollection.Add(new System.Web.HttpCookie("c2", "test")); |
104 | | - Assert.True(CookieValidatorHelper.Evaluate(triggerPart, cookieCollection)); |
| 99 | + request.CookiesValue.Add("c5", "5"); |
| 100 | + request.CookiesValue.Add("c1", "1"); |
| 101 | + request.CookiesValue.Add("c2", "test"); |
| 102 | + Assert.True(CookieValidatorHelper.Evaluate(triggerPart, request)); |
105 | 103 |
|
106 | 104 | triggerPart.ValueToCompare = "5"; |
107 | | - Assert.False(CookieValidatorHelper.Evaluate(triggerPart, cookieCollection)); |
| 105 | + Assert.False(CookieValidatorHelper.Evaluate(triggerPart, request)); |
108 | 106 |
|
109 | 107 |
|
110 | 108 | triggerPart.ValueToCompare = "Test"; |
111 | 109 | triggerPart.IsIgnoreCase = true; |
112 | 110 | triggerPart.CookieName = "c2"; |
113 | | - Assert.True(CookieValidatorHelper.Evaluate(triggerPart, cookieCollection)); |
| 111 | + Assert.True(CookieValidatorHelper.Evaluate(triggerPart, request)); |
114 | 112 |
|
115 | 113 | triggerPart.ValueToCompare = "Test"; |
116 | 114 | triggerPart.IsIgnoreCase = true; |
117 | 115 | triggerPart.IsNegative = true; |
118 | 116 | triggerPart.CookieName = "c2"; |
119 | | - Assert.False(CookieValidatorHelper.Evaluate(triggerPart, cookieCollection)); |
| 117 | + Assert.False(CookieValidatorHelper.Evaluate(triggerPart, request)); |
120 | 118 | } |
121 | 119 | } |
122 | 120 |
|
@@ -273,11 +271,10 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched() |
273 | 271 |
|
274 | 272 | var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); |
275 | 273 |
|
276 | | - var httpRequestMock = MockRepository.GenerateMock<HttpRequestBase>(); |
277 | | - httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection()); |
278 | | - httpRequestMock.Stub(r => r.UserAgent).Return(string.Empty); |
279 | 274 |
|
280 | | - Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock) == null); |
| 275 | + |
| 276 | + Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, |
| 277 | + new KnownUserTest.MockHttpRequest()) == null); |
281 | 278 | } |
282 | 279 |
|
283 | 280 | [Fact] |
@@ -321,10 +318,8 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_Matched() |
321 | 318 |
|
322 | 319 | var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); |
323 | 320 |
|
324 | | - var httpRequestMock = MockRepository.GenerateMock<HttpRequestBase>(); |
325 | | - httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection() { new HttpCookie("c1", "Value1") }); |
326 | | - httpRequestMock.Stub(r => r.UserAgent).Return(string.Empty); |
327 | 321 |
|
| 322 | + var httpRequestMock = new KnownUserTest.MockHttpRequest() { CookiesValue = new NameValueCollection() { { "c1", "Value1" } } }; |
328 | 323 | Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock).Name == "integration1"); |
329 | 324 | } |
330 | 325 |
|
@@ -376,10 +371,11 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched_UserAgent() |
376 | 371 |
|
377 | 372 | var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); |
378 | 373 |
|
379 | | - var httpRequestMock = MockRepository.GenerateMock<HttpRequestBase>(); |
380 | | - httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection() { new HttpCookie("c1", "Value1") }); |
381 | | - httpRequestMock.Stub(r => r.UserAgent).Return("bot.html google.com googlebot test"); |
382 | | - |
| 374 | + var httpRequestMock = new KnownUserTest.MockHttpRequest() |
| 375 | + { |
| 376 | + CookiesValue = new NameValueCollection() { { "c1", "Value1" } }, |
| 377 | + UserAgent = "bot.html google.com googlebot test" |
| 378 | + }; |
383 | 379 | Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock) == null); |
384 | 380 | } |
385 | 381 |
|
@@ -432,12 +428,12 @@ public void GetMatchedIntegrationConfig_OneTrigger_And_NotMatched_HttpHeader() |
432 | 428 |
|
433 | 429 | var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); |
434 | 430 |
|
435 | | - var httpRequestMock = MockRepository.GenerateMock<HttpRequestBase>(); |
436 | | - httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection() { new HttpCookie("c1", "Value1") }); |
437 | | - var httpHeaders = new NameValueCollection(); |
438 | | - httpHeaders.Add("Akamai-bot", "bot"); |
439 | | - httpRequestMock.Stub(r => r.Headers).Return(httpHeaders); |
440 | 431 |
|
| 432 | + var httpRequestMock = new KnownUserTest.MockHttpRequest() |
| 433 | + { |
| 434 | + CookiesValue = new NameValueCollection() { { "c1", "Value1" } }, |
| 435 | + Headers = new NameValueCollection() { { "Akamai-bot", "bot" } } |
| 436 | + }; |
441 | 437 | Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock) == null); |
442 | 438 | } |
443 | 439 |
|
@@ -481,10 +477,11 @@ public void GetMatchedIntegrationConfig_OneTrigger_Or_NotMatched() |
481 | 477 |
|
482 | 478 | var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); |
483 | 479 |
|
484 | | - var httpRequestMock = MockRepository.GenerateMock<HttpRequestBase>(); |
485 | | - httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection() { new HttpCookie("c2", "value1") }); |
486 | | - httpRequestMock.Stub(r => r.UserAgent).Return(string.Empty); |
487 | 480 |
|
| 481 | + var httpRequestMock = new KnownUserTest.MockHttpRequest() |
| 482 | + { |
| 483 | + CookiesValue = new NameValueCollection() { { "c2", "value1" } } |
| 484 | + }; |
488 | 485 | Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock) == null); |
489 | 486 | } |
490 | 487 |
|
@@ -526,10 +523,10 @@ public void GetMatchedIntegrationConfig_OneTrigger_Or_Matched() |
526 | 523 |
|
527 | 524 |
|
528 | 525 | var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); |
529 | | - var httpRequestMock = MockRepository.GenerateMock<HttpRequestBase>(); |
530 | | - httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection() { new HttpCookie("c1", "value1") }); |
531 | | - httpRequestMock.Stub(r => r.UserAgent).Return(string.Empty); |
532 | | - |
| 526 | + var httpRequestMock = new KnownUserTest.MockHttpRequest() |
| 527 | + { |
| 528 | + CookiesValue = new NameValueCollection() { { "c1", "value1" } } |
| 529 | + }; |
533 | 530 | Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock).Name == "integration1"); |
534 | 531 | } |
535 | 532 |
|
@@ -580,10 +577,7 @@ public void GetMatchedIntegrationConfig_TwoTriggers_Matched() |
580 | 577 |
|
581 | 578 | var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); |
582 | 579 |
|
583 | | - var httpRequestMock = MockRepository.GenerateMock<HttpRequestBase>(); |
584 | | - httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection()); |
585 | | - httpRequestMock.Stub(r => r.UserAgent).Return(string.Empty); |
586 | | - |
| 580 | + var httpRequestMock = new KnownUserTest.MockHttpRequest(); |
587 | 581 | Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock).Name == "integration1", string.Empty); |
588 | 582 | } |
589 | 583 |
|
@@ -633,10 +627,7 @@ public void GetMatchedIntegrationConfig_TwoTriggers_NotMatched() |
633 | 627 |
|
634 | 628 | var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); |
635 | 629 |
|
636 | | - var httpRequestMock = MockRepository.GenerateMock<HttpRequestBase>(); |
637 | | - httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection()); |
638 | | - httpRequestMock.Stub(r => r.UserAgent).Return(string.Empty); |
639 | | - |
| 630 | + var httpRequestMock = new KnownUserTest.MockHttpRequest(); |
640 | 631 | Assert.True(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock) == null); |
641 | 632 | } |
642 | 633 |
|
@@ -712,10 +703,10 @@ public void GetMatchedIntegrationConfig_ThreeIntegrationsInOrder_SecondMatched() |
712 | 703 |
|
713 | 704 | var url = new Uri("http://test.tesdomain.com:8080/test?q=2"); |
714 | 705 |
|
715 | | - var httpRequestMock = MockRepository.GenerateMock<HttpRequestBase>(); |
716 | | - httpRequestMock.Stub(r => r.Cookies).Return(new HttpCookieCollection() { new HttpCookie("c1") { Value = "Value1" } }); |
717 | | - httpRequestMock.Stub(r => r.UserAgent).Return(string.Empty); |
718 | | - |
| 706 | + var httpRequestMock = new KnownUserTest.MockHttpRequest() |
| 707 | + { |
| 708 | + CookiesValue = new NameValueCollection() { { "c1", "Value1" } } |
| 709 | + }; |
719 | 710 | Assert.False(testObject.GetMatchedIntegrationConfig(customerIntegration, url.AbsoluteUri, httpRequestMock).Name == "integration2"); |
720 | 711 | } |
721 | 712 | } |
|
0 commit comments