public void Can_Serialize_empty_model_of_NullableTypes() { var model = new ModelWithFieldsOfNullableTypes(); var json = JsonSerializer.SerializeToString(model); var fromJson = JsonSerializer.DeserializeFromString<ModelWithFieldsOfNullableTypes>(json); ModelWithFieldsOfNullableTypes.AssertIsEqual(model, fromJson); }
public static void AssertIsEqual(ModelWithFieldsOfNullableTypes actual, ModelWithFieldsOfNullableTypes expected) { Assert.That(actual.Id, Is.EqualTo(expected.Id)); Assert.That(actual.NId, Is.EqualTo(expected.NId)); Assert.That(actual.NGuid, Is.EqualTo(expected.NGuid)); Assert.That(actual.NLongId, Is.EqualTo(expected.NLongId)); Assert.That(actual.NBool, Is.EqualTo(expected.NBool)); Assert.That(actual.NTimeSpan, Is.EqualTo(expected.NTimeSpan)); Assert.That(actual.NDateTime, Is.EqualTo(expected.NDateTime).Within(TimeSpan.FromSeconds(1))); Assert.That(actual.NFloat, Is.EqualTo(expected.NFloat).Within(1f)); Assert.That(actual.NDouble, Is.EqualTo(expected.NDouble).Within(1d)); }
public static ModelWithFieldsOfNullableTypes CreateConstant(int id) { ModelWithFieldsOfNullableTypes modelWithFieldsOfNullableType1 = new ModelWithFieldsOfNullableTypes(); modelWithFieldsOfNullableType1.Id = id; modelWithFieldsOfNullableType1.NId = new int?(id); modelWithFieldsOfNullableType1.NBool = new bool?(id % 2 == 0); modelWithFieldsOfNullableType1.NDateTime = new DateTime?(new DateTime(1979, id % 12 + 1, id % 28 + 1)); modelWithFieldsOfNullableType1.NFloat = new float?(1.11f + (float)id); modelWithFieldsOfNullableType1.NDouble = new double?(1.11 + (double)id); modelWithFieldsOfNullableType1.NGuid = new Guid?(new Guid((id % 240 + 16).ToString("X") + "7DA519-73B6-4525-84BA-B57673B2360D")); modelWithFieldsOfNullableType1.NLongId = new long?((long)999 + id); modelWithFieldsOfNullableType1.NDecimal = new decimal?(id + 0.5m); modelWithFieldsOfNullableType1.NTimeSpan = new TimeSpan?(TimeSpan.FromSeconds((double)id)); return(modelWithFieldsOfNullableType1); }
public static ModelWithFieldsOfNullableTypes CreateConstant(int id) { var row = new ModelWithFieldsOfNullableTypes { Id = id, NId = id, NBool = id % 2 == 0, NDateTime = new DateTime(1979, (id % 12) + 1, (id % 28) + 1), NFloat = 1.11f + id, NDouble = 1.11d + id, NGuid = new Guid(((id % 240) + 16).ToString("X") + "7DA519-73B6-4525-84BA-B57673B2360D"), NLongId = 999 + id, NDecimal = id + 0.5m, NTimeSpan = TimeSpan.FromSeconds(id), }; return row; }
public static ModelWithFieldsOfNullableTypes Create(int id) { var row = new ModelWithFieldsOfNullableTypes { Id = id, NId = id, NBool = id % 2 == 0, NDateTime = DateTime.Now.AddDays(id), NFloat = 1.11f + id, NDouble = 1.11d + id, NGuid = Guid.NewGuid(), NLongId = 999 + id, NDecimal = id + 0.5m, NTimeSpan = TimeSpan.FromSeconds(id), }; return row; }
public static ModelWithFieldsOfNullableTypes CreateConstant(int id) { var row = new ModelWithFieldsOfNullableTypes { Id = id, NId = id, NBool = id % 2 == 0, NDateTime = new DateTime(1979, (id % 12) + 1, (id % 28) + 1), NFloat = 1.11f + id, NDouble = 1.11d + id, NGuid = new Guid(((id % 240) + 16).ToString("X") + "7DA519-73B6-4525-84BA-B57673B2360D"), NLongId = 999 + id, NDecimal = id + 0.5m, NTimeSpan = TimeSpan.FromSeconds(id), }; return(row); }
public static ModelWithFieldsOfNullableTypes Create(int id) { var row = new ModelWithFieldsOfNullableTypes { Id = id, NId = id, NBool = id % 2 == 0, NDateTime = DateTime.Now.AddDays(id), NFloat = 1.11f + id, NDouble = 1.11d + id, NGuid = Guid.NewGuid(), NLongId = 999 + id, NDecimal = id + 0.5m, NTimeSpan = TimeSpan.FromSeconds(id), }; return(row); }
public static ModelWithFieldsOfNullableTypes Create(int id) { ModelWithFieldsOfNullableTypes modelWithFieldsOfNullableType1 = new ModelWithFieldsOfNullableTypes(); modelWithFieldsOfNullableType1.Id = id; modelWithFieldsOfNullableType1.NId = new int?(id); modelWithFieldsOfNullableType1.NBool = new bool?(id % 2 == 0); modelWithFieldsOfNullableType1.NDateTime = new DateTime?(DateTime.Now.AddDays((double)id)); modelWithFieldsOfNullableType1.NFloat = new float?(1.11f + (float)id); modelWithFieldsOfNullableType1.NDouble = new double?(1.11 + (double)id); modelWithFieldsOfNullableType1.NGuid = new Guid?(Guid.NewGuid()); modelWithFieldsOfNullableType1.NLongId = new long?((long)999 + id); modelWithFieldsOfNullableType1.NDecimal = new decimal?(id + 0.5m); modelWithFieldsOfNullableType1.NTimeSpan = new TimeSpan?(TimeSpan.FromSeconds((double)id)); ModelWithFieldsOfNullableTypes modelWithFieldsOfNullableType2 = modelWithFieldsOfNullableType1; return(modelWithFieldsOfNullableType2); }
public static void AssertIsEqual(ModelWithFieldsOfNullableTypes actual, ModelWithFieldsOfNullableTypes expected) { Assert.That(actual.Id, Is.EqualTo(expected.Id)); Assert.That(actual.NId, Is.EqualTo(expected.NId)); Assert.That(actual.NGuid, Is.EqualTo(expected.NGuid)); Assert.That(actual.NLongId, Is.EqualTo(expected.NLongId)); Assert.That(actual.NBool, Is.EqualTo(expected.NBool)); Assert.That(actual.NTimeSpan, Is.EqualTo(expected.NTimeSpan)); try { Assert.That(actual.NDateTime, Is.EqualTo(expected.NDateTime)); } catch (Exception ex) { Log.Error("Trouble with DateTime precisions, trying Assert again with rounding to seconds", ex); Assert.That(actual.NDateTime.Value.ToUniversalTime().RoundToSecond(), Is.EqualTo(expected.NDateTime.Value.ToUniversalTime().RoundToSecond())); } try { Assert.That(actual.NFloat, Is.EqualTo(expected.NFloat)); } catch (Exception ex) { Log.Error("Trouble with float precisions, trying Assert again with rounding to 10 decimals", ex); Assert.That(Math.Round(actual.NFloat.Value, 10), Is.EqualTo(Math.Round(actual.NFloat.Value, 10))); } try { Assert.That(actual.NDouble, Is.EqualTo(expected.NDouble)); } catch (Exception ex) { Log.Error("Trouble with double precisions, trying Assert again with rounding to 10 decimals", ex); Assert.That(Math.Round(actual.NDouble.Value, 10), Is.EqualTo(Math.Round(actual.NDouble.Value, 10))); } }
public void Can_access_ModelWithFieldsOfDifferentAndNullableTypes() { var idAccessor = new PropertyAccessor<ModelWithFieldsOfNullableTypes>("Id"); var idNAccessor = new PropertyAccessor<ModelWithFieldsOfNullableTypes>("NId"); var longIdAccessor = new PropertyAccessor<ModelWithFieldsOfNullableTypes>("NLongId"); var guidAccessor = new PropertyAccessor<ModelWithFieldsOfNullableTypes>("NGuid"); var boolAccessor = new PropertyAccessor<ModelWithFieldsOfNullableTypes>("NBool"); var dateTimeAccessor = new PropertyAccessor<ModelWithFieldsOfNullableTypes>("NDateTime"); var floatAccessor = new PropertyAccessor<ModelWithFieldsOfNullableTypes>("NFloat"); var doubleAccessor = new PropertyAccessor<ModelWithFieldsOfNullableTypes>("NDouble"); var decimalAccessor = new PropertyAccessor<ModelWithFieldsOfNullableTypes>("NDecimal"); var timespanAccessor = new PropertyAccessor<ModelWithFieldsOfNullableTypes>("NTimeSpan"); var original = ModelWithFieldsOfNullableTypesFactory.Instance.CreateInstance(1); Assert.That(idAccessor.GetPropertyFn()(original), Is.EqualTo(original.Id)); Assert.That(idNAccessor.GetPropertyFn()(original), Is.EqualTo(original.NId)); Assert.That(longIdAccessor.GetPropertyFn()(original), Is.EqualTo(original.NLongId)); Assert.That(guidAccessor.GetPropertyFn()(original), Is.EqualTo(original.NGuid)); Assert.That(boolAccessor.GetPropertyFn()(original), Is.EqualTo(original.NBool)); Assert.That(dateTimeAccessor.GetPropertyFn()(original), Is.EqualTo(original.NDateTime)); Assert.That(floatAccessor.GetPropertyFn()(original), Is.EqualTo(original.NFloat)); Assert.That(doubleAccessor.GetPropertyFn()(original), Is.EqualTo(original.NDouble)); Assert.That(decimalAccessor.GetPropertyFn()(original), Is.EqualTo(original.NDecimal)); Assert.That(timespanAccessor.GetPropertyFn()(original), Is.EqualTo(original.NTimeSpan)); var to = ModelWithFieldsOfNullableTypesFactory.Instance.CreateInstance(2); idAccessor.SetPropertyFn()(original, to.Id); idNAccessor.SetPropertyFn()(original, to.NId); longIdAccessor.SetPropertyFn()(original, to.NLongId); guidAccessor.SetPropertyFn()(original, to.NGuid); boolAccessor.SetPropertyFn()(original, to.NBool); dateTimeAccessor.SetPropertyFn()(original, to.NDateTime); floatAccessor.SetPropertyFn()(original, to.NFloat); doubleAccessor.SetPropertyFn()(original, to.NDouble); decimalAccessor.SetPropertyFn()(original, to.NDecimal); timespanAccessor.SetPropertyFn()(original, to.NTimeSpan); ModelWithFieldsOfNullableTypesFactory.Instance.AssertIsEqual(original, to); //Can handle nulls original = new ModelWithFieldsOfNullableTypes(); Assert.That(idAccessor.GetPropertyFn()(original), Is.EqualTo(original.Id)); Assert.That(idNAccessor.GetPropertyFn()(original), Is.EqualTo(original.NId)); Assert.That(longIdAccessor.GetPropertyFn()(original), Is.EqualTo(original.NLongId)); Assert.That(guidAccessor.GetPropertyFn()(original), Is.EqualTo(original.NGuid)); Assert.That(boolAccessor.GetPropertyFn()(original), Is.EqualTo(original.NBool)); Assert.That(dateTimeAccessor.GetPropertyFn()(original), Is.EqualTo(original.NDateTime)); Assert.That(floatAccessor.GetPropertyFn()(original), Is.EqualTo(original.NFloat)); Assert.That(doubleAccessor.GetPropertyFn()(original), Is.EqualTo(original.NDouble)); Assert.That(decimalAccessor.GetPropertyFn()(original), Is.EqualTo(original.NDecimal)); Assert.That(timespanAccessor.GetPropertyFn()(original), Is.EqualTo(original.NTimeSpan)); }