public void Evaluate_Test() { var triggerPart = new TriggerPart() { CookieName = "c1", Operator = ComparisonOperatorType.Contains, ValueToCompare = "1" }; var cookieCollection = new System.Web.HttpCookieCollection() { }; Assert.False(CookieValidatorHelper.Evaluate(triggerPart, cookieCollection)); cookieCollection.Add(new System.Web.HttpCookie("c5", "5")); cookieCollection.Add(new System.Web.HttpCookie("c1", "1")); cookieCollection.Add(new System.Web.HttpCookie("c2", "test")); Assert.True(CookieValidatorHelper.Evaluate(triggerPart, cookieCollection)); triggerPart.ValueToCompare = "5"; Assert.False(CookieValidatorHelper.Evaluate(triggerPart, cookieCollection)); triggerPart.ValueToCompare = "Test"; triggerPart.IsIgnoreCase = true; triggerPart.CookieName = "c2"; Assert.True(CookieValidatorHelper.Evaluate(triggerPart, cookieCollection)); triggerPart.ValueToCompare = "Test"; triggerPart.IsIgnoreCase = true; triggerPart.IsNegative = true; triggerPart.CookieName = "c2"; Assert.False(CookieValidatorHelper.Evaluate(triggerPart, cookieCollection)); }
public void Evaluate_Test() { var triggerPart = new TriggerPart() { HttpHeaderName = "c1", Operator = ComparisonOperatorType.Contains, ValueToCompare = "1" }; var httpHeaders = new NameValueCollection() { }; Assert.False(HttpHeaderValidatorHelper.Evaluate(triggerPart, httpHeaders)); httpHeaders.Add("c5", "5"); httpHeaders.Add("c1", "1"); httpHeaders.Add("c2", "test"); Assert.True(HttpHeaderValidatorHelper.Evaluate(triggerPart, httpHeaders)); triggerPart.ValueToCompare = "5"; Assert.False(HttpHeaderValidatorHelper.Evaluate(triggerPart, httpHeaders)); triggerPart.ValueToCompare = "Test"; triggerPart.IsIgnoreCase = true; triggerPart.HttpHeaderName = "c2"; Assert.True(HttpHeaderValidatorHelper.Evaluate(triggerPart, httpHeaders)); triggerPart.ValueToCompare = "Test"; triggerPart.IsIgnoreCase = true; triggerPart.IsNegative = true; triggerPart.HttpHeaderName = "c2"; Assert.False(HttpHeaderValidatorHelper.Evaluate(triggerPart, httpHeaders)); }
public void Evaluate_Test() { var triggerPart = new TriggerPart() { UrlPart = UrlPartType.PageUrl, Operator = ComparisonOperatorType.Contains, ValueToCompare = "http://test.tesdomain.com:8080/test?q=1" }; Assert.False(UrlValidatorHelper.Evaluate(triggerPart, "http://test.tesdomain.com:8080/test?q=2")); triggerPart.ValueToCompare = "/Test/t1"; triggerPart.UrlPart = UrlPartType.PagePath; triggerPart.Operator = ComparisonOperatorType.EqualS; triggerPart.IsIgnoreCase = true; Assert.True(UrlValidatorHelper.Evaluate(triggerPart, "http://test.tesdomain.com:8080/test/t1?q=2&y02")); triggerPart.UrlPart = UrlPartType.HostName; triggerPart.ValueToCompare = "test.tesdomain.com"; triggerPart.Operator = ComparisonOperatorType.Contains; Assert.True(UrlValidatorHelper.Evaluate(triggerPart, "http://m.test.tesdomain.com:8080/test?q=2")); triggerPart.UrlPart = UrlPartType.HostName; triggerPart.ValueToCompare = "test.tesdomain.com"; triggerPart.IsNegative = true; triggerPart.Operator = ComparisonOperatorType.Contains; Assert.False(UrlValidatorHelper.Evaluate(triggerPart, "http://m.test.tesdomain.com:8080/test?q=2")); }
public void Evaluate_Test() { var triggerPart = new TriggerPart { CookieName = "c1", Operator = ComparisonOperatorType.Contains, ValueToCompare = "1" }; var request = new KnownUserTest.MockHttpRequest(); Assert.False(CookieValidatorHelper.Evaluate(triggerPart, request)); request.CookiesValue.Add("c5", "5"); request.CookiesValue.Add("c1", "1"); request.CookiesValue.Add("c2", "test"); Assert.True(CookieValidatorHelper.Evaluate(triggerPart, request)); triggerPart.ValueToCompare = "5"; Assert.False(CookieValidatorHelper.Evaluate(triggerPart, request)); triggerPart.ValueToCompare = "Test"; triggerPart.IsIgnoreCase = true; triggerPart.CookieName = "c2"; Assert.True(CookieValidatorHelper.Evaluate(triggerPart, request)); triggerPart.ValueToCompare = "Test"; triggerPart.IsIgnoreCase = true; triggerPart.IsNegative = true; triggerPart.CookieName = "c2"; Assert.False(CookieValidatorHelper.Evaluate(triggerPart, request)); }
public void Evaluate_Test() { var triggerPart = new TriggerPart { Operator = ComparisonOperatorType.Contains, ValueToCompare = "test body" }; var request = new KnownUserTest.MockHttpRequest(); Assert.False(RequestBodyValidatorHelper.Evaluate(triggerPart, request.GetRequestBodyAsString())); request.Body = "test body"; Assert.True(RequestBodyValidatorHelper.Evaluate(triggerPart, request.GetRequestBodyAsString())); triggerPart.ValueToCompare = "ZZZ"; Assert.False(RequestBodyValidatorHelper.Evaluate(triggerPart, request.GetRequestBodyAsString())); triggerPart.ValueToCompare = "Test"; triggerPart.IsIgnoreCase = true; Assert.True(RequestBodyValidatorHelper.Evaluate(triggerPart, request.GetRequestBodyAsString())); triggerPart.ValueToCompare = "Test"; triggerPart.IsIgnoreCase = true; triggerPart.IsNegative = true; Assert.False(RequestBodyValidatorHelper.Evaluate(triggerPart, request.GetRequestBodyAsString())); triggerPart.ValueToCompare = "Test"; triggerPart.IsIgnoreCase = true; triggerPart.IsNegative = true; Assert.False(RequestBodyValidatorHelper.Evaluate(triggerPart, request.GetRequestBodyAsString())); }
public void ValidateRequestByIntegrationConfig_Test() { // Arrange UserInQueueServiceMock mock = new UserInQueueServiceMock(); KnownUser._UserInQueueService = (mock); TriggerPart triggerPart = new TriggerPart(); triggerPart.Operator = "Contains"; triggerPart.ValueToCompare = "event1"; triggerPart.UrlPart = "PageUrl"; triggerPart.ValidatorType = "UrlValidator"; triggerPart.IsNegative = false; triggerPart.IsIgnoreCase = true; TriggerModel trigger = new TriggerModel(); trigger.LogicalOperator = "And"; trigger.TriggerParts = new TriggerPart[] { triggerPart }; IntegrationConfigModel config = new IntegrationConfigModel(); config.Name = "event1action"; //config.ActionType = "Queue"; config.EventId = "event1"; config.CookieDomain = ".test.com"; config.LayoutName = "Christmas Layout by Queue-it"; config.Culture = "da-DK"; config.ExtendCookieValidity = true; config.CookieValidityMinute = 20; config.Triggers = new TriggerModel[] { trigger }; config.QueueDomain = "knownusertest.queue-it.net"; config.RedirectLogic = "AllowTParameter"; config.ForcedTargetUrl = ""; CustomerIntegration customerIntegration = new CustomerIntegration(); customerIntegration.Integrations = new IntegrationConfigModel[] { config }; customerIntegration.Version = 3; // Act KnownUser.ValidateRequestByIntegrationConfig("http://test.com?event1=true", "queueitToken", customerIntegration, "customerId", "secretKey"); // Assert Assert.True(mock.validateRequestCalls.Count == 1); Assert.Equal("http://test.com?event1=true", mock.validateRequestCalls[0][0]); Assert.Equal("queueitToken", mock.validateRequestCalls[0][1]); Assert.Equal(".test.com:Christmas Layout by Queue-it:da-DK:event1:knownusertest.queue-it.net:true:20:3", mock.validateRequestCalls[0][2]); Assert.Equal("customerId", mock.validateRequestCalls[0][3]); Assert.Equal("secretKey", mock.validateRequestCalls[0][4]); }
public object GetTriggerValue(int index) { TriggerPart part = triggerParts[index]; switch (part.type) { case TriggerTypes.Bool: return(part.triggerBool); case TriggerTypes.Int: return(part.triggerInt); case TriggerTypes.Float: return(part.triggerFloat); case TriggerTypes.Double: return(part.triggerDouble); case TriggerTypes.String: return(part.triggerString); } return(null); }
public object GetDefaultValue(int index) { TriggerPart part = triggerParts[index]; switch (part.type) { case TriggerTypes.Bool: return(part.defaultBool); case TriggerTypes.Int: return(part.defaultInt); case TriggerTypes.Float: return(part.defaultFloat); case TriggerTypes.Double: return(part.defaultDouble); case TriggerTypes.String: return(part.defaultString); } return(null); }
public void Evaluate_Test() { var triggerPart = new TriggerPart() { Operator = ComparisonOperatorType.Contains, ValueToCompare = "googlebot" }; Assert.False(UserAgentValidatorHelper.Evaluate(triggerPart, "Googlebot sample useraagent")); triggerPart.ValueToCompare = "googlebot"; triggerPart.Operator = ComparisonOperatorType.EqualS; triggerPart.IsIgnoreCase = true; triggerPart.IsNegative = true; Assert.True(UserAgentValidatorHelper.Evaluate(triggerPart, "oglebot sample useraagent")); triggerPart.ValueToCompare = "googlebot"; triggerPart.Operator = ComparisonOperatorType.Contains; triggerPart.IsIgnoreCase = false; triggerPart.IsNegative = true; Assert.False(UserAgentValidatorHelper.Evaluate(triggerPart, "googlebot")); triggerPart.ValueToCompare = "googlebot"; triggerPart.IsIgnoreCase = true; triggerPart.IsNegative = false; triggerPart.Operator = ComparisonOperatorType.Contains; Assert.True(UserAgentValidatorHelper.Evaluate(triggerPart, "Googlebot")); triggerPart.ValueToCompare = null; triggerPart.ValuesToCompare = new string[] { "googlebot" }; triggerPart.IsIgnoreCase = true; triggerPart.IsNegative = false; triggerPart.Operator = ComparisonOperatorType.ContainsAny; Assert.True(UserAgentValidatorHelper.Evaluate(triggerPart, "Googlebot")); triggerPart.ValuesToCompare = new string[] { "googlebot" }; triggerPart.IsIgnoreCase = true; triggerPart.IsNegative = true; triggerPart.Operator = ComparisonOperatorType.EqualsAny; Assert.True(UserAgentValidatorHelper.Evaluate(triggerPart, "oglebot sample useraagent")); }
public bool IsTriggerGreaterThan(int index, object otherValue, bool orEqualTo = false) { TriggerPart part = triggerParts[index]; switch (part.type) { case TriggerTypes.Bool: return(orEqualTo ? (part.triggerBool == (bool)otherValue) : (part.triggerBool != (bool)otherValue)); case TriggerTypes.Int: return(orEqualTo ? (part.triggerInt >= (int)otherValue) : (part.triggerInt > (int)otherValue)); case TriggerTypes.Float: return(orEqualTo ? (part.triggerFloat >= (float)otherValue) : (part.triggerFloat > (float)otherValue)); case TriggerTypes.Double: return(orEqualTo ? (part.triggerDouble >= (double)otherValue) : (part.triggerDouble > (double)otherValue)); case TriggerTypes.String: return(orEqualTo ? (part.triggerString == (string)otherValue) : (part.triggerString != (string)otherValue)); } return(false); }
public bool IsTriggerEqual(int index, object otherValue) { TriggerPart part = triggerParts[index]; switch (part.type) { case TriggerTypes.Bool: return(part.triggerBool == (bool)otherValue); case TriggerTypes.Int: return(part.triggerInt == (int)otherValue); case TriggerTypes.Float: return(part.triggerFloat == (float)otherValue); case TriggerTypes.Double: return(part.triggerDouble == (double)otherValue); case TriggerTypes.String: return(part.triggerString == (string)otherValue); } return(false); }