public void IsSignedIn_ShouldReturnFalseWhenNotSignedIn()
        {
            //Arrange
            var fakeHttpContext = FakeFactory.FakeHttpContextWithCustomerAuthenticationSetTo(false);

            var cookieAuth = new CookieAuthentication(fakeHttpContext);

            var email = fixture.CreateAnonymous<string>();
            var customerData = fixture.CreateAnonymous<Customer>();
            //Act
            var signedin = cookieAuth.IsSignedIn();
            //Assert

            signedin.Should().BeFalse();
        }
        public void IsSignedIn_ShouldReturnTheCustomerDataFromCookieWhenCustomerIsSignedIn()
        {
            var fakeHttpContext = FakeFactory.FakeHttpContext();

            var cookieAuth = new CookieAuthentication(fakeHttpContext);

            var email = fixture.CreateAnonymous<string>();
            var customerData = fixture.CreateAnonymous<Customer>();
            //Act
            cookieAuth.Signin(email, customerData);

            var returnCustomerData = cookieAuth.CustomerData;

            //Assert

            returnCustomerData.Country.Should().Be(customerData.Country);
            returnCustomerData.CountryID.Should().Be(customerData.CountryID);
            returnCustomerData.Email.Should().Be(customerData.Email);
            returnCustomerData.FirstName.Should().Be(customerData.FirstName);
            returnCustomerData.State.Should().Be(customerData.State);
            returnCustomerData.StateID.Should().Be(customerData.StateID);
            returnCustomerData.LastName.Should().Be(customerData.LastName);
        }
        public void Signin_ShouldCreateTheCookieTicketWithTheRightUserData()
        {
            //Arrange
            var fakeHttpContext = FakeFactory.FakeHttpContext();

            var cookieAuth = new CookieAuthentication(fakeHttpContext);

            var email = fixture.CreateAnonymous<string>();
            var customerData = fixture.CreateAnonymous<Customer>();
            //Act
            cookieAuth.Signin(email, customerData);
            //Assert

            var authCookie = fakeHttpContext.Response.Cookies[FormsAuthentication.FormsCookieName];

            var authTicket = FormsAuthentication.Decrypt(authCookie.Value);

            var decryptedCustomerData = JsonConvert.DeserializeObject<Customer>(authTicket.UserData);

            decryptedCustomerData.Country.Should().Be(customerData.Country);
            decryptedCustomerData.State.Should().Be(customerData.State);
            decryptedCustomerData.LastName.Should().Be(customerData.LastName);
            decryptedCustomerData.Email.Should().Be(customerData.Email);
            decryptedCustomerData.FirstName.Should().Be(customerData.FirstName);
        }
        public void Signout_ShouldRemoveTheCookie()
        {
            //Arrange
            var fakeHttpContext = FakeFactory.FakeHttpContext();

            var cookieAuth = new CookieAuthentication(fakeHttpContext);

            var email = fixture.CreateAnonymous<string>();
            var customerData = fixture.CreateAnonymous<Customer>();
            //Act
            cookieAuth.Signin(email, customerData);
            cookieAuth.Signout();
            //Assert
            fakeHttpContext.Response.Cookies[FormsAuthentication.FormsCookieName].Expires.Should().BeBefore(DateTime.Now);
            // fakeHttpContext.Request.Cookies[FormsAuthentication.FormsCookieName].Should().BeNull();
        }
        public void Signin_ShouldCreateTheCookieTicket()
        {
            //Arrange
            var fakeHttpContext = FakeFactory.FakeHttpContext();

            var cookieAuth = new CookieAuthentication(fakeHttpContext);

            var email = fixture.CreateAnonymous<string>();
            var customerData = fixture.CreateAnonymous<Customer>();
            //Act
            cookieAuth.Signin(email,customerData);
            //Assert

            fakeHttpContext.Response.Cookies[FormsAuthentication.FormsCookieName].Should().NotBeNull();
        }