public async Task CreateItem_MissingId_Returns201_AndCreatesId() { var item = new HUnit { Data = "create-item-missing-id-returns-201" }; var response = await SendRequestToServer <HUnit>(HttpMethod.Post, "tables/hunits", item); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); var actual = await GetValueFromResponse <HUnit>(response); Assert.IsNotNull(actual.Id); // Check existence of Id Assert.IsNotNull(new Guid(actual.Id)); // Make sure it is a real GUID Assert.AreEqual(item.Data, actual.Data); Assert.IsTrue(actual.Version.Length > 0); HttpAssert.IsWithin(DateTimeOffset.UtcNow, actual.UpdatedAt, 1000); HttpAssert.AreEqual(actual.Version, response.Headers.ETag); HttpAssert.Match(actual.UpdatedAt, response.Content.Headers.LastModified); var dbItem = GetItemFromDb <HUnit>(actual.Id); Assert.IsNotNull(dbItem); Assert.AreEqual(item.Data, dbItem.Data); }
public async Task CreateItem_MissingItem_Returns201() { var item = new HUnit { Id = Guid.NewGuid().ToString("N"), Data = "create-item-missing-item-returns-201" }; var response = await SendRequestToServer <HUnit>(HttpMethod.Post, "tables/hunits", item); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); var actual = await GetValueFromResponse <HUnit>(response); Assert.AreEqual(item.Id, actual.Id); Assert.AreEqual(item.Data, actual.Data); Assert.IsTrue(actual.Version.Length > 0); HttpAssert.IsWithin(DateTimeOffset.UtcNow, actual.UpdatedAt, 1000); HttpAssert.AreEqual(actual.Version, response.Headers.ETag); HttpAssert.Match(actual.UpdatedAt, response.Content.Headers.LastModified); var dbItem = GetItemFromDb <HUnit>(item.Id); Assert.IsNotNull(dbItem); Assert.AreEqual(item.Data, dbItem.Data); }
public async Task ReplaceItem_PreconditionsSucceed_Returns200() { var item = GetItemFromDb <HUnit>("hunit-8"); var originalData = item.Data; item.Data = "Replaced"; var response = await SendRequestToServer <HUnit>(HttpMethod.Put, $"/tables/hunits/{item.Id}", item, new Dictionary <string, string> { { "If-Match", ETag.FromByteArray(item.Version) } }); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); var actual = await GetValueFromResponse <HUnit>(response); Assert.AreEqual(item.Id, actual.Id); Assert.AreEqual(item.Data, actual.Data); Assert.IsTrue(actual.Version.Length > 0); HttpAssert.IsWithin(DateTimeOffset.UtcNow, actual.UpdatedAt, 1000); HttpAssert.AreEqual(actual.Version, response.Headers.ETag); HttpAssert.Match(actual.UpdatedAt, response.Content.Headers.LastModified); var dbItem = GetItemFromDb <HUnit>(item.Id); Assert.IsNotNull(dbItem); Assert.AreEqual(item.Data, dbItem.Data); }
public async Task ReplaceItem_ValidId_Returns200() { var item = new HUnit() { Id = "hunit-6", Data = "Replaced" }; var response = await SendRequestToServer <HUnit>(HttpMethod.Put, $"/tables/hunits/{item.Id}", item); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); var actual = await GetValueFromResponse <HUnit>(response); Assert.AreEqual(item.Id, actual.Id); Assert.AreEqual(item.Data, actual.Data); Assert.IsTrue(actual.Version.Length > 0); HttpAssert.IsWithin(DateTimeOffset.UtcNow, actual.UpdatedAt, 1000); HttpAssert.AreEqual(actual.Version, response.Headers.ETag); HttpAssert.Match(actual.UpdatedAt, response.Content.Headers.LastModified); var dbItem = GetItemFromDb <HUnit>(item.Id); Assert.IsNotNull(dbItem); Assert.AreEqual(item.Data, dbItem.Data); }
public async Task PatchItem_PreconditionsSucceed_Returns200() { var item = await GetItemFromDb <HUnit>("hunit-14"); var patchDoc = @"[{ ""op"": ""replace"", ""path"": ""/Data"", ""value"": ""Replaced"" }]"; var response = await SendRequestToServer(HttpMethod.Patch, $"/tables/hunits/{item.Id}", patchDoc, new Dictionary <string, string> { { "If-Match", ETag.FromByteArray(item.Version) } }); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); var actual = await GetValueFromResponse <HUnit>(response); Assert.AreEqual(item.Id, actual.Id); Assert.AreEqual("Replaced", actual.Data); Assert.IsTrue(actual.Version.Length > 0); HttpAssert.IsWithin(DateTimeOffset.UtcNow, actual.UpdatedAt, 1000); HttpAssert.AreEqual(actual.Version, response.Headers.ETag); HttpAssert.Match(actual.UpdatedAt, response.Content.Headers.LastModified); var dbItem = await GetItemFromDb <HUnit>(item.Id); Assert.IsNotNull(dbItem); Assert.AreEqual("Replaced", dbItem.Data); }