file detail edit api

This commit is contained in:
2019-03-28 15:46:52 +01:00
parent d9f2724101
commit cccdfb4a44
7 changed files with 111 additions and 81 deletions

View File

@@ -1,39 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="url" value="http://localhost/API" />
<!--<add key="url" value="http://test.benjamin-ifland.de"/>-->
<!--<add key="url" value="http://localhost/API" />-->
<add key="url" value="http://test.benjamin-ifland.de"/>
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.OData.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.5.4.30215" newVersion="7.5.4.30215" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.OData.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.5.4.30215" newVersion="7.5.4.30215" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.5.4.30215" newVersion="7.5.4.30215" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.OData.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.5.4.30215" newVersion="7.5.4.30215" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.OData.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.5.4.30215" newVersion="7.5.4.30215" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.5.4.30215" newVersion="7.5.4.30215" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@@ -1,10 +1,11 @@
using System;
using API.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Simple.OData.Client;
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using API.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Simple.OData.Client;
using File = System.IO.File;
namespace API.Client.Test {
[TestClass]
@@ -12,7 +13,7 @@ namespace API.Client.Test {
private const string TEST_CASE_IDENTIFIER = "TESTCASE";
private static Song testSong;
[ClassInitialize]
public static async Task TestInitialize(TestContext tc) {
@@ -39,7 +40,7 @@ namespace API.Client.Test {
var client = new Client();
var data = await client.Get();
Assert.IsTrue(data.Any(_=>_.ID == testSong.ID));
Assert.IsTrue(data.Any(_ => _.ID == testSong.ID));
}
[TestMethod]
@@ -64,6 +65,29 @@ namespace API.Client.Test {
Assert.AreEqual(newSong.Name, insertedSong.Name);
}
[TestMethod]
public async Task PatchItem() {
var client = new Client();
var newSong = new Song {
Name = Guid.NewGuid().ToString(),
Text = TEST_CASE_IDENTIFIER,
Comments = "Item to Patch"
};
var response = await client.Post(newSong);
try {
var patchedSong = await client.Patch(response.ID, new { Comments = "patched" });
} catch (WebRequestException ex) {
File.WriteAllText("error.html", ex.Response);
throw;
}
var insertedSong = await client.Get(response.ID);
Assert.AreEqual("patched", insertedSong.Comments);
Assert.AreEqual(newSong.Name, insertedSong.Name);
Assert.AreEqual(TEST_CASE_IDENTIFIER, insertedSong.Text);
}
[TestMethod]
public async Task DeleteItem() {
var client = new Client();
@@ -75,9 +99,14 @@ namespace API.Client.Test {
var response = await client.Post(newSong);
var insertedSong = await client.Get(response.ID);
Assert.AreEqual(newSong.Name, insertedSong.Name);
try {
var count = await client.Delete(response.ID);
Assert.AreEqual(1, count);
var count = await client.Delete(response.ID);
Assert.AreEqual(1, count);
} catch (WebRequestException ex) {
File.WriteAllText("error.html", ex.Response);
throw;
}
try {
await client.Get(response.ID);