Exemple #1
0
        public async Task ValidateCreateUserFailsForDuplicatedUser()
        {
            // arrange
            var user = TestObjectCreationUtility.CreateUser();

            mocker
            .GetMock <IUsersRepository>()
            .Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(user);

            // act, assert
            await Assert.ThrowsAsync <ResourceAlreadyExistsException>(() => service.RegisterUserAsync(user));

            mocker.VerifyAll();
        }
Exemple #2
0
        public async Task ValidateCanGetUser()
        {
            // arrange
            var user = TestObjectCreationUtility.CreateUser();

            mocker
            .GetMock <IUsersRepository>()
            .Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(user);

            // act
            var savedUser = await service.GetUserAsync(user.Email);

            // assert
            Assert.NotNull(savedUser);
            Assert.Null(savedUser.Password);

            mocker.VerifyAll();
        }
Exemple #3
0
        public async Task ValidateCanLogin()
        {
            // arrange
            var user = TestObjectCreationUtility.CreateUser();

            mocker
            .GetMock <IEncryptionSerice>()
            .Setup(x => x.Encrypt(It.Is <string>(x => x == user.Password)))
            .Returns("some-value");

            mocker
            .GetMock <IUsersRepository>()
            .Setup(x => x.GetByEmailAndPasswordAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(user);

            // act
            var savedUser = await service.LoginAsync(user.Email, user.Password);

            // assert
            Assert.NotNull(savedUser);

            mocker.VerifyAll();
        }