public async Task <Item> AddItemAsync(Item item) { var newItem = new Item { Id = await _identifierService.GenerateIdAsync(), Text = item.Text, }; await _itemsRepository.AddAsync(newItem); return(newItem); }
public async Task AddItemAsync_validText_returnsNewItemWithIdAndCorrectProperties() { var id = Guid.NewGuid(); var text = "text of new item"; var expectedItem = new Item { Id = id, Text = text, }; Item storedItem = null; _identifierService.GenerateIdAsync().Returns(id); _itemsRepository.AddAsync(Arg.Do <Item>(item => { storedItem = item; })).Returns(Task.CompletedTask); var newItem = await _itemsService.AddItemAsync(expectedItem); Assert.That(storedItem, Is.EqualTo(expectedItem).UsingItemComparer()); Assert.That(newItem, Is.EqualTo(expectedItem).UsingItemComparer()); }