Permalink
Browse files

Upgraded to WCF Data Services 5.0. Various bug fixes.

  • Loading branch information...
object committed May 28, 2012
1 parent 79072f5 commit a8289a6ec0f198eec47112ccc15b478500213d0e
View
@@ -20,3 +20,5 @@
[assembly: AssemblyVersion("0.5.0.0")]
[assembly: AssemblyFileVersion("0.5.0.0")]
+[assembly: AssemblyInformationalVersion("0.5.0.0")]
+
@@ -50,12 +50,24 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Microsoft.Data.Edm">
+ <HintPath>..\packages\Microsoft.Data.Edm.5.0.1\lib\net40\Microsoft.Data.Edm.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.OData">
+ <HintPath>..\packages\Microsoft.Data.OData.5.0.1\lib\net40\Microsoft.Data.OData.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.Services">
+ <HintPath>..\packages\Microsoft.Data.Services.5.0.1\lib\net40\Microsoft.Data.Services.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.Services.Client">
+ <HintPath>..\packages\Microsoft.Data.Services.Client.5.0.1\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
- <Reference Include="System.Data.Services" />
- <Reference Include="System.Data.Services.Client" />
+ <Reference Include="System.Spatial">
+ <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="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
@@ -102,6 +114,9 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />
</Project>
@@ -0,0 +1,8 @@
+<?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="System.Spatial" version="5.0.1" />
+</packages>
@@ -33,6 +33,18 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Microsoft.Data.Edm">
+ <HintPath>..\packages\Microsoft.Data.Edm.5.0.1\lib\net40\Microsoft.Data.Edm.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.OData">
+ <HintPath>..\packages\Microsoft.Data.OData.5.0.1\lib\net40\Microsoft.Data.OData.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.Services">
+ <HintPath>..\packages\Microsoft.Data.Services.5.0.1\lib\net40\Microsoft.Data.Services.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.Services.Client">
+ <HintPath>..\packages\Microsoft.Data.Services.Client.5.0.1\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
+ </Reference>
<Reference Include="MongoDB.Bson, Version=1.4.2.4500, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\mongocsharpdriver.1.4.2\lib\net35\MongoDB.Bson.dll</HintPath>
@@ -45,31 +57,31 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll</HintPath>
</Reference>
- <Reference Include="Simple.Data, Version=0.16.1.0, Culture=neutral, processorArchitecture=MSIL">
+ <Reference Include="Simple.Data, Version=0.16.2.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Simple.Data.Core.0.16.1.0\lib\net40\Simple.Data.dll</HintPath>
+ <HintPath>..\packages\Simple.Data.Core.0.16.2.1\lib\net40\Simple.Data.dll</HintPath>
</Reference>
- <Reference Include="Simple.Data.OData, Version=0.2.2.0, Culture=neutral, processorArchitecture=MSIL">
+ <Reference Include="Simple.Data.OData, Version=0.2.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Simple.Data.OData.0.2.2.0\lib\net40\Simple.Data.OData.dll</HintPath>
+ <HintPath>..\packages\Simple.Data.OData.0.2.4.0\lib\net40\Simple.Data.OData.dll</HintPath>
</Reference>
<Reference Include="Simple.NExtLib, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
- <HintPath>..\packages\Simple.Data.OData.0.2.2.0\lib\net40\Simple.NExtLib.dll</HintPath>
+ <HintPath>..\packages\Simple.Data.OData.0.2.4.0\lib\net40\Simple.NExtLib.dll</HintPath>
</Reference>
- <Reference Include="Simple.OData, Version=0.2.2.0, Culture=neutral, processorArchitecture=MSIL">
+ <Reference Include="Simple.OData, Version=0.2.4.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\Simple.Data.OData.0.2.2.0\lib\net40\Simple.OData.dll</HintPath>
+ <HintPath>..\packages\Simple.Data.OData.0.2.4.0\lib\net40\Simple.OData.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
- <Reference Include="System.Data.Services" />
- <Reference Include="System.Data.Services.Client" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
+ <Reference Include="System.Spatial">
+ <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" />
@@ -22,7 +22,7 @@ public ProductInMemoryService()
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
- config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V2;
+ config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V3;
config.DataServiceBehavior.AcceptCountRequests = true;
config.DataServiceBehavior.AcceptProjectionRequests = true;
config.UseVerboseErrors = true;
@@ -39,7 +39,7 @@ public ProductQueryableService()
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.All);
- config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V2;
+ config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V3;
config.DataServiceBehavior.AcceptCountRequests = true;
config.DataServiceBehavior.AcceptProjectionRequests = true;
config.UseVerboseErrors = true;
@@ -37,9 +37,18 @@ public void TestFixtureTearDown()
[SetUp]
public void SetUp()
{
+ TestService.Configuration = new MongoConfiguration { MetadataBuildStrategy = new MongoConfiguration.Metadata { PrefetchRows = -1, UpdateDynamically = false } };
ctx = Database.Opener.Open(service.ServiceUri);
}
+ [Test]
+ public void Metadata()
+ {
+ var request = (HttpWebRequest)WebRequest.Create(service.ServiceUri + "/$metadata");
+ var response = (HttpWebResponse)request.GetResponse();
+ Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "The $metadata didn't return success.");
+ }
+
[Test]
public void AllEntitiesVerifyResultCount()
{
@@ -89,6 +98,21 @@ public void AllEntitiesVerifyReleaseDate()
Assert.AreEqual(new DateTime(1992, 1, 1), result[0].ReleaseDate, "The ReleaseDate is not correctly filled.");
}
+ [Test]
+ public void AllEntitiesVerifyNullDiscontinueDate()
+ {
+ var result = ctx.Products.All().ToList();
+ Assert.Null(result[0].DiscontinueDate, "The DiscontinueDate must be null.");
+ Assert.Null(result[1].DiscontinueDate, "The DiscontinueDate must be null.");
+ }
+
+ [Test]
+ public void AllEntitiesVerifyNonNullDiscontinueDate()
+ {
+ var result = ctx.Products.All().ToList();
+ Assert.NotNull(result[2].DiscontinueDate, "The DiscontinueDate must not be null.");
+ }
+
[Test]
public void AllEntitiesOrderby()
{
@@ -1,7 +1,12 @@
<?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.4.2" />
<package id="NUnit" version="2.6.0.12054" />
- <package id="Simple.Data.Core" version="0.16.1.0" />
- <package id="Simple.Data.OData" version="0.2.2.0" />
+ <package id="Simple.Data.Core" version="0.16.2.1" />
+ <package id="Simple.Data.OData" version="0.2.4.0" />
+ <package id="System.Spatial" version="5.0.1" />
</packages>
@@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using DataServiceProvider;
+using MongoDB.Bson;
namespace Mongo.Context.InMemory
{
@@ -39,19 +40,23 @@ private void PopulateData(DSPInMemoryContext dspContext, MongoContext mongoConte
if (this.mongoMetadata.Configuration.UpdateDynamically)
{
- var resourceType = mongoMetadata.ResolveResourceType(resourceSet.Name);
- foreach (var element in document.Elements)
- {
- var propertyName = MongoMetadata.GetResourcePropertyName(element);
- var resourceProperty = resourceType.Properties.SingleOrDefault(x => x.Name == propertyName);
- if (resourceProperty == null)
- {
- mongoMetadata.UpdateResourceType(mongoContext, resourceType, element);
- }
- }
+ UpdateMetadataFromResourceSet(mongoContext, resourceSet, document);
}
}
}
}
+
+ private void UpdateMetadataFromResourceSet(MongoContext mongoContext, ResourceSet resourceSet, BsonDocument document)
+ {
+ var resourceType = mongoMetadata.ResolveResourceType(resourceSet.Name);
+ foreach (var element in document.Elements)
+ {
+ var resourceProperty = mongoMetadata.ResolveResourceProperty(resourceType, element);
+ if (resourceProperty == null)
+ {
+ mongoMetadata.UpdateResourceType(mongoContext, resourceType, element);
+ }
+ }
+ }
}
}
@@ -33,6 +33,18 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Microsoft.Data.Edm">
+ <HintPath>..\packages\Microsoft.Data.Edm.5.0.1\lib\net40\Microsoft.Data.Edm.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.OData">
+ <HintPath>..\packages\Microsoft.Data.OData.5.0.1\lib\net40\Microsoft.Data.OData.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.Services">
+ <HintPath>..\packages\Microsoft.Data.Services.5.0.1\lib\net40\Microsoft.Data.Services.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Data.Services.Client">
+ <HintPath>..\packages\Microsoft.Data.Services.Client.5.0.1\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
+ </Reference>
<Reference Include="MongoDB.Bson, Version=1.4.2.4500, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\mongocsharpdriver.1.4.2\lib\net35\MongoDB.Bson.dll</HintPath>
@@ -44,9 +56,10 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
- <Reference Include="System.Data.Services" />
+ <Reference Include="System.Spatial">
+ <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" />
@@ -16,9 +16,7 @@ public MongoContext(string connectionString)
{
this.connectionString = connectionString;
this.server = MongoServer.Create(this.connectionString);
- string databaseName = connectionString.Substring(
- connectionString.IndexOf("localhost") + 10,
- connectionString.IndexOf("?") - connectionString.IndexOf("localhost") - 10);
+ string databaseName = GetDatabaseName(this.connectionString);
this.database = server.GetDatabase(databaseName);
}
@@ -40,5 +38,24 @@ public void Dispose()
public void SaveChanges()
{
}
+
+ private string GetDatabaseName(string connectionString)
+ {
+ var hostIndex = connectionString.IndexOf("//");
+ if (hostIndex > 0)
+ {
+ int startIndex = connectionString.IndexOf("/", hostIndex + 2) + 1;
+ int endIndex = connectionString.IndexOf("?", startIndex);
+ if (startIndex > 0)
+ {
+ if (endIndex > 0)
+ return connectionString.Substring(startIndex, endIndex - startIndex);
+ else
+ return connectionString.Substring(startIndex);
+ }
+ }
+
+ throw new ArgumentException("Unsupported MongoDB connection string", "connectionString");
+ }
}
}
@@ -19,17 +19,29 @@ public static DSPResource CreateDSPResource(BsonDocument document, MongoMetadata
foreach (var element in document.Elements)
{
+ var resourceProperty = mongoMetadata.ResolveResourceProperty(resourceType, element);
+ if (resourceProperty == null)
+ continue;
+
+ string propertyName = null;
+ object propertyValue = null;
+
if (MongoMetadata.IsObjectId(element))
{
- resource.SetValue(MongoMetadata.MappedObjectIdName, element.Value.RawValue.ToString());
+ propertyName = MongoMetadata.MappedObjectIdName;
+ propertyValue = element.Value.RawValue.ToString();
}
else if (element.Value.GetType() == typeof(BsonDocument))
{
- resource.SetValue(element.Name, CreateDSPResource(element.Value.AsBsonDocument, mongoMetadata, element.Name, MongoMetadata.GetComplexTypePrefix(resourceName)));
+ propertyName = element.Name;
+ propertyValue = CreateDSPResource(element.Value.AsBsonDocument, mongoMetadata, element.Name,
+ MongoMetadata.GetComplexTypePrefix(resourceName));
}
else if (element.Value.GetType() == typeof(BsonArray))
{
- resource.SetValue(element.Name, element.Value.RawValue);
+ propertyName = element.Name;
+ propertyValue = element.Value.RawValue;
+
//var bsonArray = element.Value.AsBsonArray;
//if (bsonArray != null && bsonArray.Count > 0)
//{
@@ -44,16 +56,16 @@ public static DSPResource CreateDSPResource(BsonDocument document, MongoMetadata
}
else
{
- object value = null;
+ propertyName = element.Name;
if (element.Value.RawValue != null)
{
switch (element.Value.BsonType)
{
case BsonType.DateTime:
- value = UnixEpoch + TimeSpan.FromMilliseconds(element.Value.AsBsonDateTime.MillisecondsSinceEpoch);
+ propertyValue = UnixEpoch + TimeSpan.FromMilliseconds(element.Value.AsBsonDateTime.MillisecondsSinceEpoch);
break;
default:
- value = element.Value.RawValue;
+ propertyValue = element.Value.RawValue;
break;
}
}
@@ -62,16 +74,22 @@ public static DSPResource CreateDSPResource(BsonDocument document, MongoMetadata
switch (element.Value.BsonType)
{
case BsonType.Binary:
- value = element.Value.AsBsonBinaryData.Bytes;
+ propertyValue = element.Value.AsBsonBinaryData.Bytes;
break;
default:
- value = element.Value.RawValue;
+ propertyValue = element.Value.RawValue;
break;
}
}
- resource.SetValue(element.Name, value);
}
+
+ if (propertyValue != null)
+ {
+ propertyValue = Convert.ChangeType(propertyValue, resourceProperty.ResourceType.InstanceType);
+ }
+ resource.SetValue(propertyName, propertyValue);
}
+
return resource;
}
Oops, something went wrong.

0 comments on commit a8289a6

Please sign in to comment.