public async Task Post_CreatedReturned() { var newItem = new ListItem { Text = "newItem" }; var createdItem = new ListItem { Id = new Guid("0B9E6EAF-83DC-4A99-9D57-A39FAF258CAB"), Text = "newItem", IsActive = false, CreationTime = new DateTime(1589, 12, 3), LastUpdateTime = new DateTime(1896, 4, 7) }; var expectedUri = new Uri($"http://www.aaa.com/{createdItem.Id}"); _repository.AddItemAsync(newItem).Returns(createdItem); _location.GetListItemLocation(createdItem.Id).Returns(expectedUri); var message = await _listController.ExecuteAction(controller => controller.PostAsync(newItem)); message.TryGetContentValue(out ListItem item); Assert.Multiple(() => { Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.Created)); Assert.That(message.Headers.Location, Is.EqualTo(expectedUri)); Assert.That(item, Is.EqualTo(createdItem).Using(_listItemEqualityComparer)); }); }
private void ArrangeTestAccordingToItem(Item expectedItem) { _timeManager.GetCurrentTime().Returns(expectedItem.CreationTime); _guidGenerator.GenerateId().Returns(expectedItem.Id); _repository.AddItemAsync(ArgWrapper.IsItem(expectedItem)) .Returns(Task.FromResult(expectedItem)); }
public async Task <IHttpActionResult> PostAsync(ListItem item) { var newItem = await _listRepository.AddItemAsync(item); var location = _urlLocation.GetListItemLocation(newItem.Id); return(Created(location, newItem)); }
public async Task <Item> CreateItemAsync(Item item) { var newItem = CreateItem(item.Text); return(await _repository.AddItemAsync(newItem)); }