Example #1
0
        public async Task UpdateUserAsync_ShouldUpdateUser_WhenExists()
        {
            //Arrange
            var guid = Guid.NewGuid();
            var data = GenerateUsers(guid);

            var mockSet = DbSetMock.GenerateMockSet(data);

            const string email   = "*****@*****.**";
            const string name    = "TestName";
            const string surname = "TestSurname";
            UserDto      dto     = new()
            {
                UserId  = guid,
                Email   = email,
                IsAdmin = false,
                Name    = name,
                Surname = surname
            };

            _userRepo.Users.Returns(mockSet);


            //Act
            var updatedUser = await _sut.UpdateUserAsync(dto);

            //Assert
            updatedUser.Should().NotBeNull();
            updatedUser.UserId.Should().Be(guid);
            updatedUser.Email.Should().Be(email);
            updatedUser.Name.Should().Be(name);
            updatedUser.Surname.Should().Be(surname);
        }
Example #2
0
        public async Task CreateUserAsync_ShouldReturnUserDto_AfterUserWasCreated()
        {
            //Arrange
            const string password = "******";
            const string email    = "*****@*****.**";
            const string name     = "Nice";
            const string surname  = "Man";

            var cud = new CreateUserDto
            {
                Password = password,
                Email    = email,
                IsAdmin  = false,
                Name     = name,
                Surname  = surname
            };
            var data    = GenerateUsers(null);
            var mockSet = DbSetMock.GenerateMockSet(data);

            _userRepo.Users.Returns(mockSet);

            //Act
            var user = await _sut.CreateUserAsync(cud);

            //Assert
            user.Should().NotBeNull();
            user.Email.Should().Be(email);
            user.IsAdmin.Should().BeFalse();
            user.Name.Should().Be(name);
            user.Surname.Should().Be(surname);
        }
Example #3
0
        public async Task UpdateUserAsync_ShouldThrowException_WhenUserNotExists()
        {
            //Arrange
            var guid = Guid.NewGuid();
            var data = GenerateUsers(guid);

            var mockSet = DbSetMock.GenerateMockSet(data);

            const string email   = "*****@*****.**";
            const string name    = "TestName";
            const string surname = "TestSurname";
            UserDto      dto     = new()
            {
                UserId  = Guid.NewGuid(),
                Email   = email,
                IsAdmin = false,
                Name    = name,
                Surname = surname
            };

            _userRepo.Users.Returns(mockSet);


            //Act
            Func <Task> act = async() =>
            {
                await _sut.UpdateUserAsync(dto);
            };

            //Assert
            await act
            .Should()
            .ThrowAsync <EntityNotFoundException>()
            .WithMessage($"Couldn\'t find user with id = {dto.UserId}");
        }
Example #4
0
        public async Task GetUserAsync_ShouldThrowException_WhenUserNotExistsWithEmail()
        {
            //Arrange
            const string email   = "*****@*****.**";
            var          data    = GenerateUsers(null);
            var          mockSet = DbSetMock.GenerateMockSet(data);

            _userRepo.Users.Returns(mockSet);

            //Act
            var user = await _sut.GetUserAsync(email);

            //Assert
            user.Should().BeNull();
        }
Example #5
0
        public async Task GetUserAsync_ShouldReturnNull_WhenUserNotExistsWithId()
        {
            //Arrange
            var guid    = Guid.NewGuid();
            var data    = GenerateUsers(null);
            var mockSet = DbSetMock.GenerateMockSet(data);

            _userRepo.Users.Returns(mockSet);

            //Act
            var user = await _sut.GetUserAsync(guid);

            //Assert
            user.Should().BeNull();
        }
Example #6
0
        public async Task GetUserAsync_ShouldReturnUser_WhenUserExistsWithEmail()
        {
            //Arrange
            const string email   = "*****@*****.**";
            var          data    = GenerateUsers(Guid.NewGuid());
            var          mockSet = DbSetMock.GenerateMockSet(data);

            _userRepo.Users.Returns(mockSet);

            //Act
            var userDto = await _sut.GetUserAsync(email);

            //Assert
            userDto.Should().NotBeNull();
            userDto.Email.Should().Be(email);
        }