Example #1
0
        public async Task GetUserInfo_WhenGot_ListOfAllUsersExpected()
        {
            // Arrange
            var initUsers = InitListOfUser();
            await _context.AddRangeAsync();

            await _context.SaveChangesAsync();

            // Act
            var result = await _userService.GetUsers();

            // Assert
            Assert.True(result.Count == 3);
            foreach (var user in result)
            {
                Assert.True(user.UserStatus != UserStatus.Deleted);
            }
        }
Example #2
0
        /// <inheritdoc />
        public async Task <UserInfo> CreateUser(UserInfo model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            var existUser = await _dbContext.Users.FirstOrDefaultAsync(x => x.UserId == model.UserId);

            if (existUser != null)
            {
                throw new XmlExceptionError1($"User with id {model.UserId} already exist");
            }

            var modelForAdd = model.AdaptUserToEntity();
            await _dbContext.Users.AddAsync(modelForAdd);

            await _dbContext.SaveChangesAsync();

            var result = await _dbContext.Users.FirstOrDefaultAsync(x => x.UserId == model.UserId);

            return(result?.AdaptEntityToUserInfoModel());
        }