creating oData client
testing odata interface
This commit is contained in:
108
API/API.Client.Test/API.Client.Test.csproj
Normal file
108
API/API.Client.Test/API.Client.Test.csproj
Normal 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>
|
||||
93
API/API.Client.Test/OdataTests.cs
Normal file
93
API/API.Client.Test/OdataTests.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
20
API/API.Client.Test/Properties/AssemblyInfo.cs
Normal file
20
API/API.Client.Test/Properties/AssemblyInfo.cs
Normal 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")]
|
||||
12
API/API.Client.Test/packages.config
Normal file
12
API/API.Client.Test/packages.config
Normal 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>
|
||||
91
API/API.Client/API.Client.csproj
Normal file
91
API/API.Client/API.Client.csproj
Normal file
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<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>{88DB6691-8EE1-428C-8DA4-50342AEB2C54}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>API.Client</RootNamespace>
|
||||
<AssemblyName>API.Client</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</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="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>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Client.cs" />
|
||||
<Compile Include="Expresseion.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Connected Services\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Models\API.Models.csproj">
|
||||
<Project>{8d72ff7d-c085-4c06-9d66-9537b7ac924d}</Project>
|
||||
<Name>API.Models</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
44
API/API.Client/Client.cs
Normal file
44
API/API.Client/Client.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
using API.Models;
|
||||
using Simple.OData.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace API.Client {
|
||||
public class Client {
|
||||
|
||||
public async Task<IEnumerable<Song>> Get() {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var songs = await client.FindEntriesAsync();
|
||||
return songs;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Song>> Get(Expression<Func<Song, bool>> filterExpression) {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var songs = await client.Filter(filterExpression).FindEntriesAsync();
|
||||
return songs;
|
||||
}
|
||||
|
||||
public async Task<Song> Get(long id) {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var song = await client.Key(id).FindEntryAsync();
|
||||
return song;
|
||||
}
|
||||
|
||||
public async Task<Song> Post(Song song) {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var insertedSong = await client.Set(song).InsertEntryAsync();
|
||||
return insertedSong;
|
||||
}
|
||||
|
||||
public async Task<int> Delete(long id) {
|
||||
var client = new ODataClient("http://localhost/API/odata").For<Song>();
|
||||
var count = await client.Key(id).DeleteEntriesAsync();
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
4
API/API.Client/Expresseion.cs
Normal file
4
API/API.Client/Expresseion.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
namespace API.Client {
|
||||
public class Expression {
|
||||
}
|
||||
}
|
||||
36
API/API.Client/Properties/AssemblyInfo.cs
Normal file
36
API/API.Client/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("API.Client")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("API.Client")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("88db6691-8ee1-428c-8da4-50342aeb2c54")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
10
API/API.Client/packages.config
Normal file
10
API/API.Client/packages.config
Normal file
@@ -0,0 +1,10 @@
|
||||
<?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="Simple.OData.Client" version="5.6.2" targetFramework="net462" />
|
||||
<package id="System.Spatial" version="5.8.4" targetFramework="net462" />
|
||||
</packages>
|
||||
25
API/API.sln
25
API/API.sln
@@ -9,6 +9,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API.Test", "API.Test\API.Te
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Backend", "Backend", "{5DD4FA9B-976C-4CDB-9E73-CF3485DBDD72}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API.Client", "API.Client\API.Client.csproj", "{88DB6691-8EE1-428C-8DA4-50342AEB2C54}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API.Client.Test", "API.Client.Test\API.Client.Test.csproj", "{52BDCA0E-DC33-4398-BB6F-485CB07DE980}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client", "Client", "{D89C3FFE-4990-4B35-977C-727F89D7D05E}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{E1B05E83-7E28-47D6-9DB5-3C1B2293AA92}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API.Models", "Models\API.Models.csproj", "{8D72FF7D-C085-4C06-9D66-9537B7AC924D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -23,6 +33,18 @@ Global
|
||||
{84714616-89D7-4A5D-86D8-2DC395530FEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{84714616-89D7-4A5D-86D8-2DC395530FEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{84714616-89D7-4A5D-86D8-2DC395530FEB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{88DB6691-8EE1-428C-8DA4-50342AEB2C54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{88DB6691-8EE1-428C-8DA4-50342AEB2C54}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{88DB6691-8EE1-428C-8DA4-50342AEB2C54}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{88DB6691-8EE1-428C-8DA4-50342AEB2C54}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{52BDCA0E-DC33-4398-BB6F-485CB07DE980}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{52BDCA0E-DC33-4398-BB6F-485CB07DE980}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{52BDCA0E-DC33-4398-BB6F-485CB07DE980}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{52BDCA0E-DC33-4398-BB6F-485CB07DE980}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8D72FF7D-C085-4C06-9D66-9537B7AC924D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8D72FF7D-C085-4C06-9D66-9537B7AC924D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8D72FF7D-C085-4C06-9D66-9537B7AC924D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8D72FF7D-C085-4C06-9D66-9537B7AC924D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -30,6 +52,9 @@ Global
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{27056FE2-5A34-44B2-9196-6F19C04F27CC} = {5DD4FA9B-976C-4CDB-9E73-CF3485DBDD72}
|
||||
{84714616-89D7-4A5D-86D8-2DC395530FEB} = {5DD4FA9B-976C-4CDB-9E73-CF3485DBDD72}
|
||||
{88DB6691-8EE1-428C-8DA4-50342AEB2C54} = {D89C3FFE-4990-4B35-977C-727F89D7D05E}
|
||||
{52BDCA0E-DC33-4398-BB6F-485CB07DE980} = {D89C3FFE-4990-4B35-977C-727F89D7D05E}
|
||||
{8D72FF7D-C085-4C06-9D66-9537B7AC924D} = {E1B05E83-7E28-47D6-9DB5-3C1B2293AA92}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {27650156-7B3F-4C0C-83D3-D13119DE083F}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<AssemblyName>API</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<MvcBuildViews>false</MvcBuildViews>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<UseIISExpress>false</UseIISExpress>
|
||||
<Use64BitIISExpress />
|
||||
<IISExpressSSLPort />
|
||||
<IISExpressAnonymousAuthentication />
|
||||
@@ -130,13 +130,6 @@
|
||||
<Compile Include="App_Start\WebApiConfig.cs" />
|
||||
<Compile Include="Controllers\SongsController.cs" />
|
||||
<Compile Include="Database\DataContext.cs" />
|
||||
<Compile Include="Database\Model\Access.cs" />
|
||||
<Compile Include="Database\Model\Change.cs" />
|
||||
<Compile Include="Database\Model\File.cs" />
|
||||
<Compile Include="Database\Model\FileType.cs" />
|
||||
<Compile Include="Database\Model\Song.cs" />
|
||||
<Compile Include="Database\Model\SongType.cs" />
|
||||
<Compile Include="Database\Model\User.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
@@ -160,7 +153,12 @@
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Models\API.Models.csproj">
|
||||
<Project>{8d72ff7d-c085-4c06-9d66-9537b7ac924d}</Project>
|
||||
<Name>API.Models</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
@@ -187,7 +185,7 @@
|
||||
<AutoAssignPort>True</AutoAssignPort>
|
||||
<DevelopmentServerPort>50752</DevelopmentServerPort>
|
||||
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
||||
<IISUrl>http://localhost:50752/</IISUrl>
|
||||
<IISUrl>http://localhost/API</IISUrl>
|
||||
<NTLMAuthentication>False</NTLMAuthentication>
|
||||
<UseCustomServer>False</UseCustomServer>
|
||||
<CustomServerUrl>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using API.App_Start;
|
||||
using API.Database.Model;
|
||||
using API.Models;
|
||||
using Microsoft.AspNet.OData.Builder;
|
||||
using Microsoft.AspNet.OData.Extensions;
|
||||
using System.Net.Http.Headers;
|
||||
@@ -22,6 +22,7 @@ namespace API {
|
||||
// Web API oData configuration
|
||||
var builder = new ODataConventionModelBuilder();
|
||||
builder.EntitySet<Song>("songs");
|
||||
config.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
|
||||
config.MapODataServiceRoute(
|
||||
routeName: "songs",
|
||||
routePrefix: "odata",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using API.Database;
|
||||
using API.Database.Model;
|
||||
using API.Models;
|
||||
using Microsoft.AspNet.OData;
|
||||
using System.Data.Entity;
|
||||
using System.Data.Entity.Infrastructure;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
namespace ProductService.Controllers {
|
||||
@@ -73,6 +74,15 @@ namespace ProductService.Controllers {
|
||||
return Updated(update);
|
||||
}
|
||||
|
||||
public async Task<IHttpActionResult> Delete([FromODataUri] int key) {
|
||||
var product = await db.Songs.FindAsync(key);
|
||||
if (product == null) {
|
||||
return NotFound();
|
||||
}
|
||||
db.Songs.Remove(product);
|
||||
await db.SaveChangesAsync();
|
||||
return StatusCode(HttpStatusCode.NoContent);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
using API.Database.Model;
|
||||
using API.Models;
|
||||
using System.Data.Entity;
|
||||
|
||||
namespace API.Database {
|
||||
public class DataContext : DbContext {
|
||||
|
||||
public DataContext() : base("DataContext") { }
|
||||
|
||||
public DbSet<Song> Songs { get; set; }
|
||||
public DbSet<Change> Changes { get; set; }
|
||||
public DbSet<File> Files { get; set; }
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</configSections>
|
||||
<connectionStrings>
|
||||
<add name="DataContext" connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=wgenerator;Integrated Security=True;User ID=sa;Password=sa" providerName="System.Data.SqlClient" />
|
||||
<add name="DataContext" connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=wgenerator;User ID=sa;Password=sa" providerName="System.Data.SqlClient" />
|
||||
</connectionStrings>
|
||||
<appSettings>
|
||||
<add key="webpages:Version" value="3.0.0.0" />
|
||||
|
||||
54
API/Models/API.Models.csproj
Normal file
54
API/Models/API.Models.csproj
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<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>{8D72FF7D-C085-4C06-9D66-9537B7AC924D}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Models</RootNamespace>
|
||||
<AssemblyName>Models</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</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="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Access.cs" />
|
||||
<Compile Include="Change.cs" />
|
||||
<Compile Include="File.cs" />
|
||||
<Compile Include="FileType.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Song.cs" />
|
||||
<Compile Include="SongType.cs" />
|
||||
<Compile Include="User.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace API.Database.Model {
|
||||
namespace API.Models {
|
||||
public enum Access {
|
||||
Inactive,
|
||||
Reader,
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace API.Database.Model {
|
||||
namespace API.Models {
|
||||
public class Change {
|
||||
public int ID { get; set; }
|
||||
public int UserId { get; set; }
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace API.Database.Model {
|
||||
namespace API.Models {
|
||||
public class File {
|
||||
public int ID { get; set; }
|
||||
public Guid ReferenceFile { get; set; }
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace API.Database.Model {
|
||||
namespace API.Models {
|
||||
public enum FileType {
|
||||
None,
|
||||
Sheet,
|
||||
36
API/Models/Properties/AssemblyInfo.cs
Normal file
36
API/Models/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Models")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Models")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("8d72ff7d-c085-4c06-9d66-9537b7ac924d")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace API.Database.Model {
|
||||
namespace API.Models {
|
||||
public class Song {
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace API.Database.Model {
|
||||
namespace API.Models {
|
||||
public enum SongType {
|
||||
Praise,
|
||||
Worship
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace API.Database.Model {
|
||||
namespace API.Models {
|
||||
public class User {
|
||||
public int ID { get; set; }
|
||||
public string Account { get; set; }
|
||||
Reference in New Issue
Block a user