public void UpdatingAProduct(ProductModel user, long productId) { "Given an existing user". f(() => ManagementServiceMock.Setup(m => m.UpdateProductAsync(It.IsAny<ProductUpdateModel>(), productId)).ReturnsAsync(1)); "When a PUT request is made". f(() => { dynamic dto = JObject.FromObject(new { description = "TEST_DESCRIPTION", name = "TEST_NAME", quantityAvailable = 99, }); Request.Method = HttpMethod.Put; Request.RequestUri = new Uri(string.Format("{0}/{1}", ProductsUrl, productId)); Request.Content = new ObjectContent<dynamic>(dto, new JsonMediaTypeFormatter()); Response = Client.SendAsync(Request).Result; }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldBe(HttpStatusCode.OK)); "And the user should be updated". f(() => ManagementServiceMock.Verify(m => m.UpdateProductAsync(It.IsAny<ProductUpdateModel>(), productId), Times.Once())); }
public void RetrievingAProduct(ProductModel product, long productId) { "Given an existing product". f(() => ManagementServiceMock.Setup(m => m.GetProductAsync(productId)).ReturnsAsync(new ProductModel {Id = productId})); "When it is retrieved". f(() => { Request.RequestUri = new Uri(string.Format("{0}/{1}", ProductsUrl, productId)); Response = Client.SendAsync(Request).Result; product = Response.Content.ReadAsAsync<ProductModel>().Result; }); "Then the product should be retrieved". f(() => ManagementServiceMock.Verify(m => m.GetProductAsync(productId), Times.Once())); "And a '200 OK' status is returned". f(() => Response.StatusCode.ShouldBe(HttpStatusCode.OK)); "Then it is returned". f(() => product.ShouldNotBe(null)); "And it should have an id". f(() => product.Id.ShouldBe(productId)); }