public async Task DeleteItemAsync_EmptyGuid_ReturnsBadRequest() { var id = Guid.Empty; var message = await ItemsController.ExecuteAsyncAction(controller => controller.DeleteItemAsync(id)); Assert.Multiple(() => { ItemObtainingService.DidNotReceive().ExistsAsync(Arg.Any <Guid>()); ItemRepository.DidNotReceive().GetByIdAsync(Arg.Any <Guid>()); AssertExtended.IsBadResponseMessage(message, string.Empty); }); }
public async Task PutItemAsync_ExistingItem_ReturnsOkWithUpdatedItem() { var changedItem = ItemFactory.CreateItem("0EBF758B-FC9F-4A42-8A6E-3DD7209E0E46", "Learn redux"); ItemObtainingService.ExistsAsync(changedItem.Id).Returns(true); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PutItemAsync(changedItem.Id, changedItem)); Assert.Multiple(() => { Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.NoContent)); ItemUpdatingService.Received(1).UpdateAsync(changedItem); }); }
public async Task DeleteItemAsync_NonexistentItem_ReturnsNotFound() { var id = Guid.Parse("EA531B21-FC10-4BEB-B6BE-A9635E610213"); ItemObtainingService.ExistsAsync(id).Returns(false); var message = await ItemsController.ExecuteAsyncAction(controller => controller.DeleteItemAsync(id)); Assert.Multiple(() => { ItemRepository.DidNotReceive().GetByIdAsync(Arg.Any <Guid>()); Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); }); }
public async Task GetItemByIdAsync_NonexistentItem_ReturnsNotFound() { var id = Guid.Parse("46A4D418-931F-45EC-8C2F-06236772B245"); ItemObtainingService.ExistsAsync(id).Returns(false); var message = await ItemsController.ExecuteAsyncAction(controller => controller.GetItemByIdAsync(id)); Assert.Multiple(() => { ItemObtainingService.DidNotReceive().GetById(Arg.Any <Guid>()); Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); }); }
public async Task DeleteItemAsync_ExistingItem_ReturnsOkWithDeletedItem() { var expectedDeletedItem = ItemFactory.CreateItem("EA531B21-FC10-4BEB-B6BE-A9635E610213", "Write Web API"); var id = expectedDeletedItem.Id; ItemObtainingService.ExistsAsync(id).Returns(true); ItemRepository.DeleteAsync(id).Returns(expectedDeletedItem); var message = await ItemsController.ExecuteAsyncAction(controller => controller.DeleteItemAsync(id)); message.TryGetContentValue(out Item actualDeletedItem); Assert.Multiple(() => { Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(actualDeletedItem, Is.EqualTo(expectedDeletedItem)); }); }
public async Task GetItemByIdAsync_ExistingItem_ReturnsOkWithRequiredItem() { var expectedItem = ItemFactory.CreateItem("46A4D418-931F-45EC-8C2F-06236772B245", "Learn react"); var id = expectedItem.Id; ItemObtainingService.ExistsAsync(id).Returns(true); ItemObtainingService.GetById(id).Returns(expectedItem); var message = await ItemsController.ExecuteAsyncAction(controller => controller.GetItemByIdAsync(id)); message.TryGetContentValue(out Item actualItem); Assert.Multiple(() => { Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(actualItem, Is.EqualTo(expectedItem)); }); }
public async Task PutItemAsync_NonexistentItem_ReturnsCreated() { var creationTime = new DateTime(2018, 9, 27); var changedItem = ItemFactory.CreateItem("0EBF758B-FC9F-4A42-8A6E-3DD7209E0E46", "Learn redux"); var expectedItem = ItemFactory.CreateItem(changedItem.Id, changedItem.Text, creationTime, creationTime); var headerLocation = new Uri("http://localhost/"); ItemObtainingService.ExistsAsync(changedItem.Id).Returns(false); ItemCreatingService.CreateAsync(Arg.Is <Item>(newItem => newItem.Text == changedItem.Text)).Returns(expectedItem); UrlService.GetItemUrl(expectedItem.Id).Returns(headerLocation); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PutItemAsync(changedItem.Id, changedItem)); message.TryGetContentValue(out Item actualItem); Assert.Multiple(() => { Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.Created)); Assert.That(message.Headers.Location, Is.EqualTo(headerLocation)); Assert.That(actualItem, Is.EqualTo(expectedItem)); }); }