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 bool SetCookieAuth(string path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } CookieAuthentication auth = new CookieAuthentication(path); _Auth = auth; return(auth.RefreshCache()); }
public void IsSignedIn_ShouldReturnTrueWhenTheCustomerIsSignedIn() { //Arrange var fakeHttpContext = FakeFactory.FakeHttpContextWithCustomerAuthenticationSetTo(true); var cookieAuth = new CookieAuthentication(fakeHttpContext); var email = fixture.CreateAnonymous <string>(); var customerData = fixture.CreateAnonymous <Customer>(); //Act var signedin = cookieAuth.IsSignedIn(); //Assert signedin.Should().BeTrue(); }
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(); }
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 ExplorerClient(Network network, Uri serverAddress) { if (serverAddress == null) { throw new ArgumentNullException(nameof(serverAddress)); } if (network == null) { throw new ArgumentNullException(nameof(network)); } _Address = serverAddress; _Network = network; _Serializer = new Serializer(network); _Factory = new DerivationStrategy.DerivationStrategyFactory(Network); var auth = new CookieAuthentication(NBXplorer.Client.Utils.GetDefaultCookieFilePath(network)); if (auth.RefreshCache()) { _Auth = auth; } }
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); }