public void TestFixtureSetUp() { datumConverterFactory = Substitute.For<IDatumConverterFactory>(); queryConverter = new QueryConverter(datumConverterFactory, expressionConverterFactory); var stringDatum = new Datum() { type = Datum.DatumType.R_STR, r_str = "Jackpot!", }; var stringDatumConverter = Substitute.For<IDatumConverter<string>>(); stringDatumConverter .ConvertObject("Jackpot!") .Returns(stringDatum); stringDatumConverter .ConvertDatum(Arg.Is<Datum>(d => d.type == stringDatum.type && d.r_str == stringDatum.r_str)) .Returns("Jackpot!"); IDatumConverter<string> value; datumConverterFactory .TryGet<string>(queryConverter, out value) .Returns(args => { args[1] = stringDatumConverter; return true; }); IDatumConverter value2; datumConverterFactory .TryGet(typeof(string), queryConverter, out value2) .Returns(args => { args[2] = stringDatumConverter; return true; }); }
public void ConvertDatum_Timezone_ThrowsException() { var datum = new Datum() { type = Datum.DatumType.R_OBJECT }; datum.r_object.Add(new Datum.AssocPair() { key = "$reql_type$", val = new Datum() { type = Datum.DatumType.R_STR, r_str = "TIME" } }); datum.r_object.Add(new Datum.AssocPair() { key = "epoch_time", val = new Datum() { type = Datum.DatumType.R_NUM, r_num = 1376704156.123 } }); datum.r_object.Add(new Datum.AssocPair() { key = "timezone", val = new Datum() { type = Datum.DatumType.R_STR, r_str = "+01:00" } }); DateTimeDatumConverterFactory.Instance.Get<DateTime>().ConvertDatum(datum); }
public void ConvertDatum() { var datum = new Datum() { type = Datum.DatumType.R_OBJECT }; datum.r_object.Add(new Datum.AssocPair() { key = "$reql_type$", val = new Datum() { type = Datum.DatumType.R_STR, r_str = "TIME" } }); datum.r_object.Add(new Datum.AssocPair() { key = "epoch_time", val = new Datum() { type = Datum.DatumType.R_NUM, r_num = 1376704156.123 } }); datum.r_object.Add(new Datum.AssocPair() { key = "timezone", val = new Datum() { type = Datum.DatumType.R_STR, r_str = "+00:00" } }); var result = DateTimeDatumConverterFactory.Instance.Get<DateTime>().ConvertDatum(datum); Assert.That(result, Is.EqualTo(new DateTime(2013, 8, 17, 1, 49, 16, 123))); }
public void ConvertDatum() { var datum = new Datum { type = Datum.DatumType.R_OBJECT, r_object = { new Datum.AssocPair() { key = "key1", val = new Datum() { type = Datum.DatumType.R_NUM, r_num = 1 } }, new Datum.AssocPair() { key = "key2", val = new Datum() { type = Datum.DatumType.R_NUM, r_num = 2 } }, } }; var value = NamedValueDictionaryDatumConverterFactory.Instance.Get<Dictionary<string, object>>(datumConverterFactory).ConvertDatum(datum); value.Should().NotBeNull(); value.Should().Contain("key1", 1); value.Should().Contain("key2", 2); }
public void ConvertDatum() { var datum = new Datum() { type = Datum.DatumType.R_OBJECT }; datum.r_object.Add(new Datum.AssocPair() { key = "$reql_type$", val = new Datum() { type = Datum.DatumType.R_STR, r_str = "BINARY" } }); datum.r_object.Add(new Datum.AssocPair() { key = "data", val = new Datum() { type = Datum.DatumType.R_STR, r_str = "SGVsbG8sIHdvcmxkIQ==" } }); var result = BinaryDatumConverterFactory.Instance.Get<byte[]>().ConvertDatum(datum); Assert.That(result, Is.EquivalentTo(new byte[] { 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33 })); }
public void TestFixtureSetUp() { var datumConverterFactory = Substitute.For<IDatumConverterFactory>(); var stringDatum = new Datum() { type = Datum.DatumType.R_STR, r_str = "Jackpot!", }; var stringDatumConverter = Substitute.For<IDatumConverter<string>>(); stringDatumConverter .ConvertObject("Jackpot!") .Returns(stringDatum); stringDatumConverter .ConvertDatum(Arg.Is<Datum>(d => d.type == stringDatum.type && d.r_str == stringDatum.r_str)) .Returns("Jackpot!"); testObject2Converter = DataContractDatumConverterFactory.Instance.Get<TestObject2>(datumConverterFactory); testObject4Converter = DataContractDatumConverterFactory.Instance.Get<TestObject4>(datumConverterFactory); testObjectStructEmitDefaultValueFieldConverter = DataContractDatumConverterFactory.Instance.Get<TestObjectStructEmitDefaultValueField>(datumConverterFactory); testObjectStructEmitDefaultValuePropertyConverter = DataContractDatumConverterFactory.Instance.Get<TestObjectStructEmitDefaultValueProperty>(datumConverterFactory); IDatumConverter<string> value; datumConverterFactory .TryGet<string>(datumConverterFactory, out value) .Returns(args => { args[1] = stringDatumConverter; return true; }); }
public void ConvertDatum_Object_ExceptionOnInvalidTupleSize() { var datum = new RethinkDb.Spec.Datum { type = RethinkDb.Spec.Datum.DatumType.R_OBJECT }; TupleDatumConverterFactory.Instance.Get <Tuple <string, string, string> >(datumConverterFactory).ConvertDatum(datum); }
public void ConvertDatumWrongType() { var datum = new Datum() { type = Datum.DatumType.R_STR, r_str = "60", }; datumConverter.ConvertDatum(datum); }
public void ConvertDatum_Object_ExceptionOnInvalidKey() { var datum = new RethinkDb.Spec.Datum {type = RethinkDb.Spec.Datum.DatumType.R_OBJECT}; datum.r_object.Add(new Datum.AssocPair { key = "hi", val = null }); datum.r_object.Add(new Datum.AssocPair { key = "group", val = null }); TupleDatumConverterFactory.Instance.Get<Tuple<string, string>>(datumConverterFactory).ConvertDatum(datum); }
public void ConvertDatum_Array_ExceptionOnSizeMismatch() { string[] expected = {"one","two","three"}; var datum = new RethinkDb.Spec.Datum {type = RethinkDb.Spec.Datum.DatumType.R_ARRAY}; datum.r_array.AddRange(expected.Select(DatumHelpers.ToDatum)); TupleDatumConverterFactory.Instance.Get<Tuple<string, string>>(datumConverterFactory).ConvertDatum(datum); }
public void ConvertDatumNullable() { var datum = new Datum() { type = Datum.DatumType.R_NULL, }; var value = datumConverter.ConvertDatum(datum); Assert.That(value.HasValue, Is.False); }
public DatumReaderToken(Datum d) { this.Datum = d; if (Datum.type == Datum.DatumType.R_OBJECT) this.AssocPairs = Datum.r_object.GetEnumerator(); else if (Datum.type == Datum.DatumType.R_ARRAY) this.Array = Datum.r_array.GetEnumerator(); }
public void ConvertDatum_ExceptionOnUnsupportedType() { var datum = new RethinkDb.Spec.Datum { type = RethinkDb.Spec.Datum.DatumType.R_NUM }; TupleDatumConverterFactory.Instance.Get <Tuple <string, string> >(datumConverterFactory).ConvertDatum(datum); }
public void NonGenericConvertDatumNullable() { var datum = new Datum() { type = Datum.DatumType.R_NULL, }; var value = ((IDatumConverter)datumConverter).ConvertDatum(datum); Assert.That(value, Is.Null); }
public void ConvertDatum_DefaultOnNull() { var datum = new RethinkDb.Spec.Datum { type = RethinkDb.Spec.Datum.DatumType.R_NULL }; var value = TupleDatumConverterFactory.Instance.Get <Tuple <string, string> >(datumConverterFactory).ConvertDatum(datum); Assert.That(value, Is.Null); }
public void ConvertDatum() { var datum = new Datum() { type = Datum.DatumType.R_NUM, r_num = 5 }; var value = datumConverter.ConvertDatum(datum); Assert.That(value.HasValue); }
public void ConvertDatumEmpty() { var datum = new Datum { type = Datum.DatumType.R_OBJECT }; var value = NamedValueDictionaryDatumConverterFactory.Instance.Get<Dictionary<string, object>>(datumConverterFactory).ConvertDatum(datum); value.Should().NotBeNull(); value.Count.Should().Be(0); }
public void ConvertDatum() { var datum = new Datum() { type = Datum.DatumType.R_NUM, r_num = 60.123, }; var ts = datumConverter.ConvertDatum(datum); Assert.That(ts, Is.EqualTo(TimeSpan.FromSeconds(60.123))); }
public void NonGenericConvertDatum() { var datum = new Datum() { type = Datum.DatumType.R_NUM, r_num = 5 }; var value = ((IDatumConverter)datumConverter).ConvertDatum(datum); Assert.That(value, Is.EqualTo(5)); }
public void ConvertDatum_ReturnsValueReferenceType() { string[] expected = {"one", "two", "three"}; var datum = new Datum {type = Datum.DatumType.R_ARRAY}; datum.r_array.AddRange(expected.Select(DatumHelpers.ToDatum)); var value = ArrayDatumConverterFactory.Instance.Get<string[]>(datumConverterFactory).ConvertDatum(datum); Assert.That(value, Is.EqualTo(expected)); }
public void ConvertDatum_ReturnsValue() { int[] expected = {1, 2, 3}; var datum = new Datum {type = Datum.DatumType.R_ARRAY}; datum.r_array.AddRange(expected.Select(DatumHelpers.ToDatum)); var value = ArrayDatumConverterFactory.Instance.Get<int[]>(datumConverterFactory).ConvertDatum(datum); Assert.That(value, Is.EqualTo(expected)); }
public void ConvertDatum_Array_ReturnsValue() { string[] expected = {"one","two"}; var datum = new RethinkDb.Spec.Datum {type = RethinkDb.Spec.Datum.DatumType.R_ARRAY}; datum.r_array.AddRange(expected.Select(DatumHelpers.ToDatum)); var value = TupleDatumConverterFactory.Instance.Get<Tuple<string, string>>(datumConverterFactory).ConvertDatum(datum); Assert.That(value, Is.EqualTo(new Tuple<string, string> ("one", "two"))); }
public void UInt64ConvertDatum() { var datumConverter = EnumDatumConverterFactory.Instance.Get<TestEnumUInt64>(); var datum = new Datum() { type = Datum.DatumType.R_NUM, r_num = 1L << 34, }; var value = datumConverter.ConvertDatum(datum); Assert.That(value, Is.EqualTo(TestEnumUInt64.Value1)); }
public void deseralizing_null_timespans_return_default() { var input = new Datum() { type = Datum.DatumType.R_NULL, }; var output = DatumConvert.DeserializeObject<TimeSpan>(input, new TimeSpanConverter()); output.Should().Be(default(TimeSpan)); }
public void deseralizing_nullable_timespans_return_null() { var input = new Datum() { type = Datum.DatumType.R_NULL, }; var output = DatumConvert.DeserializeObject<TimeSpan?>(input, new TimeSpanConverter()); output.Should().NotHaveValue(); }
public void Int32ConvertDatumInvalidEnum() { var datumConverter = EnumDatumConverterFactory.Instance.Get<TestEnumInt32>(); var datum = new Datum() { type = Datum.DatumType.R_NUM, r_num = 500, }; var value = datumConverter.ConvertDatum(datum); Assert.That(value, Is.EqualTo((TestEnumInt32)500)); }
public void ConvertDatum_Array_ExceptionOnSizeMismatch() { string[] expected = { "one", "two", "three" }; var datum = new RethinkDb.Spec.Datum { type = RethinkDb.Spec.Datum.DatumType.R_ARRAY }; datum.r_array.AddRange(expected.Select(DatumHelpers.ToDatum)); TupleDatumConverterFactory.Instance.Get <Tuple <string, string> >(datumConverterFactory).ConvertDatum(datum); }
public static void DatumCamelCase(Datum d) { foreach (var pair in d.r_object) { pair.key = ToCamelCase(pair.key); DatumCamelCase(pair.val); } foreach (var ele in d.r_array) { DatumCamelCase(ele); } }
public void should_be_able_to_serialize_timespan_to_floatseconds() { var span = new TimeSpan(days: 1, hours: 2, minutes: 3, seconds: 4, milliseconds: 5); var truth = new Datum() { type = Datum.DatumType.R_NUM, r_num = span.TotalSeconds }; var datum = DatumConvert.SerializeObject(span, new TimeSpanConverter()); truth.ShouldBeEquivalentTo(datum); }
public void should_be_able_to_deseralize_timespan_objects_from_floatseconds() { var timespan = new TimeSpan(days: 1, hours: 2, minutes: 3, seconds: 4, milliseconds: 5); var input = new Datum() { type = Datum.DatumType.R_NUM, r_num = timespan.TotalSeconds }; var output = DatumConvert.DeserializeObject<TimeSpan>(input, new TimeSpanConverter()); timespan.Should().Be(output); }
public void ConvertDatum_Array_ReturnsValue() { string[] expected = { "one", "two" }; var datum = new RethinkDb.Spec.Datum { type = RethinkDb.Spec.Datum.DatumType.R_ARRAY }; datum.r_array.AddRange(expected.Select(DatumHelpers.ToDatum)); var value = TupleDatumConverterFactory.Instance.Get <Tuple <string, string> >(datumConverterFactory).ConvertDatum(datum); Assert.That(value, Is.EqualTo(new Tuple <string, string> ("one", "two"))); }
public void ConvertDatum_NullElementWithNotNullResult() { var expected = new List<int> { 1, 2, 3 }; var datum = new Datum { type = Datum.DatumType.R_ARRAY }; datum.r_array.AddRange(expected.Select(DatumHelpers.ToDatum)); datum.r_array.Add(null); var value = ArrayDatumConverterFactory.Instance.Get<int[]>(datumConverterFactory).ConvertDatum(datum); expected.Add(0); Assert.That(value, Is.EqualTo(expected)); }
public void ConvertDatum_Object_ExceptionOnInvalidKey() { var datum = new RethinkDb.Spec.Datum { type = RethinkDb.Spec.Datum.DatumType.R_OBJECT }; datum.r_object.Add(new Datum.AssocPair { key = "hi", val = null }); datum.r_object.Add(new Datum.AssocPair { key = "group", val = null }); TupleDatumConverterFactory.Instance.Get <Tuple <string, string> >(datumConverterFactory).ConvertDatum(datum); }
public void ConvertDatum_Object_GroupReduction() { var datum = new RethinkDb.Spec.Datum { type = RethinkDb.Spec.Datum.DatumType.R_OBJECT }; datum.r_object.Add(new Datum.AssocPair { key = "group", val = "left".ToDatum() }); datum.r_object.Add(new Datum.AssocPair { key = "reduction", val = "right".ToDatum() }); var value = TupleDatumConverterFactory.Instance.Get <Tuple <string, string> >(datumConverterFactory).ConvertDatum(datum); Assert.That(value, Is.EqualTo(new Tuple <string, string> ("left", "right"))); }
public void TestIListStringConvertDatum() { var listStringConverter = ListDatumConverterFactory.Instance.Get<IList<string>>(rootDatumConverterFactory); var datum = new Datum() { type = Datum.DatumType.R_ARRAY }; datum.r_array.Add( new Datum() { type = Datum.DatumType.R_STR, r_str = "Jackpot!" } ); var list = listStringConverter.ConvertDatum(datum); Assert.That(list, Is.Not.Null); Assert.That(list, Has.Count.EqualTo(1)); Assert.That(list[0], Is.EqualTo("Jackpot!")); }
public void PropertyDataContractConvertDatum() { var datum = new Datum() { type = Datum.DatumType.R_OBJECT }; datum.r_object.Add(new Datum.AssocPair() { key = "name", val = new Datum() { type = Datum.DatumType.R_STR, r_str = "Jackpot!", } }); var obj = testObject4Converter.ConvertDatum(datum); Assert.That(obj, Is.Not.Null); Assert.That(obj.Id, Is.EqualTo(0)); Assert.That(obj.Name, Is.EqualTo("Jackpot!")); }
public void ser_deser_datetimeoffsetnullable_dateset() { var obj = new DateTimeOffsetNullable() { Id = "my_id", TheDateTimeOffset = DateTimeOffset.Parse("10/30/2013 4:12:02 PM -07:00") }; var truth = new Datum { type = Datum.DatumType.R_OBJECT }; truth.r_object.Add(new Datum.AssocPair { key = "Id", val = new Datum { type = Datum.DatumType.R_STR, r_str = "my_id" } }); truth.r_object.Add(new Datum.AssocPair { key = "TheDateTimeOffset", val = new Datum { type = Datum.DatumType.R_OBJECT, r_object = { new Datum.AssocPair {key = "$reql_type$", val = new Datum {type = Datum.DatumType.R_STR, r_str = "TIME"}}, new Datum.AssocPair {key = "epoch_time", val = new Datum {type = Datum.DatumType.R_NUM, r_num = 1383174722}}, new Datum.AssocPair {key = "timezone", val = new Datum {type = Datum.DatumType.R_STR, r_str = "-07:00"}}, } } }); //ser test var ser = DatumConvert.SerializeObject(obj); ser.ShouldBeEquivalentTo(truth); //deser test var newtonObj = DatumConvert.DeserializeObject<DateTimeOffsetNullable>(truth); newtonObj.ShouldBeEquivalentTo(obj); }
public Type GetBestNativeTypeForDatum(Spec.Datum datum) { return(delegatedDatumConverterFactory.GetBestNativeTypeForDatum(datum)); }