Beispiel #1
0
        public void Stratabase_ToFromObject()
        {
            TestDataWithList data = new TestDataWithList
            {
                Name  = "Test #1",
                Value = 20,
            };

            data.ChildList.Add(new TestData
            {
                Name  = "Child",
                Value = 6
            });

            Stratabase sb = new Stratabase(3);

            sb.SetBaselineFromPropertiesOf(data);

            TestDataWithList found = new TestDataWithList();

            sb.SetObjectWithProperties(data.Id, found);

            Assert.AreEqual(data.Name, found.Name);
            Assert.AreEqual(data.Value, found.Value);
            Assert.AreEqual(1, data.ChildList?.Count ?? 0);
            Assert.AreEqual(1, found.ChildList?.Count ?? 0);
            Assert.AreEqual(data.ChildList[0].Name, found.ChildList[0].Name);
            Assert.AreEqual(data.ChildList[0].Value, found.ChildList[0].Value);

            sb.SetOverridePropertyValue(2, data.Id, "Name", "Test #4");

            found = new TestDataWithList();
            sb.SetObjectWithProperties(data.Id, found);
            Assert.AreEqual("Test #4", found.Name);
        }
Beispiel #2
0
        public void Stratabase_SetData_WithLists()
        {
            var data = new TestDataWithList
            {
                Name  = "Bob",
                Value = 2
            };

            data.ChildList.Add(new TestData
            {
                Name  = "Mary",
                Value = 6
            });

            data.ChildList.Add(new TestData
            {
                Name  = "Gillian",
                Value = 8
            });

            Stratabase sb = new Stratabase(1);

            sb.SetBaselineFromPropertiesOf(data.Id, data);

            var name      = sb.GeneratePropertyAccess <string>(data.Id, nameof(TestDataWithList.Name));
            var value     = sb.GeneratePropertyAccess <int>(data.Id, nameof(TestDataWithList.Value));
            var childList = sb.GenerateListPropertyAccess <TestData>(data.Id, nameof(TestDataWithList.ChildList));

            Assert.AreEqual(data.Name, name.GetValue());
            Assert.AreEqual(data.Value, value.GetValue());
            Assert.AreEqual(data.ChildList.Count, childList.GetCount());

            Assert.AreEqual(data.ChildList[0], childList.Elements[0]);
            Assert.AreEqual(data.ChildList[1], childList.Elements[1]);
        }