コード例 #1
0
        public void GetUser_ReturnsUserDto()
        {
            Guid IdMock = Guid.NewGuid();
            var userMock = new User()
            {
                Id = IdMock,
                Username = "******",
                Profile = new UserProfile()
                {
                    Id = IdMock,
                    FirstName = "test firstname",
                    LastName = "test lastname",
                    CurrentTradeRole = TradeRole.Seller,
                    Address = new Address() { Country = "UK" }
                }
            };

            IUsersRepository usersRepository = new UsersRepositoryMock(userMock);
            UsersController controller = new UsersController(usersRepository);

            var actionResult = controller.GetUser(IdMock).Result;
            var response = actionResult as OkNegotiatedContentResult<UserDto>;

            Assert.IsNotNull(response.Content);
            Assert.AreEqual<Guid>(IdMock, response.Content.Id);
            Assert.AreEqual<string>(userMock.Username, response.Content.Username);
            Assert.AreEqual<string>(userMock.Profile.FirstName, response.Content.FirstName);
            Assert.AreEqual<string>(userMock.Profile.LastName, response.Content.LastName);
            Assert.AreEqual<string>(userMock.Profile.CurrentTradeRole.ToString(), response.Content.CurrentTradeRole.ToString());
            Assert.AreEqual<string>(userMock.Profile.Address.Country, response.Content.Address.Country);
        }
コード例 #2
0
        public async Task<bool> CreateUser(User newUser)
        {
            this.dbContext.Users.Add(newUser);
            await this.dbContext.SaveChangesAsync();

            return true;
        }
コード例 #3
0
        public async Task<bool> UpdateUser(User modifiedUser)
        {
            var existingUser = await this.dbContext.Users.FindAsync(modifiedUser.Id);

            if (existingUser == null)
            {
                return false;
            }

            // Explicitly map the properties which can be changed to avoid changing some of the unchangable ones (ex: Username)
            existingUser.Profile.FirstName = modifiedUser.Profile.FirstName;
            existingUser.Profile.LastName = modifiedUser.Profile.LastName;            
            existingUser.Profile.LastModified = modifiedUser.Profile.LastModified;
            existingUser.Profile.CurrentTradeRole = modifiedUser.Profile.CurrentTradeRole;
            existingUser.Profile.Address = modifiedUser.Profile.Address;

            await this.dbContext.SaveChangesAsync();

            return true;
        }
コード例 #4
0
 public UsersRepositoryMock(User userMock)
 {
     this.userMock = userMock;
 }
コード例 #5
0
ファイル: Mapper.cs プロジェクト: ivaneft/PropTradeApp
 public static RelatedUserDto MapUserAndProfileToRelatedUserDto(User user, UserProfile profile)
 {
     return new RelatedUserDto()
     {
         UserId = user.Id,
         Username = user.Username,
         FirstName = profile.FirstName,
         LastName = profile.LastName,
         CurrentTradeRole = Mapper.MapTradeRoleEntityToDto(profile.CurrentTradeRole)
     };
 }