/// <summary> /// 还原BsonValue /// </summary> /// <returns></returns> public BsonValue GetBsonValue() { BsonValue value = new BsonString(string.Empty); switch (MBsonType) { case "BsonString": value = new BsonString(MBsonString); break; case "BsonInt32": value = new BsonInt32(MBsonInt32); break; case "BsonInt64": value = new BsonInt64(MBsonInt64); break; case "BsonDecimal128": value = new BsonDecimal128(MBSonDecimal128); break; case "BsonDateTime": value = new BsonDateTime(MBsonDateTime); break; case "BsonBoolean": value = MBsonBoolean ? BsonBoolean.True : BsonBoolean.False; break; } return(value); }
public void ToDecimal128_should_return_expected_result(long int64Value) { var subject = new BsonInt64(int64Value); var result = subject.ToDecimal128(); result.Should().Be((Decimal128)int64Value); }
/// <summary> /// 使用属性会发生一些MONO上的移植问题 /// </summary> /// <returns></returns> public BsonValue GetValue(BsonValueEx.BasicType DataType) { BsonValue mValue = null; switch (DataType) { case BsonValueEx.BasicType.BsonString: mValue = new BsonString(txtBsonValue.Text); break; case BsonValueEx.BasicType.BsonInt32: mValue = new BsonInt32(Convert.ToInt32(NumberPick.Value)); break; case BsonValueEx.BasicType.BsonInt64: mValue = new BsonInt64(Convert.ToInt64(NumberPick.Value)); break; case BsonValueEx.BasicType.BsonDecimal128: mValue = new BsonDecimal128(Convert.ToDecimal(NumberPick.Value)); break; case BsonValueEx.BasicType.BsonDouble: mValue = new BsonDouble(Convert.ToDouble(txtBsonValue.Text)); break; case BsonValueEx.BasicType.BsonDateTime: mValue = new BsonDateTime(dateTimePicker.Value); break; case BsonValueEx.BasicType.BsonBoolean: mValue = radTrue.Checked ? BsonBoolean.True : BsonBoolean.False; break; case BsonValueEx.BasicType.BsonArray: case BsonValueEx.BasicType.BsonLegacyPoint: mValue = _mBsonArray; break; case BsonValueEx.BasicType.BsonGeoJSON: case BsonValueEx.BasicType.BsonDocument: mValue = _mBsonDocument; break; case BsonValueEx.BasicType.BsonMaxKey: mValue = BsonMaxKey.Value; break; case BsonValueEx.BasicType.BsonMinKey: mValue = BsonMinKey.Value; break; case BsonValueEx.BasicType.BsonBinary: mValue = new BsonBinaryData(Encoding.Default.GetBytes(txtBsonValue.Text)); break; } return(mValue); }
public void CompareTo_BsonInt64_should_return_expected_result(double doubleValue, long otherInt64Value, int expectedResult) { var subject = new BsonDouble(doubleValue); var other = new BsonInt64(otherInt64Value); var result = subject.CompareTo(other); result.Should().Be(expectedResult); }
public void CompareTo_BsonInt32_should_return_expected_result(long int64Value, int otherInt32Value, int expectedResult) { var subject = new BsonInt64(int64Value); var other = new BsonInt32(otherInt32Value); var result = subject.CompareTo(other); result.Should().Be(expectedResult); }
public void operator_equals_with_BsonDecimal128_should_return_expected_result(long lhsInt64Value, double rhsDoubleValue, bool expectedResult) { var lhs = new BsonInt64(lhsInt64Value); var rhs = new BsonDecimal128((Decimal128)(decimal)rhsDoubleValue); var result = lhs == rhs; result.Should().Be(expectedResult); }
public void operator_equals_with_BsonInt32_should_return_expected_result(long lhsInt64Value, int rhsInt32Value, bool expectedResult) { var lhs = new BsonInt64(lhsInt64Value); var rhs = new BsonInt32(rhsInt32Value); var result = lhs == rhs; result.Should().Be(expectedResult); }
public void operator_equals_with_BsonInt64_should_return_expected_result(double lhsDoubleValue, long rhsInt64Value, bool expectedResult) { var lhs = new BsonDouble(lhsDoubleValue); var rhs = new BsonInt64(rhsInt64Value); var result = lhs == rhs; result.Should().Be(expectedResult); }
public void CompareTo_BsonDecimal128_should_return_expected_result(long int64Value, double otherDoubleValue, int expectedResult) { var subject = new BsonInt64(int64Value); var other = new BsonDecimal128((Decimal128)(decimal)otherDoubleValue); var result = subject.CompareTo(other); result.Should().Be(expectedResult); }
public void TestBsonDoubleEquals() { var a = new BsonDouble(1.0); var b = new BsonDouble(1.0); var c = new BsonInt32(1); var d = new BsonInt64(1L); var e = new BsonDouble(2.0); var f = new BsonInt32(2); var g = new BsonInt64(2L); var n = (BsonDouble)null; var nan = new BsonDouble(double.NaN); Assert.IsTrue(object.Equals(a, b)); Assert.IsFalse(object.Equals(a, c)); Assert.IsFalse(object.Equals(a, d)); Assert.IsFalse(object.Equals(a, e)); Assert.IsFalse(object.Equals(a, f)); Assert.IsFalse(object.Equals(a, g)); Assert.IsFalse(object.Equals(a, BsonNull.Value)); Assert.IsFalse(a.Equals(n)); Assert.IsFalse(a.Equals(null)); Assert.IsFalse(a.Equals(nan)); Assert.IsTrue(nan.Equals(nan)); Assert.IsTrue(a == b); Assert.IsTrue(a == c); Assert.IsTrue(a == d); Assert.IsFalse(a == e); Assert.IsFalse(a == f); Assert.IsFalse(a == g); Assert.IsFalse(a == BsonNull.Value); Assert.IsFalse(a == null); Assert.IsFalse(null == a); Assert.IsTrue(n == null); Assert.IsTrue(null == n); Assert.IsFalse(a == nan); Assert.IsFalse(nan == a); Assert.IsFalse(nan == double.NaN); Assert.IsFalse(double.NaN == nan); Assert.IsFalse(a != b); Assert.IsFalse(a != c); Assert.IsFalse(a != d); Assert.IsTrue(a != e); Assert.IsTrue(a != f); Assert.IsTrue(a != g); Assert.IsTrue(a != BsonNull.Value); Assert.IsTrue(a != null); Assert.IsTrue(null != a); Assert.IsFalse(n != null); Assert.IsFalse(null != n); Assert.IsTrue(a != nan); Assert.IsTrue(nan != a); Assert.IsTrue(nan != double.NaN); Assert.IsTrue(double.NaN != nan); }
public void CompareTo_null_should_return_expected_result() { var subject = new BsonInt64(0); var result1 = subject.CompareTo((BsonInt64)null); var result2 = subject.CompareTo((BsonValue)null); result1.Should().Be(1); result2.Should().Be(1); }
public void TestMapBsonInt64() { var value = new BsonInt64(1L); var bsonValue = (BsonInt64)BsonTypeMapper.MapToBsonValue(value); Assert.AreSame(value, bsonValue); var bsonInt64 = (BsonInt64)BsonTypeMapper.MapToBsonValue(value, BsonType.Int64); Assert.AreSame(value, bsonInt64); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public static BsonValue NullableDateTime(object value) { DateTime?val = (DateTime?)value; if (val == null) { return(BsonNull.Value); } return(BsonInt64.Create(val.Value.Ticks)); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public static BsonValue NullableLong(object value) { long?val = (long?)value; if (val == null) { return(BsonNull.Value); } return(BsonInt64.Create(val)); }
public void CompareTo_BsonInt64_should_return_expected_result(long int64Value, long otherInt64Value, int expectedResult) { var subject = new BsonInt64(int64Value); var other = new BsonInt64(otherInt64Value); var result1 = subject.CompareTo((BsonInt64)other); var result2 = subject.CompareTo((BsonValue)other); result1.Should().Be(expectedResult); result2.Should().Be(expectedResult); }
public void TestCompareDifferentTypeOnes() { var n1 = new BsonInt32(1); var n2 = new BsonInt64(1); var n3 = new BsonDouble(1.0); Assert.IsTrue(n1 == n2); Assert.IsTrue(n1 == n3); Assert.IsTrue(n2 == n1); Assert.IsTrue(n2 == n3); Assert.IsTrue(n3 == n1); Assert.IsTrue(n3 == n2); }
private static void WriteInt64(PropertyInfo property, object o, BsonDocument document) { if (property.GetValue(o, null) != null) { BsonInt64 bsonInt64 = BsonInt64.Create(property.GetValue(o, null)); document.Add(property.Name, bsonInt64); } else { document.Add(property.Name, BsonNull.Value); } }
public void EqualTwoDifferentBsonTypes() { // Arrange var a = new BsonInt32(100); var b = new BsonInt64(100); // Act var eq = a.Equal(b); // Assert Assert.False(eq); }
public void ParseConditionValueForIntTest() { PrivateObject p = new PrivateObject(typeof(MongoDataSource.MongoDataSource)); string value = "123"; BsonInt64 expected = new BsonInt64(Int64.Parse(value)); object parsedValue = p.Invoke("ParseConditionValue", new object[] { value, DataType.DT_I8 }); Assert.AreEqual(expected, parsedValue); parsedValue = p.Invoke("ParseConditionValue", new object[] { value, DataType.DT_I4 }); Assert.AreEqual(expected, parsedValue); }
public void TestIsNumeric() { BsonValue d128 = new BsonDecimal128(1.0M); BsonValue d = new BsonDouble(1.0); BsonValue i32 = new BsonInt32(1); BsonValue i64 = new BsonInt64(1L); BsonValue s = new BsonString(""); Assert.True(d128.IsNumeric); Assert.True(d.IsNumeric); Assert.True(i32.IsNumeric); Assert.True(i64.IsNumeric); Assert.False(s.IsDecimal128); }
public void TestBsonDocumentWithBsonInt64Id() { _collection.RemoveAll(); var doc = new BsonDocument { { "_id", BsonInt64.Create(0) }, { "X", 1 } }; _collection.Insert(doc); doc = new BsonDocument { { "_id", BsonInt64.Create(1) }, { "X", 1 } }; _collection.Insert(doc); }
public void DiffTwoDifferentBsonTypes() { // Arrange var a = new BsonInt32(100); var b = new BsonInt64(100); var expected = new BsonDocument("types differ", new BsonDocument { { "a", "Int32" }, { "b", "Int64" } }); // Act var doc = a.Diff(b); // Assert Assert.That(doc, Is.EqualTo(expected)); }
/// <summary> /// 还原BsonValue /// </summary> /// <returns></returns> public BsonValue GetBsonValue() { BsonValue value = new BsonString(string.Empty); switch (mBsonType) { case BasicType.BsonString: value = new BsonString(mBsonString); break; case BasicType.BsonInt32: value = new BsonInt32(mBsonInt32); break; case BasicType.BsonInt64: value = new BsonInt64(mBsonInt64); break; case BasicType.BsonDecimal128: value = new BsonDecimal128(mBSonDecimal128); break; case BasicType.BsonDouble: value = new BsonDouble(mBsonDouble); break; case BasicType.BsonDateTime: value = new BsonDateTime(mBsonDateTime); break; case BasicType.BsonBoolean: value = mBsonBoolean ? BsonBoolean.True : BsonBoolean.False; break; case BasicType.BsonMaxKey: value = BsonMaxKey.Value; break; case BasicType.BsonMinKey: value = BsonMinKey.Value; break; case BasicType.BsonBinary: value = new BsonBinaryData(mBsonBinary); break; } return(value); }
private BsonValue GetValue(object value) { if (value is DBNull || value == null) { return(BsonNull.Value); } else if (value is string) { return(BsonString.Create(value)); } else if (value is bool) { return(BsonBoolean.Create(value)); } else if (value is int || value is short || value is byte) { return(BsonInt32.Create(value)); } else if (value is long) { return(BsonInt64.Create(value)); } else if (value is decimal) { return(BsonDecimal128.Create(value)); } else if (value is double || value is float) { return(BsonDouble.Create(value)); } else if (value is DateTime) { return(BsonDateTime.Create(value)); } else if (value is char c) { return(BsonString.Create("" + c)); } else if (value is byte[]) { return(BsonBinaryData.Create(value)); } else { return(BsonString.Create(value.ToString())); } }
/// <summary> /// 使用属性会发生一些MONO上的移植问题 /// </summary> /// <returns></returns> public BsonValue GetValue(BsonValueEx.BasicType DataType) { BsonValue mValue = null; switch (DataType) { case BsonValueEx.BasicType.BsonString: mValue = new BsonString(txtBsonValue.Text); break; case BsonValueEx.BasicType.BsonInt32: mValue = new BsonInt32(Convert.ToInt32(NumberPick.Value)); break; case BsonValueEx.BasicType.BsonInt64: mValue = new BsonInt64(Convert.ToInt64(NumberPick.Value)); break; case BsonValueEx.BasicType.BsonDecimal128: mValue = new BsonDecimal128(Convert.ToDecimal(NumberPick.Value)); break; case BsonValueEx.BasicType.BsonDouble: mValue = new BsonDouble(Convert.ToDouble(txtBsonValue.Text)); break; case BsonValueEx.BasicType.BsonDateTime: mValue = new BsonDateTime(dateTimePicker.Value); break; case BsonValueEx.BasicType.BsonBoolean: mValue = radTrue.Checked ? BsonBoolean.True : BsonBoolean.False; break; case BsonValueEx.BasicType.BsonArray: case BsonValueEx.BasicType.BsonGeo: mValue = _mBsonArray; break; case BsonValueEx.BasicType.BsonDocument: mValue = _mBsonDocument; break; } return(mValue); }
/// <summary>Try to convert the string to a <see cref="BsonInt64"/>.</summary> /// <param name="value">The value to convert.</param> /// <param name="bsonValue">The BsonValue result.</param> /// <returns><c>true</c> if the value was converted; otherwise <c>false</c>.</returns> public static bool TryInt64(this string value, out BsonValue bsonValue) { bsonValue = null; if (value == null) { return(false); } long result; var r = long.TryParse(value, out result); if (r) { bsonValue = new BsonInt64(result); } return(r); }
public String ValidserieDemands(List <string> numbers) { BsonArray series = new BsonArray(); BsonInt64 num1 = 7; foreach (string num in numbers) { series.Add(num); } IMongoQuery query = Query.And(Query.In("objects.serie", series), Query.NE("status", num1), Query.NE("system_status", false)); JoinCollections Join = new JoinCollections(); Join.Select("Demand") .Join("ReferenceObjects", "objects.objectReference", "_id", "name=>objectref"); return(Join.Find(query)); }
public async Task log_has_expected_bson_datatypes() { MockClock clockMock = new MockClock(); (IBank <TestUser> bank, IMongoCollection <TestUser> usersCollection) = CreateDbObjects(clockMock); TestUser user = new TestUser { Money = 10 }; await usersCollection.InsertOneAsync(user); List <int> list = new List <int> { 1, 2, 3 }; Dictionary <string, bool> dictionary = new Dictionary <string, bool> { ["yes"] = true, ["no"] = false }; await bank.PerformTransaction(new Transaction <TestUser>(user, 1, "test", new Dictionary <string, object?> { ["null_field"] = null, ["int_field"] = 42, ["string_field"] = "foo", ["list_field"] = list, ["dictionary_field"] = dictionary })); IMongoCollection <BsonDocument> transactionLogCollection = usersCollection.Database.GetCollection <BsonDocument>("transactionLog"); BsonDocument log = await transactionLogCollection.Find(FilterDefinition <BsonDocument> .Empty).FirstAsync(); Assert.IsInstanceOf <BsonObjectId>(log["_id"]); Assert.AreEqual(BsonString.Create(user.Id), log["user"]); Assert.AreEqual(BsonInt64.Create(1), log["change"]); Assert.AreEqual(BsonInt64.Create(10), log["old_balance"]); Assert.AreEqual(BsonInt64.Create(11), log["new_balance"]); Assert.AreEqual(clockMock.FixedCurrentInstant, log["timestamp"].ToUniversalTime().ToInstant()); Assert.AreEqual(BsonString.Create("test"), log["type"]); Assert.AreEqual(BsonNull.Value, log["null_field"]); Assert.AreEqual(BsonInt32.Create(42), log["int_field"]); Assert.AreEqual(BsonString.Create("foo"), log["string_field"]); Assert.AreEqual(BsonArray.Create(list), log["list_field"]); Assert.AreEqual(BsonDocument.Create(dictionary), log["dictionary_field"]); }
private static BsonValue ToBsonValue(this TypedItem item) { BsonValue bson = null; Type type = item.Value.GetType(); switch (type.Name.ToLower()) { case "string": bson = new BsonString(item.Value.ToString()); break; case "datetime": bson = new BsonDateTime((DateTime)item.Value); break; case "int16": case "int32": bson = new BsonInt32((Int32)item.Value); break; case "int64": bson = new BsonInt64((Int64)item.Value); break; case "double": bson = new BsonDouble((double)item.Value); break; case "boolean": bson = new BsonBoolean((bool)item.Value); break; case "byte[]": bson = new BsonObjectId((byte[])item.Value); break; default: bson = new BsonString(item.Value.ToString()); break; } return(bson); }
public void TestClassWithBsonInt64Id() { _collection.RemoveAll(); var doc = new ClassWithBsonInt64Id { Id = null, X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonInt64Id { Id = BsonInt64.Create(0), X = 1 }; _collection.Insert(doc); doc = new ClassWithBsonInt64Id { Id = BsonInt64.Create(1), X = 1 }; _collection.Insert(doc); }
public void TestCompareDifferentTypeOnes() { var n1 = new BsonInt32(1); var n2 = new BsonInt64(1); var n3 = new BsonDouble(1.0); Assert.IsTrue(n1 == n2); Assert.IsTrue(n1 == n3); Assert.IsTrue(n2 == n1); Assert.IsTrue(n2 == n3); Assert.IsTrue(n3 == n1); Assert.IsTrue(n3 == n2); var v1 = (BsonValue)new BsonInt32(1); var v2 = (BsonValue)new BsonInt64(1); var v3 = (BsonValue)new BsonDouble(1.0); Assert.IsTrue(v1 == v2); Assert.IsTrue(v1 == v3); Assert.IsTrue(v2 == v1); Assert.IsTrue(v2 == v3); Assert.IsTrue(v3 == v1); Assert.IsTrue(v3 == v2); }
/// <summary> /// 各种基本类型的初始值 /// </summary> /// <param name="DataType"></param> /// <returns></returns> public static BsonValue GetInitValue(BsonValueEx.BasicType DataType) { BsonValue InitValue = BsonNull.Value; switch (DataType) { case BasicType.BsonString: InitValue = new BsonString(string.Empty); break; case BasicType.BsonInt32: InitValue = new BsonInt32(0); break; case BasicType.BsonInt64: InitValue = new BsonInt64(0); break; case BasicType.BsonDecimal128: InitValue = new BsonDecimal128(0); break; case BasicType.BsonDouble: InitValue = new BsonDouble(0); break; case BasicType.BsonDateTime: InitValue = new BsonDateTime(DateTime.Now); break; case BasicType.BsonBoolean: InitValue = BsonBoolean.False; break; case BasicType.BsonArray: InitValue = new BsonArray(); break; case BasicType.BsonDocument: InitValue = new BsonDocument(); break; case BasicType.BsonLegacyPoint: InitValue = new BsonArray() { 0, 0 }; break; case BasicType.BsonGeoJSON: InitValue = new BsonDocument("type", "Point"); InitValue.AsBsonDocument.Add("coordinates", new BsonArray() { 0, 0 }); break; case BasicType.BsonMaxKey: InitValue = BsonMaxKey.Value; break; case BasicType.BsonMinKey: InitValue = BsonMinKey.Value; break; case BasicType.BsonBinary: InitValue = new BsonBinaryData(new byte[0]); break; default: break; } return InitValue; }
public void TestBsonInt64() { var value = new BsonInt64(1); Assert.AreSame(value, ((IConvertible)value).ToType(typeof(object), null)); Assert.AreEqual(true, Convert.ToBoolean(value)); Assert.AreEqual(1, Convert.ToByte(value)); Assert.AreEqual(1, Convert.ToChar(value)); Assert.Throws<InvalidCastException>(() => Convert.ToDateTime(value)); Assert.AreEqual(1m, Convert.ToDecimal(value)); Assert.AreEqual(1.0, Convert.ToDouble(value)); Assert.AreEqual(1, Convert.ToInt16(value)); Assert.AreEqual(1, Convert.ToInt32(value)); Assert.AreEqual(1, Convert.ToInt64(value)); Assert.AreEqual(1, Convert.ToSByte(value)); Assert.AreEqual(1.0F, Convert.ToSingle(value)); Assert.AreEqual("1", Convert.ToString(value)); Assert.AreEqual(1, Convert.ToUInt16(value)); Assert.AreEqual(1, Convert.ToUInt32(value)); Assert.AreEqual(1, Convert.ToUInt64(value)); }
/// <summary> /// 使用属性会发生一些MONO上的移植问题 /// </summary> /// <returns></returns> public BsonValue GetValue(BsonValueEx.BasicType DataType) { BsonValue mValue = null; switch (DataType) { case BsonValueEx.BasicType.BsonString: mValue = new BsonString(txtBsonValue.Text); break; case BsonValueEx.BasicType.BsonInt32: mValue = new BsonInt32(Convert.ToInt32(NumberPick.Value)); break; case BsonValueEx.BasicType.BsonInt64: mValue = new BsonInt64(Convert.ToInt64(NumberPick.Value)); break; case BsonValueEx.BasicType.BsonDecimal128: mValue = new BsonDecimal128(Convert.ToDecimal(NumberPick.Value)); break; case BsonValueEx.BasicType.BsonDouble: mValue = new BsonDouble(Convert.ToDouble(txtBsonValue.Text)); break; case BsonValueEx.BasicType.BsonDateTime: mValue = new BsonDateTime(dateTimePicker.Value); break; case BsonValueEx.BasicType.BsonBoolean: mValue = radTrue.Checked ? BsonBoolean.True : BsonBoolean.False; break; case BsonValueEx.BasicType.BsonArray: case BsonValueEx.BasicType.BsonLegacyPoint: mValue = _mBsonArray; break; case BsonValueEx.BasicType.BsonGeoJSON: case BsonValueEx.BasicType.BsonDocument: mValue = _mBsonDocument; break; case BsonValueEx.BasicType.BsonMaxKey: mValue = BsonMaxKey.Value; break; case BsonValueEx.BasicType.BsonMinKey: mValue = BsonMinKey.Value; break; case BsonValueEx.BasicType.BsonBinary: mValue = new BsonBinaryData(Encoding.Default.GetBytes(txtBsonValue.Text)); break; } return mValue; }
public void operator_equals_with_BsonInt64_should_return_expected_result(long lhsInt64Value, long rhsInt64Value, bool expectedResult) { var lhs = new BsonInt64(lhsInt64Value); var rhs = new BsonInt64(rhsInt64Value); var result = lhs == rhs; result.Should().Be(expectedResult); }
public void DiffTwoDifferentBsonTypes() { // Arrange var a = new BsonInt32(100); var b = new BsonInt64(100); var expected = new BsonDocument("types differ", new BsonDocument {{"a", "Int32"}, {"b", "Int64"}}); // Act var doc = a.Diff(b); // Assert Assert.That(doc, Is.EqualTo(expected)); }
/// <summary>Try to convert the string to a <see cref="BsonInt64"/>.</summary> /// <param name="value">The value to convert.</param> /// <param name="bsonValue">The BsonValue result.</param> /// <returns><c>true</c> if the value was converted; otherwise <c>false</c>.</returns> public static bool TryInt64(this string value, out BsonValue bsonValue) { bsonValue = null; if (value == null) return false; long result; var r = long.TryParse(value, out result); if (r) bsonValue = new BsonInt64(result); return r; }
/// <summary> /// 还原BsonValue /// </summary> /// <returns></returns> public BsonValue GetBsonValue() { BsonValue value = new BsonString(string.Empty); switch (mBsonType) { case BasicType.BsonString: value = new BsonString(mBsonString); break; case BasicType.BsonInt32: value = new BsonInt32(mBsonInt32); break; case BasicType.BsonInt64: value = new BsonInt64(mBsonInt64); break; case BasicType.BsonDecimal128: value = new BsonDecimal128(mBSonDecimal128); break; case BasicType.BsonDouble: value = new BsonDouble(mBsonDouble); break; case BasicType.BsonDateTime: value = new BsonDateTime(mBsonDateTime); break; case BasicType.BsonBoolean: value = mBsonBoolean ? BsonBoolean.True : BsonBoolean.False; break; case BasicType.BsonMaxKey: value = BsonMaxKey.Value; break; case BasicType.BsonMinKey: value = BsonMinKey.Value; break; case BasicType.BsonBinary: value = new BsonBinaryData(mBsonBinary); break; } return value; }
public void ParseConditionValueForIntTest() { MongoDataSource_Accessor target = new MongoDataSource_Accessor(); string value = "123"; BsonInt64 expected = new BsonInt64(Int64.Parse(value)); object parsedValue = target.ParseConditionValue(value, DataType.DT_I8); Assert.AreEqual(expected, parsedValue); parsedValue = target.ParseConditionValue(value, DataType.DT_I4); Assert.AreEqual(expected, parsedValue); }
public TestClass( BsonInt64 value ) { this.B = value; this.V = value; }
public void TestMapBsonInt64() { var value = new BsonInt64(1L); var bsonValue = (BsonInt64) BsonTypeMapper.MapToBsonValue(value); Assert.AreSame(value, bsonValue); var bsonInt64 = (BsonInt64) BsonTypeMapper.MapToBsonValue(value, BsonType.Int64); Assert.AreSame(value, bsonInt64); }
private BsonValue ParseConditionValue(String value, DataType dt) { BsonValue parsedValue = value; if (dt == DataType.DT_DATE | dt == DataType.DT_DBTIMESTAMPOFFSET | dt == DataType.DT_DBTIMESTAMP) { if ("now".Equals(value, StringComparison.CurrentCultureIgnoreCase) || "today".Equals(value, StringComparison.CurrentCultureIgnoreCase)) { parsedValue = new BsonDateTime(DateTime.Now); } else if ("yesterday".Equals(value, StringComparison.CurrentCultureIgnoreCase)) { parsedValue = new BsonDateTime(DateTime.Now.AddDays(-1)); } else if (value.StartsWith("-")) { int noOfDays = Int16.Parse(value); parsedValue = new BsonDateTime(DateTime.Now.AddDays(noOfDays)); } else { parsedValue = new BsonDateTime(DateTime.Parse(value)); } } else if (dt == DataType.DT_I8 || dt == DataType.DT_I4) { parsedValue = new BsonInt64(Int64.Parse(value)); } else if (dt == DataType.DT_R8 || dt == DataType.DT_R4) { parsedValue = new BsonDouble(Double.Parse(value)); } return parsedValue; }
public void TestBsonInt64Equals() { var a = new BsonInt64(1L); var b = new BsonInt64(1L); var c = new BsonInt32(1); var d = new BsonDouble(1.0); var e = new BsonInt64(2L); var f = new BsonInt32(2); var g = new BsonDouble(2.0); var n = (BsonInt64)null; Assert.IsTrue(object.Equals(a, b)); Assert.IsFalse(object.Equals(a, c)); Assert.IsFalse(object.Equals(a, d)); Assert.IsFalse(object.Equals(a, e)); Assert.IsFalse(object.Equals(a, f)); Assert.IsFalse(object.Equals(a, g)); Assert.IsFalse(object.Equals(a, BsonNull.Value)); Assert.IsFalse(a.Equals(n)); Assert.IsFalse(a.Equals(null)); Assert.IsTrue(a == b); Assert.IsTrue(a == c); Assert.IsTrue(a == d); Assert.IsFalse(a == e); Assert.IsFalse(a == f); Assert.IsFalse(a == g); Assert.IsFalse(a == BsonNull.Value); Assert.IsFalse(a == null); Assert.IsFalse(null == a); Assert.IsTrue(n == null); Assert.IsTrue(null == n); Assert.IsFalse(a != b); Assert.IsFalse(a != c); Assert.IsFalse(a != d); Assert.IsTrue(a != e); Assert.IsTrue(a != f); Assert.IsTrue(a != g); Assert.IsTrue(a != BsonNull.Value); Assert.IsTrue(a != null); Assert.IsTrue(null != a); Assert.IsFalse(n != null); Assert.IsFalse(null != n); }