コード例 #1
0
        public async Task when_invoking_get_async_it_should_invoke_get_async_on_user_repository()
        {
            //Arange
            var user       = new User(Guid.NewGuid(), "user", "test", "*****@*****.**", "secret");
            var accountDTO = new AccountDTO
            {
                Id    = user.Id,
                Name  = user.Name,
                Role  = user.Role,
                Email = user.Email
            };
            var userRepositoryMock = new Mock <IUserRepository>();
            var jwtHandler         = new Mock <IJwtHandler>();
            var mapperMock         = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <AccountDTO>(user)).Returns(accountDTO);
            var userService = new UserService(userRepositoryMock.Object, jwtHandler.Object, mapperMock.Object);

            userRepositoryMock.Setup(x => x.GetAsync(user.Id)).ReturnsAsync(user);

            //Act
            var existingAccountDTO = await userService.GetAccountAsync(user.Id);

            //Assert
            userRepositoryMock.Verify(x => x.GetAsync(user.Id), Times.Once());
            accountDTO.Should().NotBeNull();
            accountDTO.Email.ShouldBeEquivalentTo(user.Email);
        }
コード例 #2
0
        public void AccountGetByNameTest(int id, string firstname, string lastname, string email, string password, string username, bool admin)
        {
            AccountDTO dto = new AccountDTO(id, firstname, lastname, email, password, username, admin);

            AccountDTO result = converter.ModelToDTO(container.GetByName(converter.DtoToModel(dto)));

            dto.Should().BeEquivalentTo(result);
        }