Browse Source
Implemented CSHARP-270. Added more information to a few of the error messages in exceptions thrown by BsonClassMapSerializer.
pull/63/head
Implemented CSHARP-270. Added more information to a few of the error messages in exceptions thrown by BsonClassMapSerializer.
pull/63/head

3 changed files with 82 additions and 5 deletions
-
11Bson/Serialization/BsonClassMapSerializer.cs
-
1BsonUnitTests/BsonUnitTests.csproj
-
75BsonUnitTests/Jira/CSharp270Tests.cs
@ -0,0 +1,75 @@ |
|||
/* Copyright 2010-2011 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; |
|||
using System.Collections.Generic; |
|||
using System.Collections.ObjectModel; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Runtime.Serialization; |
|||
using System.Text; |
|||
using System.Text.RegularExpressions; |
|||
using NUnit.Framework; |
|||
|
|||
using MongoDB.Bson; |
|||
using MongoDB.Bson.IO; |
|||
using MongoDB.Bson.Serialization; |
|||
using MongoDB.Bson.Serialization.Attributes; |
|||
|
|||
namespace MongoDB.BsonUnitTests.Jira.CSharp270 { |
|||
public class C { |
|||
public ObjectId Id; |
|||
[BsonRequired] |
|||
[BsonElement("field")] |
|||
public int Field; |
|||
[BsonRequired] |
|||
[BsonElement("property")] |
|||
public int Property { get; set; } |
|||
} |
|||
|
|||
[TestFixture] |
|||
public class CSharp270Tests { |
|||
[Test] |
|||
public void TestBogusElement() { |
|||
var document = new BsonDocument("bogus", 0); |
|||
var message = "Element 'bogus' does not match any field or property of class MongoDB.BsonUnitTests.Jira.CSharp270.C."; |
|||
var ex = Assert.Throws<FileFormatException>(() => { BsonSerializer.Deserialize<C>(document); }); |
|||
Assert.AreEqual(message, ex.Message); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestMissingElementForField() { |
|||
var document = new BsonDocument { |
|||
{ "_id", ObjectId.GenerateNewId() }, |
|||
{ "property", 0 } |
|||
}; |
|||
var message = "Required element 'field' for field 'Field' of class MongoDB.BsonUnitTests.Jira.CSharp270.C is missing."; |
|||
var ex = Assert.Throws<FileFormatException>(() => { BsonSerializer.Deserialize<C>(document); }); |
|||
Assert.AreEqual(message, ex.Message); |
|||
} |
|||
|
|||
[Test] |
|||
public void TestMissingElementForProperty() { |
|||
var document = new BsonDocument { |
|||
{ "_id", ObjectId.GenerateNewId() }, |
|||
{ "field", 0 } |
|||
}; |
|||
var message = "Required element 'property' for property 'Property' of class MongoDB.BsonUnitTests.Jira.CSharp270.C is missing."; |
|||
var ex = Assert.Throws<FileFormatException>(() => { BsonSerializer.Deserialize<C>(document); }); |
|||
Assert.AreEqual(message, ex.Message); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue