Permalink
Browse files

IDataServiceQueryProvider implementation seems good.

  • Loading branch information...
1 parent 17e5f0a commit 26751981bbdbeaa63adfde92ac11e2790edc7e84 @craiggwilson committed Aug 27, 2012
Showing with 941 additions and 150 deletions.
  1. +1 −0 .gitignore
  2. +30 −6 MongoDB.OData.sln
  3. +83 −0 src/MongoDB.OData.IntegrationTests/MongoDB.OData.IntegrationTests.csproj
  4. +36 −0 src/MongoDB.OData.IntegrationTests/Properties/AssemblyInfo.cs
  5. +9 −0 src/MongoDB.OData.IntegrationTests/packages.config
  6. +1 −1 src/MongoDB.OData.SampleHost/{Sample.svc → BlogApi.svc}
  7. +9 −10 src/MongoDB.OData.SampleHost/{Sample.svc.cs → BlogApi.svc.cs}
  8. +3 −0 src/MongoDB.OData.SampleHost/HumanResourcesApi.svc
  9. +103 −0 src/MongoDB.OData.SampleHost/HumanResourcesApi.svc.cs
  10. +45 −21 src/MongoDB.OData.SampleHost/MongoDB.OData.SampleHost.csproj
  11. +6 −6 src/MongoDB.OData.SampleHost/packages.config
  12. +1 −1 src/MongoDB.OData.SampleModels/{ → Blog}/Blog.cs
  13. +1 −1 src/MongoDB.OData.SampleModels/{ → Blog}/BlogPostSummary.cs
  14. +1 −1 src/MongoDB.OData.SampleModels/{ → Blog}/Comment.cs
  15. +1 −1 src/MongoDB.OData.SampleModels/{ → Blog}/Post.cs
  16. +1 −1 src/MongoDB.OData.SampleModels/{ → Blog}/User.cs
  17. +1 −1 src/MongoDB.OData.SampleModels/{ → Blog}/UserSummary.cs
  18. +12 −0 src/MongoDB.OData.SampleModels/HumanResources/Contractor.cs
  19. +14 −0 src/MongoDB.OData.SampleModels/HumanResources/Employee.cs
  20. +12 −0 src/MongoDB.OData.SampleModels/HumanResources/Manager.cs
  21. +14 −0 src/MongoDB.OData.SampleModels/HumanResources/Name.cs
  22. +14 −0 src/MongoDB.OData.SampleModels/HumanResources/Person.cs
  23. +14 −0 src/MongoDB.OData.SampleModels/HumanResources/PersonRef.cs
  24. +13 −6 src/MongoDB.OData.SampleModels/MongoDB.OData.SampleModels.csproj
  25. +97 −0 src/MongoDB.OData.UnitTests/MongoDB.OData.UnitTests.csproj
  26. +36 −0 src/MongoDB.OData.UnitTests/Properties/AssemblyInfo.cs
  27. +37 −0 src/MongoDB.OData.UnitTests/Specification.cs
  28. +204 −0 src/MongoDB.OData.UnitTests/TypedMongoDataServiceMetadataTests/When_mapping_a_hierarchy.cs
  29. +11 −0 src/MongoDB.OData.UnitTests/packages.config
  30. +20 −15 src/MongoDB.OData/MongoDB.OData.csproj
  31. +1 −0 src/MongoDB.OData/Properties/AssemblyInfo.cs
  32. +2 −2 src/MongoDB.OData/TypedMongoDataService.cs
  33. +92 −69 src/MongoDB.OData/{TypedMongoDataServiceMetadata.cs → TypedMongoDataServiceMetadataBuilder.cs}
  34. +10 −2 src/MongoDB.OData/TypedMongoDataServiceMetadataProvider.cs
  35. +6 −6 src/MongoDB.OData/packages.config
View
@@ -4,6 +4,7 @@ obj
*.user
*.suo
*.cache
+TestResults
# Nuget
packages
View
@@ -1,18 +1,22 @@

