public async Task Can_Add_A_Todo_Item_To_A_Collection() { //Given var collection = new Collection { Name = "A Collection" }; await Database.OnceAndSaveAsync(async db => await db.Collections.AddAsync(collection)); var item = new TodoItem { Name = "An Item" }; //When var result = await Database.OnceAsync(async db => { var repository = new TodoItemRepository(db); return(await repository.AddAsync(collection, item)); }); //Then Assert.Equal(item.Name, result.Name); Assert.False(item.IsDone); var isExists = await Database.OnceAsync(async db => await Database.Create().Collections.AnyAsync( c => c.Id == collection.Id && c.TodoItems.Any(i => i.Name == item.Name))); Assert.True(isExists); }
public async Task CreateAsync_Should_Add_New_Entity_To_Database() { // Arrange var createTodoItemModel = Builder <CreateTodoItemModel> .CreateNew().Build(); var todoList = Builder <TodoList> .CreateNew().Build(); var todoItem = Builder <TodoItem> .CreateNew().With(ti => ti.Id = Guid.NewGuid()).Build(); TodoListRepository.GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >()).Returns(todoList); TodoItemRepository.AddAsync(Arg.Any <TodoItem>()).Returns(todoItem); // Act var result = await _sut.CreateAsync(createTodoItemModel); // Assert result.Id.Should().Be(todoItem.Id); await TodoListRepository.Received().GetFirstAsync(Arg.Any <Expression <Func <TodoList, bool> > >()); await TodoItemRepository.Received().AddAsync(Arg.Any <TodoItem>()); }