public void Returns_false_if_fails() { _oAuthAuthentication.Stub(x => x.ForUser("test", "test")).Throw(new LoginInvalidException()); var sevenDigitalCredentialsAuthProvider = new SevenDigitalCredentialsAuthProvider(_oAuthAuthentication, _userApi); var serviceBase = MockRepository.GenerateStub <IServiceBase>(); var mockRequestContext = new MockRequestContext(); serviceBase.Stub(x => x.RequestContext).Return(mockRequestContext); var tryAuthenticate = sevenDigitalCredentialsAuthProvider.TryAuthenticate(serviceBase, "test", "test"); Assert.That(tryAuthenticate, Is.False); }
public void Calls_api_authentication_class() { var oAuthAccessToken = new OAuthAccessToken(); _oAuthAuthentication.Stub(x => x.ForUser("test", "test")).Return(oAuthAccessToken); var sevenDigitalCredentialsAuthProvider = new SevenDigitalCredentialsAuthProvider(_oAuthAuthentication, _userApi); var authService = MockRepository.GenerateStub <IServiceBase>(); authService.Stub(x => x.RequestContext).Return(new MockRequestContext()); var isAuthenticated = sevenDigitalCredentialsAuthProvider.TryAuthenticate(authService, "test", "test"); _oAuthAuthentication.AssertWasCalled(x => x.ForUser("test", "test")); Assert.That(isAuthenticated); }
public void Fires_create_method_and_then_logs_in() { const string expectedUsername = "******"; const string expectedPassword = "******"; var oAuthAccessToken = new OAuthAccessToken(); _oAuthAuthentication.Stub(x => x.ForUser(null, null)).IgnoreArguments().Return(oAuthAccessToken); var serviceBase = MockRepository.GenerateStub <IServiceBase>(); serviceBase.Stub(x => x.RequestContext).Return(new MockRequestContext()); var sevenDigitalCredentialsAuthProvider = new SevenDigitalCredentialsAuthProvider(_oAuthAuthentication, _userApi); sevenDigitalCredentialsAuthProvider.TryAuthenticate(serviceBase, expectedUsername, expectedPassword); _userApi.AssertWasCalled(x => x.Create(expectedUsername, expectedPassword, "")); _oAuthAuthentication.AssertWasCalled(x => x.ForUser(HttpUtility.UrlEncode(expectedUsername), HttpUtility.UrlEncode(expectedPassword))); }
public void Fires_create_method_and_passes_down_affiliate_id_if_exists() { const string expectedUsername = "******"; const string expectedPassword = "******"; const string expectedAffiliatePartnerId = "712"; var oAuthAccessToken = new OAuthAccessToken(); _oAuthAuthentication.Stub(x => x.ForUser(null, null)).IgnoreArguments().Return(oAuthAccessToken); var serviceBase = MockRepository.GenerateStub <IServiceBase>(); var formData = new NameValueCollection { { "affiliatePartner", expectedAffiliatePartnerId } }; var loggedInContext = ContextHelper.LoggedInContext(formData); serviceBase.Stub(x => x.RequestContext).Return(loggedInContext); var sevenDigitalCredentialsAuthProvider = new SevenDigitalCredentialsAuthProvider(_oAuthAuthentication, _userApi); sevenDigitalCredentialsAuthProvider.TryAuthenticate(serviceBase, expectedUsername, expectedPassword); _userApi.AssertWasCalled(x => x.Create(expectedUsername, expectedPassword, expectedAffiliatePartnerId)); _oAuthAuthentication.AssertWasCalled(x => x.ForUser(HttpUtility.UrlEncode(expectedUsername), HttpUtility.UrlEncode(expectedPassword))); }