Browse Source

Added unit test for CSHARP-100. Not able to reproduce yet.

pull/27/head
rstam 15 years ago
parent
commit
12ff3008df
  1. 2
      Bson/DefaultSerializer/Attributes/BsonKnownTypesAttribute.cs
  2. 2
      DriverOnlineTests/DriverOnlineTests.csproj
  3. 66
      DriverOnlineTests/Jira/CSharp100Tests.cs

2
Bson/DefaultSerializer/Attributes/BsonKnownTypesAttribute.cs

@ -19,7 +19,7 @@ using System.Linq;
using System.Text;
namespace MongoDB.Bson.DefaultSerializer {
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true)]
public class BsonKnownTypesAttribute : Attribute {
#region private fields
private Type[] knownTypes;

2
DriverOnlineTests/DriverOnlineTests.csproj

@ -60,6 +60,7 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@ -77,6 +78,7 @@
<Compile Include="Jira\CSharp92Tests.cs" />
<Compile Include="Jira\CSharp93Tests.cs" />
<Compile Include="Jira\CSharp98Tests.cs" />
<Compile Include="Jira\CSharp100Tests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Samples\MagicDiscriminatorTests.cs" />
</ItemGroup>

66
DriverOnlineTests/Jira/CSharp100Tests.cs

@ -0,0 +1,66 @@
/* Copyright 2010 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using NUnit.Framework;
using MongoDB.Bson;
using MongoDB.Bson.DefaultSerializer;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace MongoDB.DriverOnlineTests.Jira.CSharpxx {
[TestFixture]
public class CSharp100Tests {
[DataContract]
private class ParentClass {
[BsonId]
public ObjectId Id { get; set; }
}
[DataContract]
private class ChildClass : ParentClass {
[DataMember(Order = 1)]
[BsonIgnoreIfNull]
public IList<SomeClass> SomeProperty { get; set; }
}
[DataContract]
public class SomeClass {
}
[Test]
public void TestDeserializationOfTwoBs() {
var server = MongoServer.Create("mongodb://localhost/?safe=true");
var database = server["onlinetests"];
var collection = database["csharpxx"];
collection.RemoveAll();
var obj = new ChildClass { SomeProperty = null };
collection.Save(obj, SafeMode.True);
obj = new ChildClass { SomeProperty = new List<SomeClass>() };
collection.Save(obj, SafeMode.True);
obj = new ChildClass { SomeProperty = new List<SomeClass> { new SomeClass() } };
collection.Save(obj, SafeMode.True);
obj = new ChildClass { SomeProperty = new List<SomeClass> { new SomeClass(), new SomeClass() } };
collection.Save(obj, SafeMode.True);
}
}
}
Loading…
Cancel
Save