creating oData client

testing odata interface
This commit is contained in:
2019-03-17 17:32:25 +01:00
parent e52bf0c3a5
commit bbe9f33571
24 changed files with 566 additions and 21 deletions

View File

@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{52BDCA0E-DC33-4398-BB6F-485CB07DE980}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>API.Client.Test</RootNamespace>
<AssemblyName>API.Client.Test</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Data.Edm, Version=5.8.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Edm.5.8.4\lib\net40\Microsoft.Data.Edm.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.OData, Version=5.8.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.OData.5.8.4\lib\net40\Microsoft.Data.OData.dll</HintPath>
</Reference>
<Reference Include="Microsoft.OData.Core, Version=7.5.3.21218, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.OData.Core.7.5.3\lib\portable-net45+win8+wpa81\Microsoft.OData.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.OData.Edm, Version=7.5.3.21218, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.OData.Edm.7.5.3\lib\portable-net45+win8+wpa81\Microsoft.OData.Edm.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Spatial, Version=7.5.3.21218, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Spatial.7.5.3\lib\portable-net45+win8+wpa81\Microsoft.Spatial.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="Simple.OData.Client.Core, Version=5.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Simple.OData.Client.5.6.2\lib\net452\Simple.OData.Client.Core.dll</HintPath>
</Reference>
<Reference Include="Simple.OData.Client.Dynamic, Version=5.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Simple.OData.Client.5.6.2\lib\net452\Simple.OData.Client.Dynamic.dll</HintPath>
</Reference>
<Reference Include="Simple.OData.Client.V3.Adapter, Version=5.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Simple.OData.Client.5.6.2\lib\net452\Simple.OData.Client.V3.Adapter.dll</HintPath>
</Reference>
<Reference Include="Simple.OData.Client.V4.Adapter, Version=5.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Simple.OData.Client.5.6.2\lib\net452\Simple.OData.Client.V4.Adapter.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Spatial, Version=5.8.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.Spatial.5.8.4\lib\net40\System.Spatial.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="OdataTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\API.Client\API.Client.csproj">
<Project>{88db6691-8ee1-428c-8da4-50342aeb2c54}</Project>
<Name>API.Client</Name>
</ProjectReference>
<ProjectReference Include="..\Models\API.Models.csproj">
<Project>{8d72ff7d-c085-4c06-9d66-9537b7ac924d}</Project>
<Name>API.Models</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />
</Project>

View File

@@ -0,0 +1,93 @@
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using API.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Simple.OData.Client;
namespace API.Client.Test {
[TestClass]
public class OdataTests {
private const string TEST_CASE_IDENTIFIER = "TESTCASE";
private static Song testSong;
[ClassInitialize]
public static async Task TestInitialize(TestContext tc) {
var client = new Client();
var newSong = new Song {
Name = Guid.NewGuid().ToString(),
Text = TEST_CASE_IDENTIFIER
};
testSong = await client.Post(newSong);
}
[ClassCleanup]
public static async Task ClassCleanup() {
var client = new Client();
var itemsToDelete = await client.Get(_ => _.Text == TEST_CASE_IDENTIFIER);
foreach (var item in itemsToDelete) {
await client.Delete(item.ID);
}
}
[TestMethod]
public async Task GetList() {
var client = new Client();
var data = await client.Get();
Assert.IsTrue(data.Any(_=>_.ID == testSong.ID));
}
[TestMethod]
public async Task GetItem() {
var client = new Client();
var item = await client.Get(testSong.ID);
Assert.AreEqual(testSong.Name, item.Name);
}
[TestMethod]
public async Task PostItem() {
var client = new Client();
var newSong = new Song {
Name = Guid.NewGuid().ToString(),
Text = TEST_CASE_IDENTIFIER
};
var response = await client.Post(newSong);
var insertedSong = await client.Get(response.ID);
Assert.AreEqual(newSong.Name, insertedSong.Name);
}
[TestMethod]
public async Task DeleteItem() {
var client = new Client();
var newSong = new Song {
Name = Guid.NewGuid().ToString(),
Text = TEST_CASE_IDENTIFIER
};
var response = await client.Post(newSong);
var insertedSong = await client.Get(response.ID);
Assert.AreEqual(newSong.Name, insertedSong.Name);
var count = await client.Delete(response.ID);
Assert.AreEqual(1, count);
try {
await client.Get(response.ID);
Assert.Fail("WebRequestException not thrown");
} catch (WebRequestException ex) {
Assert.AreEqual(HttpStatusCode.NotFound, ex.Code);
}
}
}
}

View File

@@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("API.Client.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("API.Client.Test")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("52bdca0e-dc33-4398-bb6f-485cb07de980")]
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Data.Edm" version="5.8.4" targetFramework="net462" />
<package id="Microsoft.Data.OData" version="5.8.4" targetFramework="net462" />
<package id="Microsoft.OData.Core" version="7.5.3" targetFramework="net462" />
<package id="Microsoft.OData.Edm" version="7.5.3" targetFramework="net462" />
<package id="Microsoft.Spatial" version="7.5.3" targetFramework="net462" />
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net462" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net462" />
<package id="Simple.OData.Client" version="5.6.2" targetFramework="net462" />
<package id="System.Spatial" version="5.8.4" targetFramework="net462" />
</packages>