public async Task Update_Is_Exist_Value() { var userGenerated = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Update_Is_Exist_Value)))) { InMemoryDatabaseHelper.Save(new List <User> { userGenerated }, context); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Update_Is_Exist_Value)))) { var repository = new UserRepository(context); var user = await repository.GetById(userGenerated.Id); user.Username = UserSeed.Username; await repository.Update(user); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Update_Is_Exist_Value)))) { var repository = new UserRepository(context); var userList = repository.GetAll(); Assert.NotNull(userList); Assert.Contains(UserSeed.Username, userList.Select(u => u.Username)); } }
public async Task Delete_Is_Exist_Value(int userCount) { var userGenerated = UserSeed.CreateUserTest(); var users = UserSeed.CreateUsers(userCount); users.Add(userGenerated); using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Delete_Is_Exist_Value)))) { InMemoryDatabaseHelper.Save(users, context); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Delete_Is_Exist_Value)))) { var repository = new UserRepository(context); await repository.Delete(userGenerated.Id); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Delete_Is_Exist_Value)))) { Assert.NotNull(context.User); Assert.False(context.User.Any(u => u.Id == userGenerated.Id)); Assert.True(context.User.Count() == userCount); } }
public async Task Delete_Existing_User_Multiple_Users() { var users = UserSeed.CreateUsers(10); var userGenerated = UserSeed.CreateUserTest(); users.Add(userGenerated); var dbName = nameof(Delete_Existing_User_Multiple_Users); using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { InMemoryDatabaseHelper.Save(users, context); } using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { var controller = CreateUserControllerObject(context); var result = await controller.Delete(userGenerated.Id); Assert.IsType <OkResult>(result); } using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { Assert.False(context.User.Any(u => u.Id == userGenerated.Id)); Assert.True(context.User.Count() == users.Count() - 1); } }
public async Task Delete_Existing_User() { var dbName = nameof(Delete_Existing_User); var user = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { InMemoryDatabaseHelper.Save(new List <User> { user }, context); } using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { var controller = CreateUserControllerObject(context); var result = await controller.Delete(user.Id); Assert.IsType <OkResult>(result); } using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { Assert.False(context.User.Any(u => u.Id == user.Id)); } }
public async Task Post_Create_User_Success() { var userGenerated = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(nameof(Post_Create_User_Success))) { var controller = CreateUserControllerObject(context); var dto = new UserDto { Id = userGenerated.Id, Username = userGenerated.Username, Password = userGenerated.Password }; var result = await controller.Post(dto); var dtoSuccess = result.Value; Assert.IsType <ActionResult <UserDto> >(result); Assert.IsType <UserDto>(dtoSuccess); } using (var context = InMemoryDatabaseHelper.CreateContext(nameof(Post_Create_User_Success))) { var user = context.User.FirstOrDefault(u => u.Id == userGenerated.Id); Assert.NotNull(user); Assert.True(user.Username == userGenerated.Username); Assert.True(user.Password == userGenerated.Password); } }
public async Task Post_Create_User_Conflict() { var user = UserSeed.CreateUserTest(); var dbName = nameof(Post_Create_User_Conflict); using (var context = InMemoryDatabaseHelper.CreateContext(dbName)) { InMemoryDatabaseHelper.Save(new List <User> { user }, context); var controller = CreateUserControllerObject(context); var dto = new UserDto { Id = user.Id, Username = user.Username, Password = user.Password }; var result = await controller.Post(dto); Assert.IsType <BadRequestObjectResult>(result.Result); } }
public async Task Add_Duplicate_Id() { var userGenerated = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Add_Duplicate_Id)))) { InMemoryDatabaseHelper.Save(new List <User> { userGenerated }, context); var repository = new UserRepository(context); await Assert.ThrowsAsync <InvalidOperationException>(async() => await repository.Add(userGenerated)); } }
public async Task GetByUsername_No_Return_Value() { // Arrange var userGenerated = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(nameof(GetByUsername_No_Return_Value))) { InMemoryDatabaseHelper.Save(UserSeed.CreateUsers(), context); } using (var context = InMemoryDatabaseHelper.CreateContext(nameof(GetByUsername_No_Return_Value))) { // Act var userFinder = CreateUserFindObject(context); var user = await userFinder.GetByUsername(userGenerated.Username); // Assert Assert.Null(user); Assert.DoesNotContain(userGenerated.Username, context.User.Select(u => u.Username)); } }
public async Task GetById_Is_Exist_Value(int userCount) { var dbName = $"{nameof(GetById_Is_Exist_Value)}_{userCount}"; var userGenerated = UserSeed.CreateUserTest(); var users = UserSeed.CreateUsers(userCount); users.Add(userGenerated); using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(dbName))) { InMemoryDatabaseHelper.Save(users, context); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(dbName))) { var repository = new UserRepository(context); var user = await repository.GetById(userGenerated.Id); Assert.NotNull(user); Assert.True(user.Id == userGenerated.Id); Assert.Equal(user.Password, userGenerated.Password); } }
public async Task Add_New_Value() { var userCount = 10; var userGenerated = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Add_New_Value)))) { InMemoryDatabaseHelper.Save(UserSeed.CreateUsers(userCount), context); var repository = new UserRepository(context); await repository.Add(userGenerated); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Add_New_Value)))) { var repository = new UserRepository(context); var userList = repository.GetAll().ToList(); Assert.NotNull(userList); Assert.True(userList.Count() == userCount + 1); Assert.Contains(userGenerated.Id, userList.Select(u => u.Id)); Assert.Contains(userGenerated.Username, userList.Select(u => u.Username)); } }
public async Task GetByUsername_Return_Value() { // Arrange var userGenerated = UserSeed.CreateUserTest(); using (var context = InMemoryDatabaseHelper.CreateContext(nameof(GetByUsername_Return_Value))) { InMemoryDatabaseHelper.Save(new List <User> { userGenerated }, context); } using (var context = InMemoryDatabaseHelper.CreateContext(nameof(GetByUsername_Return_Value))) { // Act var userFinder = CreateUserFindObject(context); var user = await userFinder.GetByUsername(userGenerated.Username); // Assert Assert.NotNull(user); Assert.Equal(user.Username, userGenerated.Username); Assert.Equal(user.Id, userGenerated.Id); } }
public async Task Update_Is_Not_Exist_Value() { using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Update_Is_Not_Exist_Value)))) { InMemoryDatabaseHelper.Save(UserSeed.CreateUsers(), context); } using (var context = InMemoryDatabaseHelper.CreateContext(CreateDatabaseName(nameof(Update_Is_Not_Exist_Value)))) { var repository = new UserRepository(context); await Assert.ThrowsAsync <InvalidOperationException>(async() => await repository.Update(UserSeed.CreateUserTest())); } }