public async Task PutItemAsync_EmptyGuid_ReturnsBadRequest() { var updatedItem = ItemFactory.CreateItem("0EBF758B-FC9F-4A42-8A6E-3DD7209E0E46", "Learn redux"); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PutItemAsync(Guid.Empty, updatedItem)); AssertExtended.IsBadResponseMessage(message, string.Empty); }
public async Task PutItemAsync_NullItem_ReturnsBadRequest() { var id = Guid.Parse("0EBF758B-FC9F-4A42-8A6E-3DD7209E0E46"); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PutItemAsync(id, null)); AssertExtended.IsBadResponseMessage(message, string.Empty); }
public async Task PostItemAsync_ItemWithSetLastUpdateTime_ReturnsBadRequest() { var newItem = ItemFactory.CreateItem(Guid.Empty, "Write dummier controller", DateTime.MinValue, new DateTime(2018, 10, 23)); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PostItemAsync(newItem)); AssertExtended.IsBadResponseMessage(message, nameof(Item.LastUpdateTime)); }
public async Task PostItemAsync_ItemWithIncorrectText_ReturnsBadRequest(string text) { var newItem = ItemFactory.CreateItem(Guid.Empty, text); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PostItemAsync(newItem)); AssertExtended.IsBadResponseMessage(message, nameof(Item.Text)); }
public async Task PostItemAsync_DefaultItem_ReturnsBadRequest() { var newItem = new Item(); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PostItemAsync(newItem)); AssertExtended.IsBadResponseMessage(message, nameof(Item.Text)); }
public async Task PutItemAsync_ItemWithSetLastUpdateTime_ReturnsBadRequest() { var changedItem = ItemFactory.CreateItem("0EBF758B-FC9F-4A42-8A6E-3DD7209E0E46", "Learn redux", null, new DateTime(2018, 10, 23)); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PutItemAsync(changedItem.Id, changedItem)); AssertExtended.IsBadResponseMessage(message, nameof(Item.LastUpdateTime)); }
public async Task PutItemAsync_ItemWithIncorrectText_ReturnsBadRequest(string text) { var changedItem = ItemFactory.CreateItem("0EBF758B-FC9F-4A42-8A6E-3DD7209E0E46", text); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PutItemAsync(changedItem.Id, changedItem)); AssertExtended.IsBadResponseMessage(message, nameof(Item.Text)); }
public async Task GetItemByIdAsync_EmptyGuid_ReturnsBadRequest() { var id = Guid.Empty; var message = await ItemsController.ExecuteAsyncAction(controller => controller.GetItemByIdAsync(id)); AssertExtended.IsBadResponseMessage(message, string.Empty); }
public async Task PostItemAsync_ItemWithSetId_ReturnsBadRequest() { var newItem = ItemFactory.CreateItem("5694207A-697C-449B-BA49-05AC6683C5E5", "Write dummier controller"); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PostItemAsync(newItem)); AssertExtended.IsBadResponseMessage(message, nameof(Item.Id)); }
public async Task PutItemAsync_DefaultItem_ReturnsBadRequest() { var id = Guid.Parse("0EBF758B-FC9F-4A42-8A6E-3DD7209E0E46"); var changedItem = new Item(); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PutItemAsync(id, changedItem)); AssertExtended.IsBadResponseMessage(message, nameof(Item.Id), nameof(Item.Text)); }
public async Task PutItemAsync_NotMatchingIds_ReturnsBadRequest() { var id = Guid.Parse("EA531B21-FC10-4BEB-B6BE-A9635E610213"); var changedItem = ItemFactory.CreateItem("0EBF758B-FC9F-4A42-8A6E-3DD7209E0E46", "Learn redux"); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PutItemAsync(id, changedItem)); AssertExtended.IsBadResponseMessage(message, nameof(Item.Id)); }
public async Task PostItemAsync_BadItemModelState_ReturnsAllErrors() { var newItem = ItemFactory.CreateItem("5694207A-697C-449B-BA49-05AC6683C5E5", string.Empty, new DateTime(2018, 10, 23), new DateTime(2018, 10, 23)); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PostItemAsync(newItem)); AssertExtended.IsBadResponseMessage(message, nameof(Item.Id), nameof(Item.Text), nameof(Item.CreationTime), nameof(Item.LastUpdateTime) ); }
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 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 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 PutItemAsync_BadItemModelState_ReturnsAllErrors() { var id = Guid.Parse("0EBF758B-FC9F-4A42-8A6E-3DD7209E0E46"); var changedItem = ItemFactory.CreateItem(Guid.Empty, null, new DateTime(2018, 10, 23), new DateTime(2018, 10, 23)); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PutItemAsync(id, changedItem)); AssertExtended.IsBadResponseMessage(message, nameof(Item.Id), nameof(Item.Text), nameof(Item.CreationTime), nameof(Item.LastUpdateTime) ); }
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 PostItemAsync_ValidItem_ReturnsCreatedItem() { var creationTime = new DateTime(2018, 9, 27); var expectedItem = ItemFactory.CreateItem("5694207A-697C-449B-BA49-05AC6683C5E5", "Write dummier controller", creationTime, creationTime); var newItem = ItemFactory.CreateItem(Guid.Empty, expectedItem.Text); var headerLocation = new Uri("http://localhost/"); ItemCreatingService.CreateAsync(newItem).Returns(expectedItem); UrlService.GetItemUrl(expectedItem.Id).Returns(headerLocation); var message = await ItemsController.ExecuteAsyncAction(controller => controller.PostItemAsync(newItem)); 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)); }); }
public async Task GetAllItemsAsync_ReturnsAllItems() { var expectedItems = new [] { ItemFactory.CreateItem("46A4D418-931F-45EC-8C2F-06236772B245", "Learn react"), ItemFactory.CreateItem("0EBF758B-FC9F-4A42-8A6E-3DD7209E0E46", "Learn redux"), ItemFactory.CreateItem("EA531B21-FC10-4BEB-B6BE-A9635E610213", "Write Web API"), ItemFactory.CreateItem("5694207A-697C-449B-BA49-05AC6683C5E5", "Write dummier controller") }; ItemRepository.GetAllAsync().Returns(expectedItems); var message = await ItemsController.ExecuteAsyncAction(controller => controller.GetAllItemsAsync()); message.TryGetContentValue(out IEnumerable <Item> actualItems); Assert.Multiple(() => { Assert.That(message.StatusCode, Is.EqualTo(HttpStatusCode.OK)); Assert.That(actualItems, Is.EquivalentTo(expectedItems)); }); }
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)); }); }
public async Task PostItemAsync_NullItem_ReturnsBadRequest() { var message = await ItemsController.ExecuteAsyncAction(controller => controller.PostItemAsync(null)); AssertExtended.IsBadResponseMessage(message, string.Empty); }