Example #1
0
            public void DeserializesWhenCookieIsPresentAndValid()
            {
                RequestCookies.Add(new HttpCookie(CookieName, SerializedEnrollment));

                var result = RunTest(User);

                Assert.True(result, "The test should be enabled.");
                Assert.Empty(ResponseCookies.Keys.Cast <string>());
                EnrollmentFactory.Verify(x => x.Initialize(), Times.Never);
                EnrollmentFactory.Verify(x => x.Serialize(It.IsAny <ABTestEnrollment>()), Times.Never);
                EnrollmentFactory.Verify(x => x.TryDeserialize(It.IsAny <string>(), out OutEnrollment), Times.Once);
            }
Example #2
0
            public void InitializesWhenCookieIsMissing()
            {
                var result = RunTest(User);

                Assert.True(result, "The test should be enabled.");
                Assert.Contains(CookieName, ResponseCookies.Keys.Cast <string>());
                var cookie = ResponseCookies[CookieName];

                VerifyCookie(cookie);
                EnrollmentFactory.Verify(x => x.Initialize(), Times.Once);
                EnrollmentFactory.Verify(x => x.Serialize(InitializedEnrollment), Times.Once);
                EnrollmentFactory.Verify(x => x.Serialize(It.IsAny <ABTestEnrollment>()), Times.Once);
                EnrollmentFactory.Verify(x => x.TryDeserialize(It.IsAny <string>(), out OutEnrollment), Times.Never);
            }
Example #3
0
            public void ReturnsFalseWhenUserIsNotInFlight()
            {
                FeatureFlagService
                .Setup(x => x.IsABTestingEnabled(It.IsAny <User>()))
                .Returns(false);

                var result = RunTest(User);

                Assert.False(result, "The test should not be enabled.");
                FeatureFlagService.Verify(x => x.IsABTestingEnabled(User), Times.Once);
                Assert.Empty(ResponseCookies);
                EnrollmentFactory.Verify(x => x.Initialize(), Times.Never);
                ABTestEnrollment outEnrollment;

                EnrollmentFactory.Verify(x => x.TryDeserialize(It.IsAny <string>(), out outEnrollment), Times.Never);
            }
Example #4
0
            public void ReturnsFalseWhenCookieConsentIsNotGiven()
            {
                CookieComplianceService
                .Setup(x => x.CanWriteNonEssentialCookies(It.IsAny <HttpRequestBase>()))
                .Returns(false);

                var result = RunTest(User);

                Assert.False(result, "The test should not be enabled.");
                CookieComplianceService.Verify(x => x.CanWriteNonEssentialCookies(HttpContext.Object.Request), Times.Once);
                Assert.Empty(ResponseCookies);
                EnrollmentFactory.Verify(x => x.Initialize(), Times.Never);
                ABTestEnrollment outEnrollment;

                EnrollmentFactory.Verify(x => x.TryDeserialize(It.IsAny <string>(), out outEnrollment), Times.Never);
            }
Example #5
0
            public void InitializesWhenCookieIsPresentAndInvalid()
            {
                RequestCookies.Add(new HttpCookie(CookieName, SerializedEnrollment));
                EnrollmentFactory
                .Setup(x => x.TryDeserialize(It.IsAny <string>(), out OutEnrollment))
                .Returns(false);

                var result = RunTest(User);

                Assert.True(result, "The test should be enabled.");
                Assert.Contains(CookieName, ResponseCookies.Keys.Cast <string>());
                var cookie = ResponseCookies[CookieName];

                VerifyCookie(cookie);
                EnrollmentFactory.Verify(x => x.Initialize(), Times.Once);
                EnrollmentFactory.Verify(x => x.Serialize(InitializedEnrollment), Times.Once);
                EnrollmentFactory.Verify(x => x.Serialize(It.IsAny <ABTestEnrollment>()), Times.Once);
                EnrollmentFactory.Verify(x => x.TryDeserialize(It.IsAny <string>(), out OutEnrollment), Times.Once);
            }