public async Task CanSaveZeroTasks() { var options = CreateNewContextOptions(); const string userId = "1"; var user = new ApplicationUser { Id = userId }; using (var context = new AllReadyContext(options)) { context.Users.Add(user); await context.SaveChangesAsync(); } var message = new UpdateMyTasksCommand { UserId = userId, TaskSignups = new List <TaskSignupViewModel>() }; using (var context = new AllReadyContext(options)) { var sut = new UpdateMyTasksCommandHandler(context); await sut.Handle(message); } using (var context = new AllReadyContext(options)) { var taskSignups = context.TaskSignups.Count(); Assert.Equal(taskSignups, 0); } }
public async Task InvokeUpdateTaskSignupAsyncWithTheCorrectParametersForEachTaskSignupViewModelOnCommand() { var options = CreateNewContextOptions(); const string userId = "1"; const int taskSignupId = 1; var user = new ApplicationUser { Id = userId }; var dateTimeUtcNow = DateTime.UtcNow; var taskSignupViewModels = new List <TaskSignupViewModel> { new TaskSignupViewModel { Id = taskSignupId, StatusDescription = "statusDescription1", Status = "Accepted", TaskId = 1 } }; var message = new UpdateMyTasksCommand { TaskSignups = taskSignupViewModels, UserId = userId }; using (var context = new AllReadyContext(options)) { context.Users.Add(user); context.TaskSignups.Add(new TaskSignup { Id = taskSignupId }); context.Tasks.Add(new AllReadyTask { Id = 1 }); await context.SaveChangesAsync(); } using (var context = new AllReadyContext(options)) { var sut = new UpdateMyTasksCommandHandler(context) { DateTimeUtcNow = () => dateTimeUtcNow }; await sut.Handle(message); } using (var context = new AllReadyContext(options)) { var signup = context.TaskSignups.FirstOrDefault(x => x.Id == taskSignupId); Assert.Equal(signup != null, true); } }