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); }
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); }
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); }
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); }
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); }