public void TestLargeLongValue2() { // https://forums.couchbase.com/t/long-value-on-document-changed-after-saved-to-db/14259 using (var doc = new MutableDocument("test")) { var num1 = 11989091L; var num2 = 231548688L; doc.SetLong("num1", num1); doc.SetLong("num2", num2); using (var saved = Db.Save(doc)) using (var newDoc = saved.ToMutable()) { newDoc.GetLong("num1").Should().Be(num1); newDoc.GetLong("num2").Should().Be(num2); } } }
public void TestLargeLongValue() { using (var doc = new MutableDocument("test")) { var num1 = 1234567L; var num2 = 12345678L; var num3 = 123456789L; doc.SetLong("num1", num1); doc.SetLong("num2", num2); doc.SetLong("num3", num3); using (var saved = Db.Save(doc)) using (var newDoc = saved.ToMutable()) { newDoc.GetLong("num1").Should().Be(num1); newDoc.GetLong("num2").Should().Be(num2); newDoc.GetLong("num3").Should().Be(num3); } } }
private void SetDocument(T entity, MutableDocument mutableDocument) { var properties = ObjectToDictionaryHelper.ToDictionary(entity); foreach (var prop in properties) { if (prop.Value is int) { mutableDocument.SetInt(prop.Key, (int)prop.Value); } else if (prop.Value is long) { mutableDocument.SetLong(prop.Key, (long)prop.Value); } else if (prop.Value is bool) { mutableDocument.SetBoolean(prop.Key, (bool)prop.Value); } else if (prop.Value is DateTimeOffset) { if ((DateTimeOffset)prop.Value != default(DateTimeOffset)) { mutableDocument.SetDate(prop.Key, (DateTimeOffset)prop.Value); } } else if (prop.Value is double) { mutableDocument.SetDouble(prop.Key, (double)prop.Value); } else if (prop.Value is float) { mutableDocument.SetFloat(prop.Key, (float)prop.Value); } else if (prop.Value is string) { mutableDocument.SetString(prop.Key, (string)prop.Value); } else { mutableDocument.SetValue(prop.Key, prop.Value); } } }
public void TestGetFragmentFromLong() { var doc = new MutableDocument("doc1"); doc.SetLong("long", 10L); SaveDocument(doc, d => { var fragment = d["long"]; fragment.Exists.Should().BeTrue("because this portion of the data exists"); fragment.String.Should().BeNull("because this fragment is not of this type"); fragment.Array.Should().BeNull("because this fragment is not of this type"); fragment.Dictionary.Should().BeNull("because this fragment is not of this type"); fragment.Int.Should().Be(10, "because that is the converted value"); fragment.Long.Should().Be(10L, "because that is the stored value"); fragment.Double.Should().Be(10.0, "because that is the converted value"); fragment.Float.Should().Be(10.0f, "because that is the converted value"); fragment.Boolean.Should().Be(true, "because that is the converted value"); fragment.Date.Should().Be(DateTimeOffset.MinValue, "because that is the default value"); fragment.Value.Should().NotBeNull("because this fragment has a value"); }); }