public void Should_login_fail() { new Browser(with => { with.Dependency(fakeBookmarksContext); with.Module <TestingModule>(); }).Get("/testing"); var callbackData = new AuthenticateCallbackData { AuthenticatedClient = new AuthenticatedClient("") { UserInformation = new UserInformation { UserName = "******" } } }; //no such user A.CallTo(() => fakeBookmarksContext.GetUserByUsername("test_user")).Returns(null); //using fake context var sut = new SocialAuthenticationCallbackProvider(fakeBookmarksContext); var actual = (string)sut.Process(TestingModule.actualModule, callbackData); //now fail Assert.True(actual.StartsWith("login failed: ")); }
public void Should_login_successfully() { new Browser(with => { with.Dependency(fakeBookmarksContext); with.Module <TestingModule>(); }).Get("/testing"); var callbackData = new AuthenticateCallbackData { AuthenticatedClient = new AuthenticatedClient("") { UserInformation = new UserInformation { UserName = "******" } } }; var userNameToken = new TokenService().GetToken("test_user"); //make fake context to return something A.CallTo(() => fakeBookmarksContext.GetUserByUsername("test_user")) .Returns(new Bookmarks.Common.User { Name = "test_user" }); //using fake context var sut = new SocialAuthenticationCallbackProvider(fakeBookmarksContext); var actual = (Response)sut.Process(TestingModule.actualModule, callbackData); Assert.Equal(HttpStatusCode.SeeOther, actual.StatusCode); Assert.Contains("TagSortServiceUser", actual.Cookies.Select(cookie => cookie.Name)); Assert.Contains(userNameToken, actual.Cookies.Select(cookie => cookie.Value)); }