diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9b92a1f..b64eeca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,8 @@
* ADDED: Support for paging with page and per_page
* ADDED: User defined location for the static files (including SPAs)
* ADDED: Console parameter for help and version
-
+* FIXED: Adding to the empty collection will use the value of the id-field if it is set
+
### [0.8.0] - 2018-10-14
* Release as a dotnet tool
* Use executable location as a base path for settings files
diff --git a/FakeServer.Test/FakeServer.Test.csproj b/FakeServer.Test/FakeServer.Test.csproj
index 225ee70..c16a79a 100644
--- a/FakeServer.Test/FakeServer.Test.csproj
+++ b/FakeServer.Test/FakeServer.Test.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/FakeServer.Test/FakeServerSpecs.cs b/FakeServer.Test/FakeServerSpecs.cs
index f50050a..aa6d7af 100644
--- a/FakeServer.Test/FakeServerSpecs.cs
+++ b/FakeServer.Test/FakeServerSpecs.cs
@@ -571,7 +571,46 @@ public async Task PostAndDeleteItem_NewCollection()
{
using (var client = new HttpClient())
{
- var newUser = new { id = 1, name = "Newton" };
+ var newUser = new { id = 256, name = "Newton" };
+
+ var result = await client.GetAsync($"{_fixture.BaseUrl}/api/");
+ result.EnsureSuccessStatusCode();
+ var collections = JsonConvert.DeserializeObject>(await result.Content.ReadAsStringAsync());
+ var originalAmount = collections.Count();
+
+ var content = new StringContent(JsonConvert.SerializeObject(newUser), Encoding.UTF8, "application/json");
+ result = await client.PostAsync($"{_fixture.BaseUrl}/api/hello", content);
+ result.EnsureSuccessStatusCode();
+
+ result = await client.GetAsync($"{_fixture.BaseUrl}/api");
+ result.EnsureSuccessStatusCode();
+ collections = JsonConvert.DeserializeObject>(await result.Content.ReadAsStringAsync());
+ Assert.Equal(originalAmount + 1, collections.Count());
+
+ result = await client.GetAsync($"{_fixture.BaseUrl}/api/hello/256");
+ result.EnsureSuccessStatusCode();
+ var item = JsonConvert.DeserializeObject(await result.Content.ReadAsStringAsync());
+ Assert.Equal(newUser.name, item["name"].Value());
+
+ result = await client.GetAsync($"{_fixture.BaseUrl}/api/hello");
+ result.EnsureSuccessStatusCode();
+ var items = JsonConvert.DeserializeObject>(await result.Content.ReadAsStringAsync());
+ Assert.Single(items);
+
+ result = await client.DeleteAsync($"{_fixture.BaseUrl}/api/hello/256");
+ result.EnsureSuccessStatusCode();
+
+ result = await client.GetAsync($"{_fixture.BaseUrl}/api/hello");
+ Assert.Equal(HttpStatusCode.NotFound, result.StatusCode);
+ }
+ }
+
+ [Fact]
+ public async Task PostAndDeleteItem_NewCollection_NoId()
+ {
+ using (var client = new HttpClient())
+ {
+ var newUser = new { name = "Newton" };
var result = await client.GetAsync($"{_fixture.BaseUrl}/api/");
result.EnsureSuccessStatusCode();
diff --git a/FakeServer/FakeServer.csproj b/FakeServer/FakeServer.csproj
index 6ebf27b..c05404d 100644
--- a/FakeServer/FakeServer.csproj
+++ b/FakeServer/FakeServer.csproj
@@ -33,7 +33,7 @@
-->
-
+
@@ -42,7 +42,7 @@
-
+
@@ -50,7 +50,7 @@
-
+
diff --git a/README.md b/README.md
index 34d8572..7dcd225 100644
--- a/README.md
+++ b/README.md
@@ -894,6 +894,7 @@ Headers:
Location=http://localhost:57602/api/users/6
```
+If collection is empty and new item has an _id-field_ set, it will be used a first _id-value_. If _id-field_ is not set, _id-value_ will start from `0`.
#### Replace item
```