public void Test_Binding_ToEnumerableIndexer_Throws() { RootModel model = new RootModel() { IntEnumerable = new List <int>() { 1, 2, 3, 4, 5 } }; Relation rel = DatabaseHelper.Default.Relation(model, "IntEnumerable.Item"); Should.Throw <BindingException>(() => rel.Column().ElementAt(2).Bind(10)); }
public void Test_Binding_ToListIndexer() { RootModel model = new RootModel() { IntList = new List <int>() { 1, 2, 3, 4, 5 } }; Relation rel = DatabaseHelper.Default.Relation(model, "IntList.Item"); Should.NotThrow(() => rel.Column().ElementAt(2).Bind(10)); model.IntList.ShouldBe(new[] { 1, 2, 10, 4, 5 }); }
public void Test_Reading_ScalarList() { RootModel model = new RootModel() { IntList = new List <int>() { 1, 2, 3, 4, 5 }, }; Relation rel = DatabaseHelper.Default.Relation(model, "IntList.Item"); IEnumerable <int> ints = rel.Column().Select(f => (int)f.Value); ints.ShouldBe(new[] { 1, 2, 3, 4, 5 }); }
public void Test_Binding_ToDeepObjectGraph() { RootModel model = new RootModel() { Complex = new RootModel.SubModel() { Value = 50, Complex = new RootModel.SubModel2() { Value = "String 1", }, }, ComplexList = new List <RootModel.SubModel>() { new RootModel.SubModel() { Complex = new RootModel.SubModel2() { Value = "String 2" } }, new RootModel.SubModel() { Complex = new RootModel.SubModel2() { Value = "String 3" } }, }, }; Relation rel1 = DatabaseHelper.Default.Relation(model, "Complex.Value", "Complex.Complex.Value"); Relation rel2 = DatabaseHelper.Default.Relation(model, "ComplexList.Item.Complex.Value"); ITuple tuple1 = rel1.Row(); IField[] tuple2 = rel2.Column().ToArray(); tuple1[0].Bind(100); tuple1[1].Bind("String 3"); tuple2[0].Bind("String 4"); tuple2[1].Bind("String 5"); model.Complex.Value.ShouldBe(100); model.Complex.Complex.Value.ShouldBe("String 3"); model.ComplexList[0].Complex.Value.ShouldBe("String 4"); model.ComplexList[1].Complex.Value.ShouldBe("String 5"); }
public void Test_Fields_EqualityImplementation() { Model model1 = new Model() { ComplexList = new List <Model.SubModel>() { new Model.SubModel() { Value = 1 }, new Model.SubModel() { Value = 2 }, } }; Model model2 = new Model() { ComplexList = new List <Model.SubModel>() { new Model.SubModel() { Value = 1 }, new Model.SubModel() { Value = 2 }, } }; Relation rel1_1 = DatabaseHelper.Default.Relation(model1, "ComplexList.Item.Value"); Relation rel1_2 = DatabaseHelper.Default.Relation(model1, "ComplexList.Item.Value"); Relation rel2_1 = DatabaseHelper.Default.Relation(model2, "ComplexList.Item.Value"); IField[] fields1_1 = rel1_1.Column().ToArray(); IField[] fields1_2 = rel1_2.Column().ToArray(); IField[] fields2_1 = rel2_1.Column().ToArray(); fields1_1.ShouldBe(fields1_2); fields1_1.ShouldNotBe(fields2_1); fields1_1.Select(f => f.Identity).ShouldBe(fields2_1.Select(f => f.Identity)); }
public void Test_Reading_OfDeepObjectGraphFromDifferentSources() { DeepModel model = new DeepModel() { Sub1 = new DeepModel.SubModel1() { Sub2 = new DeepModel.SubModel2() { Sub3 = new List <DeepModel.SubModel3>() { new DeepModel.SubModel3() { Sub4 = new DeepModel.SubModel4() { Sub5 = new List <DeepModel.SubModel5>() { new DeepModel.SubModel5() { Sub6 = new List <DeepModel.SubModel6>() { new DeepModel.SubModel6() { Value = 1 }, new DeepModel.SubModel6() { Value = 2 }, new DeepModel.SubModel6() { Value = 3 }, }, }, new DeepModel.SubModel5() { Sub6 = new List <DeepModel.SubModel6>() { new DeepModel.SubModel6() { Value = 4 }, new DeepModel.SubModel6() { Value = 5 }, }, }, new DeepModel.SubModel5() { Sub6 = new List <DeepModel.SubModel6>() { new DeepModel.SubModel6() { Value = 6 }, }, } }, }, }, new DeepModel.SubModel3() { Sub4 = new DeepModel.SubModel4() { Sub5 = new List <DeepModel.SubModel5>() { new DeepModel.SubModel5() { Sub6 = new List <DeepModel.SubModel6>() { new DeepModel.SubModel6() { Value = 7 }, new DeepModel.SubModel6() { Value = 8 }, null, }, }, new DeepModel.SubModel5() { Sub6 = new List <DeepModel.SubModel6>() { new DeepModel.SubModel6() { Value = 9 }, }, }, }, }, }, new DeepModel.SubModel3() { Sub4 = new DeepModel.SubModel4() { Sub5 = new List <DeepModel.SubModel5>(), }, }, }, }, }, }; string valueAttr = "Sub1.Sub2.Sub3.Item.Sub4.Sub5.Item.Sub6.Item.Value"; Relation rel1 = DatabaseHelper.Default.Relation(model, valueAttr); Relation rel2 = new Relation(new Relation(rel1, "Sub1").Scalar(), valueAttr); Relation rel3 = new Relation(new Relation(rel2, "Sub1.Sub2").Scalar(), valueAttr); Relation rel4 = new Relation(new Relation(rel3, "Sub1.Sub2.Sub3").Scalar(), valueAttr); Relation rel5 = new Relation(new Relation(rel4, "Sub1.Sub2.Sub3.Item").Scalar(), valueAttr); Relation rel6 = new Relation(new Relation(rel5, "Sub1.Sub2.Sub3.Item.Sub4").Scalar(), valueAttr); Relation rel7 = new Relation(new Relation(rel6, "Sub1.Sub2.Sub3.Item.Sub4.Sub5").Scalar(), valueAttr); Relation rel8 = new Relation(new Relation(rel7, "Sub1.Sub2.Sub3.Item.Sub4.Sub5.Item").Scalar(), valueAttr); Relation rel9 = new Relation(new Relation(rel8, "Sub1.Sub2.Sub3.Item.Sub4.Sub5.Item.Sub6").Scalar(), valueAttr); Relation rel10 = new Relation(new Relation(rel9, "Sub1.Sub2.Sub3.Item.Sub4.Sub5.Item.Sub6.Item").Scalar(), valueAttr); Relation rel11 = new Relation(new Relation(rel10, "Sub1.Sub2.Sub3.Item.Sub4.Sub5.Item.Sub6.Item.Value").Scalar(), valueAttr); rel1.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1, 2, 3, 4, 5, 6, 7, 8, null, 9 }); rel2.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1, 2, 3, 4, 5, 6, 7, 8, null, 9 }); rel3.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1, 2, 3, 4, 5, 6, 7, 8, null, 9 }); rel4.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1, 2, 3, 4, 5, 6, 7, 8, null, 9 }); rel5.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1, 2, 3, 4, 5, 6 }); rel6.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1, 2, 3, 4, 5, 6 }); rel7.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1, 2, 3, 4, 5, 6 }); rel8.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1, 2, 3 }); rel9.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1, 2, 3 }); rel10.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1 }); rel11.Column().Select(f => (int?)f.Value).ShouldBe(new int?[] { 1 }); }