-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData", "src\MongoDB.OData\MongoDB.OData.csproj", "{FE1AD69A-98AB-4F2D-88C9-B7B449191912}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.SampleHost", "src\MongoDB.OData.SampleHost\MongoDB.OData.SampleHost.csproj", "{D9B7A239-9F4E-4E55-838D-4766EBEA5672}"
-EndProject
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C6F8D4C8-3816-48F4-A278-88D6CF8776B7}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
README.md = README.md
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData", "src\MongoDB.OData\MongoDB.OData.csproj", "{FE1AD69A-98AB-4F2D-88C9-B7B449191912}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.SampleHost", "src\MongoDB.OData.SampleHost\MongoDB.OData.SampleHost.csproj", "{D9B7A239-9F4E-4E55-838D-4766EBEA5672}"
+EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.SampleModels", "src\MongoDB.OData.SampleModels\MongoDB.OData.SampleModels.csproj", "{59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.IntegrationTests", "src\MongoDB.OData.IntegrationTests\MongoDB.OData.IntegrationTests.csproj", "{628EAB24-C5B8-47C4-B634-EECA4089BDA4}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.UnitTests", "src\MongoDB.OData.UnitTests\MongoDB.OData.UnitTests.csproj", "{079AA188-5BA0-437F-AAA2-3F4681393A15}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -53,6 +57,26 @@ Global
{59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}.Release|x86.ActiveCfg = Release|Any CPU
+ {628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Release|x86.ActiveCfg = Release|Any CPU
+ {079AA188-5BA0-437F-AAA2-3F4681393A15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {079AA188-5BA0-437F-AAA2-3F4681393A15}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {079AA188-5BA0-437F-AAA2-3F4681393A15}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {079AA188-5BA0-437F-AAA2-3F4681393A15}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {079AA188-5BA0-437F-AAA2-3F4681393A15}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {079AA188-5BA0-437F-AAA2-3F4681393A15}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {079AA188-5BA0-437F-AAA2-3F4681393A15}.Release|Any CPU.Build.0 = Release|Any CPU
+ {079AA188-5BA0-437F-AAA2-3F4681393A15}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {079AA188-5BA0-437F-AAA2-3F4681393A15}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {079AA188-5BA0-437F-AAA2-3F4681393A15}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{628EAB24-C5B8-47C4-B634-EECA4089BDA4}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>MongoDB.OData.IntegrationTests</RootNamespace>
+ <AssemblyName>MongoDB.OData.IntegrationTests</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </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.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\packages\Microsoft.Data.Edm.5.0.1\lib\net40\Microsoft.Data.Edm.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.OData, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\packages\Microsoft.Data.OData.5.0.1\lib\net40\Microsoft.Data.OData.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.Services, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\packages\Microsoft.Data.Services.5.0.1\lib\net40\Microsoft.Data.Services.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.Services.Client, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\packages\Microsoft.Data.Services.Client.5.0.1\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
+ </Reference>
+ <Reference Include="MongoDB.Bson">
+ <HintPath>..\..\packages\mongocsharpdriver.1.5\lib\net35\MongoDB.Bson.dll</HintPath>
+ </Reference>
+ <Reference Include="MongoDB.Driver">
+ <HintPath>..\..\packages\mongocsharpdriver.1.5\lib\net35\MongoDB.Driver.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Spatial, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\packages\System.Spatial.5.0.1\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.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\tools\NuGet\nuget.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -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("MongoDB.OData.IntegrationTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("MongoDB.OData.IntegrationTests")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
+[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("db1ce51c-c044-4790-8820-ae9c423ae9c3")]
+
+// 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")]
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Microsoft.Data.Edm" version="5.0.1" />
+ <package id="Microsoft.Data.OData" version="5.0.1" />
+ <package id="Microsoft.Data.Services" version="5.0.1" />
+ <package id="Microsoft.Data.Services.Client" version="5.0.1" />
+ <package id="mongocsharpdriver" version="1.5" />
+ <package id="System.Spatial" version="5.0.1" />
+</packages>
@@ -1,3 +1,3 @@

-<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Service="MongoDB.OData.SampleHost.Sample" %>
+<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Service="MongoDB.OData.SampleHost.BlogApi" %>
@@ -6,37 +6,36 @@
using System.ServiceModel.Web;
using System.Web;
using MongoDB.Driver;
-using MongoDB.OData.SampleModels;
+using MongoDB.OData.SampleModels.Blog;
namespace MongoDB.OData.SampleHost
{
- public class Sample : TypedMongoDataService
+ public class BlogApi : TypedMongoDataService
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
TypedMongoDataService.Configure(config);
-
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.UseVerboseErrors = true;
}
- protected override void BuildMetadata(TypedMongoDataServiceMetadata metadata)
+ protected override void BuildMetadata(TypedMongoDataServiceMetadataBuilder builder)
{
- metadata.SetContainer("MongoDB.Samples", "Blog");
- metadata.AddResourceSet<Blog>("Blogs", "odata", "blogs");
- metadata.AddResourceSet<Post>("Posts", "odata", "posts");
- metadata.AddResourceSet<User>("Users", "odata", "users");
+ builder.SetContainer("MongoDB.Samples", "BlogApi");
+ builder.AddResourceSet<Blog>("Blogs", "odata_blogs", "blogs");
+ builder.AddResourceSet<Post>("Posts", "odata_blogs", "posts");
+ builder.AddResourceSet<User>("Users", "odata_blogs", "users");
}
protected override MongoServer CreateDataSource()
{
var server = MongoServer.Create();
//create data if none exists...
- var db = server.GetDatabase("odata");
+ var db = server.GetDatabase("odata_blogs");
var userCollection = db.GetCollection<User>("users");
- var blogCollection = db.GetCollection<Blog>("blogs");
+ var blogCollection = db.GetCollection<BlogApi>("blogs");
var postsCollection = db.GetCollection<Post>("posts");
if (userCollection.Count() > 0)
@@ -0,0 +1,3 @@
+
+
+<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Service="MongoDB.OData.SampleHost.HumanResourcesApi" %>
@@ -0,0 +1,103 @@
+using System;
+using System.Collections.Generic;
+using System.Data.Services;
+using System.Data.Services.Common;
+using System.Linq;
+using System.ServiceModel.Web;
+using System.Web;
+using MongoDB.Bson.Serialization;
+using MongoDB.Driver;
+using MongoDB.OData.SampleModels.HumanResources;
+
+namespace MongoDB.OData.SampleHost
+{
+ public class HumanResourcesApi : TypedMongoDataService
+ {
+ // This method is called only once to initialize service-wide policies.
+ public static void InitializeService(DataServiceConfiguration config)
+ {
+ TypedMongoDataService.Configure(config);
+ config.SetEntitySetAccessRule("*", EntitySetRights.All);
+ config.UseVerboseErrors = true;
+ }
+
+ protected override void BuildMetadata(TypedMongoDataServiceMetadataBuilder builder)
+ {
+ if (!BsonClassMap.IsClassMapRegistered(typeof(Person)))
+ {
+ BsonClassMap.RegisterClassMap<Person>(cm =>
+ {
+ cm.AutoMap();
+ cm.SetIsRootClass(true);
+ cm.AddKnownType(typeof(Employee));
+ cm.AddKnownType(typeof(Manager));
+ cm.AddKnownType(typeof(Contractor));
+ });
+ }
+
+ builder.SetContainer("MongoDB.Samples", "HumanResources");
+ builder.AddResourceSet<Person>("People", "odata_hr", "people");
+ }
+
+ protected override MongoServer CreateDataSource()
+ {
+ var server = MongoServer.Create();
+
+ //create data if none exists...
+ var db = server.GetDatabase("odata_hr");
+
+ var people = db.GetCollection<Person>("people");
+
+ if (people.Count() > 0)
+ {
+ return server;
+ }
+
+ var employee1 = new Employee
+ {
+ Id = "Employee1",
+ HireDate = new DateTime(2005, 1, 1),
+ Name = new Name { First = "Jack", Last = "McJack" },
+ Salary = 1200
+ };
+
+ var employee2 = new Employee
+ {
+ Id = "Employee2",
+ HireDate = new DateTime(2007, 1, 1),
+ Name = new Name { First = "Jane", Last = "McJane" },
+ Salary = 1300
+ };
+
+ var contractor1 = new Contractor
+ {
+ Id = "Contractor1",
+ HireDate = new DateTime(2010, 1, 1),
+ Name = new Name { First = "Joe", Last = "McJoe" },
+ Salary = 300,
+ Address = "123 Main ST.",
+ };
+
+ var manager1 = new Manager
+ {
+ Id = "Manager1",
+ HireDate = new DateTime(2000, 1, 1),
+ Name = new Name { First = "Jim", Last = "McJim" },
+ Salary = 2000,
+ Employees = new List<PersonRef>
+ {
+ new PersonRef { Id = employee1.Id, Name = employee1.Name },
+ new PersonRef { Id = employee2.Id, Name = employee2.Name },
+ new PersonRef { Id = contractor1.Id, Name = contractor1.Name },
+ }
+ };
+
+ people.Save(employee1);
+ people.Save(employee2);
+ people.Save(contractor1);
+ people.Save(manager1);
+
+ return server;
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 2675198

Please sign in to comment.