public void Authorize_UserNameAndPasswordSupplied_RepositoryReturnsNullToken() { var mockAuthorizationRepository = new Mock <IAuthorizationRepository>(); var mockConfiguration = new Mock <IConfigurationProperties>(); TokenAuthorizer authorizer = new TokenAuthorizer(mockConfiguration.Object, mockAuthorizationRepository.Object); mockAuthorizationRepository.Setup(rep => rep.Authorize("testName", "testPassword")).Returns((Token)null); Token token = authorizer.Authorize("testName", "testPassword"); Assert.IsNull(token); mockAuthorizationRepository.Verify(rep => rep.Authorize(It.IsAny <string>(), It.IsAny <string>()), Times.Once); mockAuthorizationRepository.Verify(rep => rep.Authorize("testName", "testPassword"), Times.Once); }
public void Authorize_UserNameAndPasswordSupplied_RepositoryReturnsToken() { var mockAuthorizationRepository = new Mock <IAuthorizationRepository>(); var mockConfiguration = new Mock <IConfigurationProperties>(); TokenAuthorizer authorizer = new TokenAuthorizer(mockConfiguration.Object, mockAuthorizationRepository.Object); Token token = new Token(new Guid("b2b7bb51-fcba-4c50-b4e2-712cc96b9b2e"), new DateTime(2001, 01, 01)); mockAuthorizationRepository.Setup(rep => rep.Authorize("testUsername", "testPassword")).Returns(token); Token newToken = authorizer.Authorize("testUsername", "testPassword"); Assert.IsNotNull(newToken); Assert.AreEqual(token.AuthorisationToken, newToken.AuthorisationToken); mockAuthorizationRepository.Verify(rep => rep.Authorize(It.IsAny <string>(), It.IsAny <string>()), Times.Once); mockAuthorizationRepository.Verify(rep => rep.Authorize("testUsername", "testPassword"), Times.Once); }