public async Task Projects_AddNewTask_ShouldOk() { // Create new task var created = new Context.Models.Task { Name = "Set constraints on columns", Description = "Set constraints on columns to put a limit between 1 and 10 of possible values in Projects and Tasks tables", Priority = 10, Status = Context.Models.TaskStatus.Done }; // Assign as global var _task = created; _tasks.Add(created); // Add new task into DB context await _context.Tasks.AddAsync(created); // Save changes into DB Assert.DoesNotThrowAsync(async() => await _context.SaveChangesAsync()); // Check that task was created Assert.NotNull(created); // Check that task was added in DB context var taskName = (await _context.Tasks.FirstOrDefaultAsync()).Name; Assert.AreEqual(taskName, created.Name); }
public async Task Projects_AddManyNewTasks_ShouldOk(int numTasks) { // Create new tasks for (int i = 0; i < numTasks; i++) { var created = new Context.Models.Task { Name = $"Task number: {i + 1}", Description = $"Description of task number: {i + 1}", Priority = 1, Status = Context.Models.TaskStatus.InProgress }; // Assign as global var _tasks.Add(created); } // Add new task into DB context await _context.Tasks.AddRangeAsync(_tasks); // Save changes into DB Assert.DoesNotThrowAsync(async() => await _context.SaveChangesAsync()); // Check that task was created Assert.NotNull(_tasks); Assert.IsNotEmpty(_tasks); Assert.AreEqual(_tasks.Count, numTasks); }