Skip to content

Commit b8b9d21

Browse files
author
sridharn
committed
Unit tests for CSHARP-371, CSHARP-372.
1 parent 4dc2f66 commit b8b9d21

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

BsonUnitTests/BsonUnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<Link>Properties\GlobalAssemblyInfo.cs</Link>
8181
</Compile>
8282
<Compile Include="BsonExtensionMethodsTests.cs" />
83+
<Compile Include="BsonUtilsTests.cs" />
8384
<Compile Include="DefaultSerializer\Attributes\BsonRepresentationAttributeTests.cs" />
8485
<Compile Include="DefaultSerializer\BsonClassMapTests.cs" />
8586
<Compile Include="DefaultSerializer\BsonMemberMapTests.cs" />

BsonUnitTests/BsonUtilsTests.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* Copyright 2010-2011 10gen Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
18+
using MongoDB.Bson;
19+
20+
using NUnit.Framework;
21+
22+
namespace MongoDB.BsonUnitTests
23+
{
24+
[TestFixture]
25+
public class BsonUtilsTests
26+
{
27+
28+
[Test]
29+
public void TestMaxToDateTimeConversion()
30+
{
31+
var actual = BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(
32+
BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch);
33+
Assert.AreEqual(DateTime.MaxValue, actual);
34+
}
35+
36+
[Test]
37+
public void TestMinToDateTimeConversion()
38+
{
39+
var actual = BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(
40+
BsonConstants.DateTimeMinValueMillisecondsSinceEpoch);
41+
Assert.AreEqual(DateTime.MinValue, actual);
42+
}
43+
44+
[Test]
45+
public void TestZeroToDateTimeConversion()
46+
{
47+
var actual = BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(0);
48+
Assert.AreEqual(BsonConstants.UnixEpoch, actual);
49+
}
50+
51+
[Test]
52+
[ExpectedException(typeof(ArgumentOutOfRangeException))]
53+
public void TestGreaterThanMaxToDateTimeConversion()
54+
{
55+
var actual = BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(
56+
BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch+1);
57+
Assert.AreEqual(BsonConstants.UnixEpoch, actual);
58+
}
59+
60+
[Test]
61+
[ExpectedException(typeof(ArgumentOutOfRangeException))]
62+
public void TestLessThanMinToDateTimeConversion()
63+
{
64+
var actual = BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(
65+
BsonConstants.DateTimeMinValueMillisecondsSinceEpoch - 1);
66+
Assert.AreEqual(BsonConstants.UnixEpoch, actual);
67+
}
68+
69+
[Test]
70+
public void TestMaxToMillisConversion()
71+
{
72+
var actual = BsonUtils.ToMillisecondsSinceEpoch(DateTime.MaxValue);
73+
Assert.AreEqual(BsonConstants.DateTimeMaxValueMillisecondsSinceEpoch,
74+
actual);
75+
}
76+
77+
[Test]
78+
public void TestMinToMillisConversion()
79+
{
80+
var actual = BsonUtils.ToMillisecondsSinceEpoch(DateTime.MinValue);
81+
Assert.AreEqual(BsonConstants.DateTimeMinValueMillisecondsSinceEpoch,
82+
actual);
83+
}
84+
85+
}
86+
}

0 commit comments

Comments
 (0)