Beispiel #1
0
        public void AutherizationUserInvalidUserTest()
        {
            Mock <IUserRepository> userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.GetByLogin(It.IsAny <string>())).Verifiable();
            AuthenticationService.AuthenticationService service = new AuthenticationService.AuthenticationService(userRepositoryMock.Object, Mock.Of <IRoleRepository>());
            OperationResult result = service.AuthorizationUser(null, null);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Success, Is.False);
            Assert.That(result.Errors, Is.Not.Empty);
            Assert.That(result.Errors.Contains(OperationErrors.AutorizationFiledErr), Is.True);
            Assert.That(result.Errors.Count, Is.EqualTo(1));
            userRepositoryMock.Verify(x => x.GetByLogin(It.IsAny <string>()), Times.Once);
        }
Beispiel #2
0
        public void AutherizationUserTest()
        {
            Mock <IUserRepository> userRepositoryMock = new Mock <IUserRepository>();

            userRepositoryMock.Setup(x => x.GetByLogin(It.IsAny <string>())).Returns(new Models.EFModels.User
            {
                Password = "******",
                Salt     = "aMZ1Eh+6K6Eh4sK87E0ZVEG8jA9rnFn88r4Pm5MYtnA="
            }).Verifiable();
            AuthenticationService.AuthenticationService service = new AuthenticationService.AuthenticationService(userRepositoryMock.Object, Mock.Of <IRoleRepository>());
            OperationResult <Models.ServiceModels.User> result  = service.AuthorizationUser("login", "z");

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Result, Is.Not.Null);
            Assert.That(result.Success, Is.True);
            Assert.That(result.Errors, Is.Empty);
            userRepositoryMock.Verify(x => x.GetByLogin(It.IsAny <string>()), Times.Once);
        }