public void DependencyCascade() { // Dependency triggers: // Tax => Categories => Products // First create a Tax object: TaxDto taxDto = new TaxDto() { TaxTitle = Rand.AnyTitle, Rate = 10, }.SetObjectAsReady() as TaxDto; // Category next: CategoryDto categoryDto = new CategoryDto() { CategoryTitle = Rand.AnyTitle, CategoryDesc = Rand.AnyDescription, }.SetObjectAsReady() as CategoryDto; // And also a product: ProductDto productDto = new ProductDto() { ProductTitle = Rand.AnyTitle, BaseCost = 100, //TaxComponent = 0, // Don't bother, it will be overwritten }.SetObjectAsReady() as ProductDto; // Declare dependencies: categoryDto.AddPrincipalDependency(taxDto); productDto.AddPrincipalDependency(categoryDto); taxDto.Rate = 20; // We need to manually update to head version: categoryDto = (CategoryDto)OdCepManager.Versioning.GetHeadVersion(typeof(CategoryDto), categoryDto.Uuid); productDto = (ProductDto)OdCepManager.Versioning.GetHeadVersion(typeof(ProductDto), productDto.Uuid); decimal taxRateInCat = taxDto.Rate; Assert.AreEqual(taxRateInCat, categoryDto.TaxRate, "Category tax rate not as expected."); decimal expectedTaxAmountInProduct = productDto.BaseCost * taxRateInCat / 100; Assert.AreEqual(expectedTaxAmountInProduct, productDto.TaxComponent, "Product tax component not as expected."); taxDto.Rate = 50; categoryDto = (CategoryDto)OdCepManager.Versioning.GetHeadVersion(typeof(CategoryDto), categoryDto.Uuid, out string c); productDto = (ProductDto)OdCepManager.Versioning.GetHeadVersion(typeof(ProductDto), productDto.Uuid, out c); taxRateInCat = taxDto.Rate; Assert.AreEqual(taxRateInCat, categoryDto.TaxRate, "Category tax rate not as expected."); expectedTaxAmountInProduct = productDto.BaseCost * taxRateInCat / 100; Assert.AreEqual(expectedTaxAmountInProduct, productDto.TaxComponent, "Product tax component not as expected."); }
public override ObjectDto OnPrincipalObjectUpdated(ObjectDto updatedPrincipalObj, string optionalArg) { // Do whatever you need to do here to manage this change. // Do NOT attempt to save this object, else it will result in undefined behaviour; just manage // the change in the object and that's it. The library will ensure that the object is auto-saved. // Avoid doing any disk/network io here. if (updatedPrincipalObj is TaxDto) { TaxDto taxDto = updatedPrincipalObj as TaxDto; TaxRate = taxDto.Rate; } return(this); }