public void ConvertFromRow_2ModelValidationError() { var reader = CreateTableReader <Model>("", validator: new DefaultModelValidator()); reader.ErrorLimit = 2; var maps = new AutoIndexPropertyMapper().CreatePropertyMaps(typeof(Model), null); try { reader.ConvertFromRow(new[] { "1", "TOO_LONG", null }, 2, maps); Assert.Fail(); } catch (TableIOException ex) { Assert.AreEqual(2, ex.Errors.Count); var error = ex.Errors[0]; Assert.AreEqual("ModelValidation", error.Type); Assert.AreEqual("PStringError", error.Message); Assert.AreEqual(2, error.RowIndex); CollectionAssert.AreEqual(new[] { "PString" }, error.MemberNames.ToArray()); error = ex.Errors[1]; Assert.AreEqual("PNIntError", error.Message); CollectionAssert.AreEqual(new[] { "PNInt" }, error.MemberNames.ToArray()); } }
public void ConvertFromRow_ConvertFailed() { var reader = CreateTableReader <Model>(""); var maps = new AutoIndexPropertyMapper().CreatePropertyMaps(typeof(Model), null); try { reader.ConvertFromRow(new[] { "NG", "abc", "10" }, 2, maps); Assert.Fail(); } catch (TableIOException ex) { Assert.AreEqual(1, ex.Errors.Count); var error = ex.Errors[0]; Assert.AreEqual("ConvertFailed", error.Type); Assert.AreEqual(2, error.RowIndex); Assert.AreEqual(0, error.ColumnIndex); Assert.AreEqual("PInt", error.MemberNames.First()); } try { reader.ConvertFromRow(new[] { "1", "abc", "NG" }, 2, maps); Assert.Fail(); } catch (TableIOException ex) { var error = ex.Errors[1]; Assert.AreEqual(2, error.ColumnIndex); Assert.AreEqual("PNInt", error.MemberNames.First()); } }
public void ConvertFromRow_EmptyToNullableInt() { var reader = CreateTableReader <Model>(""); var maps = new AutoIndexPropertyMapper().CreatePropertyMaps(typeof(Model), null); var model = reader.ConvertFromRow(new[] { "1", "abc", "" }, 0, maps); Assert.AreEqual(null, model.PNInt); }
public void Read_HasReadOnlyModel() { var mapper = new AutoIndexPropertyMapper(AutoIndexPropertyTargetType.CanWrite); var reader = CreateTableReader <HasReadOnlyModel>("1\n2", mapper: mapper); var models = reader.Read().ToList(); Assert.AreEqual(2, models.Count); }
public void ConvertFromRow() { var reader = CreateTableReader <Model>(""); var maps = new AutoIndexPropertyMapper().CreatePropertyMaps(typeof(Model), null); var model = reader.ConvertFromRow(new[] { "1", "abc", "10" }, 0, maps); Assert.AreEqual(1, model.PInt); Assert.AreEqual("abc", model.PString); Assert.AreEqual(10, model.PNInt); }
public void CreatePropertyMaps() { var mapper = new AutoIndexPropertyMapper(); var maps = mapper.CreatePropertyMaps(typeof(Model), null).ToArray(); Assert.AreEqual(0, maps[0].ColumnIndex); Assert.AreEqual(1, maps[1].ColumnIndex); Assert.AreEqual(2, maps[2].ColumnIndex); Assert.AreEqual("P1", maps[0].Property.Name); Assert.AreEqual("P2", maps[1].Property.Name); Assert.AreEqual("P3", maps[2].Property.Name); }
public void ReadFailed_OutOfRangeColumnIndexMapping_ByReadOnlyProperty() { var mapper = new AutoIndexPropertyMapper(AutoIndexPropertyTargetType.All); var reader = CreateTableReader <HasReadOnlyModel>("1\n2", mapper: mapper); try { reader.Read().ToList(); Assert.Fail(); } catch (TableIOException ex) { Assert.AreEqual(1, ex.Errors.Count); Assert.AreEqual("OutOfRangeColumnIndexMapping", ex.Errors[0].Type); Assert.AreEqual(0, ex.Errors[0].RowIndex); } }
public void ConvertToRow() { var strWriter = new StringWriter(); var writer = CreateTableWriter <Model>(strWriter); var maps = new AutoIndexPropertyMapper().CreatePropertyMaps(typeof(Model), null); var row = writer.ConvertToRow(new Model { PInt = 1, PString = "aaa", PNInt = 10 }, maps, 3); Assert.AreEqual(3, row.Count); Assert.AreEqual(1, row[0]); Assert.AreEqual("aaa", row[1]); Assert.AreEqual(10, row[2]); row = writer.ConvertToRow(new Model { PInt = 1, PString = null, PNInt = null }, maps, 4); Assert.AreEqual(4, row.Count); Assert.AreEqual(1, row[0]); Assert.AreEqual(null, row[1]); Assert.AreEqual(null, row[2]); }