Esempio n. 1
0
        public static PathBuildingTestClassWithPrivatePropertiesAndFields CreateWithPrivateFields(int price, int quantity)
        {
            var obj = new PathBuildingTestClassWithPrivatePropertiesAndFields
            {
                _priceField    = price,
                _quantityField = quantity
            };

            return(obj);
        }
Esempio n. 2
0
        public void AddDependency_PrivateFieldsInDependencyPath_Supported()
        {
            var random           = new Random();
            var expectedPrice    = random.Next(1, 100);
            var expectedQuantity = random.Next(100, 200);
            var expectedCost     = expectedPrice * expectedQuantity;

            var mapItems = PathBuildingTestClassWithPrivatePropertiesAndFields.FieldsDependenciesMap.MapItems;

            Assert.Equal(2, mapItems.Count);

            var priceFieldPathItemWithRoot    = mapItems.Single(mi => mi.PathStrings.Skip(1).Single() == "_priceField");
            var quantityFieldPathItemWithRoot = mapItems.Single(mi => mi.PathStrings.Skip(1).Single() == "_quantityField");

            var priceFieldPathItem    = priceFieldPathItemWithRoot.Ancestor;
            var quantityFieldPathItem = quantityFieldPathItemWithRoot.Ancestor;

            Assert.Equal("root", priceFieldPathItemWithRoot.PathStrings.First());
            Assert.Equal("root", quantityFieldPathItemWithRoot.PathStrings.First());

            //Test compiled getters

            var obj = PathBuildingTestClassWithPrivatePropertiesAndFields.CreateWithPrivateFields(expectedPrice, expectedQuantity);

            var actualPrice    = (int)((PropertyPathItem <PathBuildingTestClassWithPrivatePropertiesAndFields>)priceFieldPathItem).PropertyOrFieldGetter(obj);
            var actualQuantity = (int)((PropertyPathItem <PathBuildingTestClassWithPrivatePropertiesAndFields>)quantityFieldPathItem).PropertyOrFieldGetter(obj);

            Assert.Equal(expectedPrice, actualPrice);
            Assert.Equal(expectedQuantity, actualQuantity);

            //Test compiled setter
            Assert.Equal(0, obj.GetCostField());

            priceFieldPathItem.UpdateDependentPropertyOrFieldAction(obj);

            Assert.Equal(expectedCost, obj.GetCostField());

            obj = PathBuildingTestClassWithPrivatePropertiesAndFields.CreateWithPrivateFields(expectedPrice, expectedQuantity);

            Assert.Equal(0, obj.GetCostField());

            quantityFieldPathItem.UpdateDependentPropertyOrFieldAction(obj);

            Assert.Equal(expectedCost, obj.GetCostField());
        }