public void constructor_should_initialize_instance() { var cursor = new Mock <IAsyncCursor <RawBsonDocument> >().Object; var documentSerializer = new Mock <IBsonSerializer <BsonDocument> >().Object; var binding = new Mock <IReadBinding>().Object; var initialOperationTime = new BsonTimestamp(3L); var postBatchResumeToken = new BsonDocument("c", 3); var changeStreamOperation = CreateChangeStreamOperation(); var startAfter = new BsonDocument("a", 1); var resumeAfter = new BsonDocument("b", 2); var startAtOperationTime = BsonTimestamp.Create(3L); var subject = new ChangeStreamCursor <BsonDocument>(cursor, documentSerializer, binding, changeStreamOperation, postBatchResumeToken, initialOperationTime, startAfter, resumeAfter, startAtOperationTime); subject._binding().Should().BeSameAs(binding); subject._changeStreamOperation().Should().BeSameAs(changeStreamOperation); subject._current().Should().BeNull(); subject._cursor().Should().BeSameAs(cursor); subject._disposed().Should().BeFalse(); subject._documentSerializer().Should().BeSameAs(documentSerializer); subject._postBatchResumeToken().Should().BeSameAs(postBatchResumeToken); subject._initialOperationTime().Should().BeSameAs(initialOperationTime); subject._initialStartAfter().Should().Be(startAfter); subject._initialResumeAfter().Should().Be(resumeAfter); subject._initialStartAtOperationTime().Should().Be(startAtOperationTime); }
public void ChangeStreamOperation_should_not_calculate_effective_options_for_non_resume_process() { var pipeline = new BsonDocument[0]; var resultSerializer = new ChangeStreamDocumentSerializer <BsonDocument>(BsonDocumentSerializer.Instance); var messageEncoderSettings = new MessageEncoderSettings(); var resumeAfter = new BsonDocument("a", 1); var startAfter = new BsonDocument("b", 2); var startAtOperationTime = BsonTimestamp.Create(3L); var documentResumeToken = new BsonDocument("c", 3); ChangeStreamOperation <ChangeStreamDocument <BsonDocument> > subject = new ChangeStreamOperation <ChangeStreamDocument <BsonDocument> >(_collectionNamespace, pipeline, resultSerializer, messageEncoderSettings) { ResumeAfter = resumeAfter, StartAfter = startAfter, StartAtOperationTime = startAtOperationTime, DocumentResumeToken = documentResumeToken }; var result = subject.CreateChangeStreamStage(false); var changeStream = result.GetValue("$changeStream").AsBsonDocument; changeStream.GetValue("resumeAfter").Should().Be(resumeAfter); changeStream.GetValue("startAfter").Should().Be(startAfter); changeStream.GetValue("startAtOperationTime").Should().Be(startAtOperationTime); }
public static BsonTimestamp DateTimeToStamp(this DateTime time) { TimeSpan ts = time - new DateTime(1970, 1, 1, 0, 0, 0, 0); var s = Convert.ToInt64(ts.TotalSeconds - 28800).ToString(); return(BsonTimestamp.Create(s)); }
public static BsonTimestamp ConvertToTimeStamp(this string strTime) { TimeSpan ts = Convert.ToDateTime(strTime) - new DateTime(1970, 1, 1, 0, 0, 0, 0); var s = Convert.ToInt64(ts.TotalSeconds).ToString(); return(BsonTimestamp.Create(s)); }
private BsonType ParseTimestamp() { VerifyToken(":"); var valueToken = PopToken(); if (valueToken.Type != JsonTokenType.Int32 && valueToken.Type != JsonTokenType.Int64) { var message = string.Format("JSON reader expected an integer but found: '{0}'", valueToken.Lexeme); throw new FileFormatException(message); } VerifyToken("}"); currentValue = BsonTimestamp.Create(valueToken.Int64Value); return(BsonType.Timestamp); }
public void TestBsonDocumentWithBsonTimestampId() { _collection.RemoveAll(); var doc = new BsonDocument { { "_id", BsonTimestamp.Create(0, 0) }, { "X", 1 } }; _collection.Insert(doc); Assert.AreEqual(BsonTimestamp.Create(0, 0), doc["_id"].AsBsonTimestamp); doc = new BsonDocument { { "_id", BsonTimestamp.Create(1, 2) }, { "X", 1 } }; _collection.Insert(doc); }
public void ChangeStreamOperation_should_have_expected_change_stream_operation_options_for_resume_process_after_resumable_error( string resumeAfterJson, string startAfterJson, object startAtOperationTimeValue, string documentResumeTokenJson, object initialOperationTime, string expectedResumeAfter, object expectedStartAtOperationTimeValue) { var pipeline = new BsonDocument[0]; var resultSerializer = new ChangeStreamDocumentSerializer <BsonDocument>(BsonDocumentSerializer.Instance); var messageEncoderSettings = new MessageEncoderSettings(); var resumeAfter = resumeAfterJson != null?BsonDocument.Parse(resumeAfterJson) : null; var startAfter = startAfterJson != null?BsonDocument.Parse(startAfterJson) : null; var startAtOperationTime = startAtOperationTimeValue != null?BsonTimestamp.Create(startAtOperationTimeValue) : null; var documentResumeToken = documentResumeTokenJson != null?BsonDocument.Parse(documentResumeTokenJson) : null; ChangeStreamOperation <ChangeStreamDocument <BsonDocument> > subject = new ChangeStreamOperation <ChangeStreamDocument <BsonDocument> >(_collectionNamespace, pipeline, resultSerializer, messageEncoderSettings) { ResumeAfter = resumeAfter, StartAfter = startAfter, StartAtOperationTime = startAtOperationTime, DocumentResumeToken = documentResumeToken }; if (initialOperationTime != null) { subject._initialOperationTime(BsonTimestamp.Create(initialOperationTime)); } var result = subject.CreateChangeStreamStage(true); var changeStream = result.GetValue("$changeStream").AsBsonDocument; changeStream.GetValue("resumeAfter", null).Should().Be(expectedResumeAfter != null ? BsonDocument.Parse(expectedResumeAfter) : null); changeStream.TryGetValue("startAfter", out _).Should().BeFalse(); changeStream.GetValue("startAtOperationTime", null).Should().Be(expectedStartAtOperationTimeValue != null ? BsonTimestamp.Create(expectedStartAtOperationTimeValue) : null); }
public void TestBsonTimestamp() { var value = BsonTimestamp.Create(123); Assert.Throws <InvalidCastException>(() => Convert.ToBoolean(value)); Assert.Throws <InvalidCastException>(() => Convert.ToByte(value)); Assert.Throws <InvalidCastException>(() => Convert.ToChar(value)); Assert.Throws <InvalidCastException>(() => Convert.ToDateTime(value)); Assert.Throws <InvalidCastException>(() => Convert.ToDecimal(value)); Assert.Throws <InvalidCastException>(() => Convert.ToDouble(value)); Assert.Throws <InvalidCastException>(() => Convert.ToInt16(value)); Assert.Throws <InvalidCastException>(() => Convert.ToInt32(value)); Assert.Throws <InvalidCastException>(() => Convert.ToInt64(value)); Assert.Throws <InvalidCastException>(() => Convert.ToSByte(value)); Assert.Throws <InvalidCastException>(() => Convert.ToSingle(value)); Assert.Throws <InvalidCastException>(() => Convert.ToString(value)); Assert.Throws <InvalidCastException>(() => Convert.ToUInt16(value)); Assert.Throws <InvalidCastException>(() => Convert.ToUInt32(value)); Assert.Throws <InvalidCastException>(() => Convert.ToUInt64(value)); }
// public methods /// <summary> /// Deserializes an object from a BsonReader. /// </summary> /// <param name="bsonReader">The BsonReader.</param> /// <param name="nominalType">The nominal type of the object.</param> /// <param name="actualType">The actual type of the object.</param> /// <param name="options">The serialization options.</param> /// <returns>An object.</returns> public override object Deserialize( BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) { VerifyTypes(nominalType, actualType, typeof(BsonTimestamp)); var bsonType = bsonReader.GetCurrentBsonType(); if (bsonType == BsonType.Null) { bsonReader.ReadNull(); return(null); } else { return(BsonTimestamp.Create(bsonReader.ReadTimestamp())); } }
public void TestClassWithBsonTimestampId() { _collection.RemoveAll(); var doc = new ClassWithBsonTimestampId { Id = null, X = 1 }; _collection.Insert(doc); Assert.IsNull(doc.Id); doc = new ClassWithBsonTimestampId { Id = BsonTimestamp.Create(0, 0), X = 1 }; _collection.Insert(doc); Assert.AreEqual(BsonTimestamp.Create(0, 0), doc.Id); doc = new ClassWithBsonTimestampId { Id = BsonTimestamp.Create(1, 2), X = 1 }; _collection.Insert(doc); }
private BsonValue ParseTimestamp() { VerifyToken(":"); var valueToken = PopToken(); long value; if (valueToken.Type == JsonTokenType.Int32 && valueToken.Type == JsonTokenType.Int64) { value = valueToken.Int64Value; } else if (valueToken.Type == JsonTokenType.UnquotedString && valueToken.Lexeme == "NumberLong") { value = ParseNumberLong().AsInt64; } else { var message = string.Format("JSON reader expected an integer but found: '{0}'", valueToken.Lexeme); throw new FileFormatException(message); } VerifyToken("}"); return(BsonTimestamp.Create(value)); }
public void ChangeStreamOperation_should_have_expected_change_stream_operation_options_for_resume_process_after_resumable_error( string postBatchResumeTokenJson, string resumeAfterJson, string startAfterJson, object startAtOperationTimeValue, string documentResumeTokenJson, object initialOperationTimeObj, string expectedResumeAfter, object expectedStartAtOperationTimeValue) { var postBatchResumeToken = postBatchResumeTokenJson != null?BsonDocument.Parse(postBatchResumeTokenJson) : null; var resumeAfter = resumeAfterJson != null?BsonDocument.Parse(resumeAfterJson) : null; var startAfter = startAfterJson != null?BsonDocument.Parse(startAfterJson) : null; var startAtOperationTime = startAtOperationTimeValue != null?BsonTimestamp.Create(startAtOperationTimeValue) : null; var documentResumeToken = documentResumeTokenJson != null?BsonDocument.Parse(documentResumeTokenJson) : null; var initialOperationTime = initialOperationTimeObj != null?BsonTimestamp.Create(initialOperationTimeObj) : null; var mockCursor = CreateMockCursor(); var subject = CreateSubject( cursor: mockCursor.Object, startAfter: startAfter, resumeAfter: resumeAfter, startAtOperationTime: startAtOperationTime, postBatchResumeToken: postBatchResumeToken, initialOperationTime: initialOperationTime); subject._documentResumeToken(documentResumeToken); var result = subject.GetResumeValues(); result.ResumeAfter.Should().Be(expectedResumeAfter != null ? BsonDocument.Parse(expectedResumeAfter) : null); result.StartAfter.Should().BeNull(); result.StartAtOperationTime.Should().Be(expectedStartAtOperationTimeValue != null ? BsonTimestamp.Create(expectedStartAtOperationTimeValue) : null); }
public static void Main(string[] args) { Book book = new Book(); string line; // 定义文件绝对路径 string path = @"C:\\Users\\tpl\\Desktop\\主泵\\RCS-1\\RCS-1.csv"; StreamReader sr = new StreamReader(path, Encoding.UTF8); sr.ReadLine(); sr.ReadLine(); sr.ReadLine(); for (int i = 0; i < 10; i++) { // 一行一行读取数据 line = sr.ReadLine(); string[] arr = line.Split(","); book.time = BsonTimestamp.Create(GetTimeStamp(arr[0])); book.data = Convert.ToDouble(arr[1]); Console.WriteLine(book.time + " " + book.data); } Console.WriteLine(" "); Console.WriteLine(GetTime("1602720001")); }
public void TestClassWithBsonValueId() { // repeats all tee TestClassWithBsonXyzId tests using ClassWithBsonValueId { // same as TestClassWithBonArrayId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = new BsonArray(), X = 1 }; Assert.Throws <MongoSafeModeException>(() => { _collection.Insert(doc); }); doc = new ClassWithBsonValueId { Id = new BsonArray { 1, 2, 3 }, X = 1 }; Assert.Throws <MongoSafeModeException>(() => { _collection.Insert(doc); }); } { // same as TestClastWithBsonBinaryDataId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonBinaryData.Create(new byte[] { }), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonBinaryData.Create(new byte[] { 1, 2, 3 }), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonBooleanId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonBoolean.Create(false), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonBoolean.Create(true), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonDocumentId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = new BsonDocument(), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = new BsonDocument { { "A", 1 }, { "B", 2 } }, X = 3 }; _collection.Insert(doc); } { // same as TestClassWithBsonDateTimeId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonDateTime.Create(DateTime.MinValue), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonDateTime.Create(DateTime.UtcNow), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonDateTime.Create(DateTime.MaxValue), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonDoubleId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonDouble.Create(0.0), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonDouble.Create(1.0), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonInt32Id _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonInt32.Create(0), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonInt32.Create(1), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonInt64Id _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonInt64.Create(0), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonValueId { Id = BsonInt64.Create(1), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonMaxKeyId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.AreEqual(null, doc.Id); doc = new ClassWithBsonValueId { Id = BsonMaxKey.Value, X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonMinKeyId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.AreEqual(null, doc.Id); doc = new ClassWithBsonValueId { Id = BsonMinKey.Value, X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonNullId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.AreEqual(null, doc.Id); doc = new ClassWithBsonValueId { Id = BsonNull.Value, X = 1 }; Assert.Throws <MongoSafeModeException>(() => { _collection.Insert(doc); }); } { // same as TestClassWithBsonObjectId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.IsNull(doc.Id); // BsonObjectIdGenerator is not invoked when nominalType is BsonValue doc = new ClassWithBsonValueId { Id = BsonObjectId.Empty, X = 1 }; _collection.Insert(doc); Assert.AreEqual(ObjectId.Empty, doc.Id.AsObjectId); // BsonObjectIdGenerator is not invoked when nominalType is BsonValue doc = new ClassWithBsonValueId { Id = BsonObjectId.GenerateNewId(), X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonStringId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.IsNull(doc.Id); doc = new ClassWithBsonValueId { Id = "", X = 1 }; _collection.Insert(doc); Assert.AreEqual("", doc.Id.AsString); doc = new ClassWithBsonValueId { Id = "123", X = 1 }; _collection.Insert(doc); } { // same as TestClassWithBsonTimestampId _collection.RemoveAll(); var doc = new ClassWithBsonValueId { Id = null, X = 1 }; _collection.Insert(doc); Assert.IsNull(doc.Id); doc = new ClassWithBsonValueId { Id = BsonTimestamp.Create(0, 0), X = 1 }; _collection.Insert(doc); Assert.AreEqual(BsonTimestamp.Create(0, 0), doc.Id); doc = new ClassWithBsonValueId { Id = BsonTimestamp.Create(1, 2), X = 1 }; _collection.Insert(doc); } }
public void TestExtraElementsOfAllTypes() { var json = "{ '_id' : 1, 'A' : 2, 'B' : 3, #X }"; var extraElements = new string[][] { new string[] { "XArray", "[1, 2.0]" }, new string[] { "XBinary", "HexData(2, '1234')" }, new string[] { "XBoolean", "true" }, new string[] { "XByteArray", "HexData(0, '1234')" }, new string[] { "XDateTime", "ISODate('2012-03-16T11:19:00Z')" }, new string[] { "XDocument", "{ 'a' : 1 }" }, new string[] { "XDouble", "1.0" }, new string[] { "XGuidLegacy", "HexData(3, '33221100554477668899aabbccddeeff')" }, new string[] { "XGuidStandard", "HexData(4, '00112233445566778899aabbccddeeff')" }, new string[] { "XInt32", "1" }, new string[] { "XInt64", "NumberLong(1)" }, new string[] { "XJavaScript", "{ '$code' : 'abc' }" }, new string[] { "XJavaScriptWithScope", "{ '$code' : 'abc', '$scope' : { 'x' : 1 } }" }, new string[] { "XMaxKey", "{ '$maxkey' : 1 }" }, new string[] { "XMinKey", "{ '$minkey' : 1 }" }, new string[] { "XNull", "null" }, new string[] { "XObjectId", "ObjectId('00112233445566778899aabb')" }, new string[] { "XRegularExpression", "/abc/" }, new string[] { "XString", "'abc'" }, new string[] { "XSymbol", "{ '$symbol' : 'abc' }" }, new string[] { "XTimestamp", "{ '$timestamp' : NumberLong(1234) }" }, new string[] { "XUndefined", "undefined" }, }; var extraElementsRepresentation = string.Join(", ", extraElements.Select(e => string.Format("'{0}' : {1}", e[0], e[1])).ToArray()); json = json.Replace("#X", extraElementsRepresentation).Replace("'", "\""); var c = BsonSerializer.Deserialize <C>(json); // round trip it both ways before checking individual values json = c.ToJson(); c = BsonSerializer.Deserialize <C>(json); Assert.IsInstanceOf <List <object> >(c.X["XArray"]); Assert.IsInstanceOf <BsonBinaryData>(c.X["XBinary"]); Assert.IsInstanceOf <bool>(c.X["XBoolean"]); Assert.IsInstanceOf <byte[]>(c.X["XByteArray"]); Assert.IsInstanceOf <DateTime>(c.X["XDateTime"]); Assert.IsInstanceOf <Dictionary <string, object> >(c.X["XDocument"]); Assert.IsInstanceOf <double>(c.X["XDouble"]); Assert.IsInstanceOf <Guid>(c.X["XGuidLegacy"]); Assert.IsInstanceOf <Guid>(c.X["XGuidStandard"]); Assert.IsInstanceOf <int>(c.X["XInt32"]); Assert.IsInstanceOf <long>(c.X["XInt64"]); Assert.IsInstanceOf <BsonJavaScript>(c.X["XJavaScript"]); Assert.IsInstanceOf <BsonJavaScriptWithScope>(c.X["XJavaScriptWithScope"]); Assert.IsInstanceOf <BsonMaxKey>(c.X["XMaxKey"]); Assert.IsInstanceOf <BsonMinKey>(c.X["XMinKey"]); Assert.IsNull(c.X["XNull"]); Assert.IsInstanceOf <ObjectId>(c.X["XObjectId"]); Assert.IsInstanceOf <BsonRegularExpression>(c.X["XRegularExpression"]); Assert.IsInstanceOf <string>(c.X["XString"]); Assert.IsInstanceOf <BsonSymbol>(c.X["XSymbol"]); Assert.IsInstanceOf <BsonTimestamp>(c.X["XTimestamp"]); Assert.IsInstanceOf <BsonUndefined>(c.X["XUndefined"]); Assert.AreEqual(22, c.X.Count); Assert.IsTrue(new object[] { 1, 2.0 }.SequenceEqual((List <object>)c.X["XArray"])); #pragma warning disable 618 // OldBinary is obsolete Assert.AreEqual(BsonBinarySubType.OldBinary, ((BsonBinaryData)c.X["XBinary"]).SubType); #pragma warning restore 618 Assert.IsTrue(new byte[] { 0x12, 0x34 }.SequenceEqual(((BsonBinaryData)c.X["XBinary"]).Bytes)); Assert.AreEqual(true, c.X["XBoolean"]); Assert.IsTrue(new byte[] { 0x12, 0x34 }.SequenceEqual((byte[])c.X["XByteArray"])); Assert.AreEqual(new DateTime(2012, 3, 16, 11, 19, 0, DateTimeKind.Utc), c.X["XDateTime"]); Assert.AreEqual(1, ((IDictionary <string, object>)c.X["XDocument"]).Count); Assert.AreEqual(1, ((IDictionary <string, object>)c.X["XDocument"])["a"]); Assert.AreEqual(1.0, c.X["XDouble"]); Assert.AreEqual(new Guid("00112233-4455-6677-8899-aabbccddeeff"), c.X["XGuidLegacy"]); Assert.AreEqual(new Guid("00112233-4455-6677-8899-aabbccddeeff"), c.X["XGuidStandard"]); Assert.AreEqual(1, c.X["XInt32"]); Assert.AreEqual(1L, c.X["XInt64"]); Assert.AreEqual("abc", ((BsonJavaScript)c.X["XJavaScript"]).Code); Assert.AreEqual("abc", ((BsonJavaScriptWithScope)c.X["XJavaScriptWithScope"]).Code); Assert.AreEqual(1, ((BsonJavaScriptWithScope)c.X["XJavaScriptWithScope"]).Scope.ElementCount); Assert.AreEqual(BsonInt32.Create(1), ((BsonJavaScriptWithScope)c.X["XJavaScriptWithScope"]).Scope["x"]); Assert.AreSame(BsonMaxKey.Value, c.X["XMaxKey"]); Assert.AreSame(BsonMinKey.Value, c.X["XMinKey"]); Assert.AreEqual(null, c.X["XNull"]); Assert.AreEqual(ObjectId.Parse("00112233445566778899aabb"), c.X["XObjectId"]); Assert.AreEqual(new BsonRegularExpression("abc"), c.X["XRegularExpression"]); Assert.AreEqual("abc", c.X["XString"]); Assert.AreSame(BsonSymbol.Create("abc"), c.X["XSymbol"]); Assert.AreEqual(BsonTimestamp.Create(1234), c.X["XTimestamp"]); Assert.AreSame(BsonUndefined.Value, c.X["XUndefined"]); }
public void Create_should_throw_when_value_is_null() { Action action = () => { BsonTimestamp.Create(null); }; action.ShouldThrow <ArgumentNullException>().And.ParamName.Should().Be("value"); }
public void Create_should_return_expected_result(object value, long expectedValue) { var result = BsonTimestamp.Create(value); result.Value.Should().Be(expectedValue); }
public static BsonValue Create(this BsonType bsonType, object o) { BsonValue value = BsonNull.Value; try { switch (bsonType) { case BsonType.EndOfDocument: break; case BsonType.Double: value = BsonDouble.Create(o); break; case BsonType.String: value = BsonString.Create(o); break; case BsonType.Document: value = BsonDocument.Create(o); break; case BsonType.Array: value = BsonArray.Create(o); break; case BsonType.Binary: value = BsonBinaryData.Create(o); break; case BsonType.Undefined: break; case BsonType.ObjectId: value = BsonObjectId.Create(o); break; case BsonType.Boolean: value = BsonBoolean.Create(o); break; case BsonType.DateTime: value = BsonDateTime.Create(o); break; case BsonType.Null: value = BsonNull.Value; break; case BsonType.RegularExpression: value = BsonRegularExpression.Create(o); break; case BsonType.JavaScript: value = BsonJavaScript.Create(o); break; case BsonType.Symbol: value = BsonSymbol.Create(o); break; case BsonType.JavaScriptWithScope: value = BsonJavaScriptWithScope.Create(o); break; case BsonType.Int32: value = BsonInt32.Create(o); break; case BsonType.Timestamp: value = BsonTimestamp.Create(o); break; case BsonType.Int64: value = BsonInt64.Create(o); break; case BsonType.MaxKey: value = BsonValue.Create(o); break; case BsonType.MinKey: value = BsonValue.Create(o); break; } } catch { } return(value); }