public void Returns_false_when_no_principal_providers_exist() { var principalProvider = new Mock<IPrincipalProvider>(); principalProvider.Setup(x => x.GetPrincipal("username", "password")) .Returns((string username, string password) => new PrincipalProviderResult()); var service = new MembershipService(new IPrincipalProvider[] {}, null); var result = service.ValidateUser("username", "password"); result.ShouldBeFalse(); }
public void Returns_true_when_a_principal_provider_returns_a_principal() { var principalProvider = new Mock<IPrincipalProvider>(); principalProvider.Setup(x => x.GetPrincipal("username", "password")) .Returns(CreateResultWithThisPrincipal(new Mock<IPrincipal>().Object)); var service = new MembershipService(new[] {principalProvider.Object}, null); var result = service.ValidateUser("username", "password"); result.ShouldBeTrue(); }
public void Login_passes_the_principal_from_valid_provider_to_principal_login_service() { var expected = new Mock<IPrincipal>().Object; var validPrincipalProvider = new Mock<IPrincipalProvider>(); validPrincipalProvider.Setup(x => x.GetPrincipal("user name", "password")) .Returns(CreateResultWithThisPrincipal(expected)); var principalLoginService = new Mock<IPrincipalLoginService>(); var membershipService = new MembershipService(new[] {validPrincipalProvider.Object}, principalLoginService.Object); membershipService.LogInAsUser("user name", "password"); principalLoginService .Verify(x => x.LogIn(expected, validPrincipalProvider.Object.GetType()), Times.Once()); }
public void Login_only_passes_one_valid_principal() { var principalLoginService = new Mock<IPrincipalLoginService>(); var provider1 = new Mock<IPrincipalProvider>(); provider1.Setup(x => x.GetPrincipal("user name", "password")) .Returns(CreateResultWithThisPrincipal(new Mock<IPrincipal>().Object)); var provider2 = new Mock<IPrincipalProvider>(); provider2.Setup(x => x.GetPrincipal("user name", "password")) .Returns(CreateResultWithThisPrincipal(new Mock<IPrincipal>().Object)); var membershipService = new MembershipService(new[] {provider2.Object, provider1.Object}, principalLoginService.Object); membershipService.LogInAsUser("user name", "password"); principalLoginService .Verify(x => x.LogIn(It.IsAny<IPrincipal>(), It.IsAny<Type>()), Times.Once()); }
public void Login_only_passes_a_principal_from_a_valid_provider() { var expected = new Mock<IPrincipal>().Object; var principalLoginService = new Mock<IPrincipalLoginService>(); var validPrincipalProvider = new Mock<IPrincipalProvider>(); validPrincipalProvider.Setup(x => x.GetPrincipal("user name", "password")) .Returns(CreateResultWithThisPrincipal(expected)); var invalidPrincipalProvider = new Mock<IPrincipalProvider>(); var resultWithThisPrincipal = CreateResultWithThisPrincipal(null); invalidPrincipalProvider.Setup(x => x.GetPrincipal(It.IsAny<string>(), It.IsAny<string>())) .Returns(resultWithThisPrincipal); var membershipService = new MembershipService(new[] {invalidPrincipalProvider.Object, validPrincipalProvider.Object}, principalLoginService.Object); membershipService.LogInAsUser("user name", "password"); principalLoginService .Verify(x => x.LogIn(resultWithThisPrincipal.Principal, It.IsAny<Type>()), Times.Never()); }
public void The_new_principal_is_returned_from_LogIn() { var principalLoginService = new Mock<IPrincipalLoginService>(); var expected = new Mock<IPrincipal>().Object; var provider = new Mock<IPrincipalProvider>(); provider.Setup(x => x.GetPrincipal("user name", "password")) .Returns(CreateResultWithThisPrincipal(expected)); var membershipService = new MembershipService(new[] { provider.Object }, principalLoginService.Object); var result = membershipService.LogInAsUser("user name", "password"); result.ShouldBeSameAs(expected); }