public void TestDomainService_UpdateMemberToDefaultValue() { TestDomainServices.EF.Catalog service = ServerTestHelper.CreateInitializedDomainService<TestDomainServices.EF.Catalog>(DomainOperationType.Submit); DomainServiceDescription serviceDescription = DomainServiceDescription.GetDescription(service.GetType()); // in the below, non RTO is simulated by leaving ReorderPoint as its default value in the // original instance AdventureWorksModel.Product currProduct = new AdventureWorksModel.Product { ProductID = 1, ReorderPoint = 0, Weight = 0 }; AdventureWorksModel.Product origProduct = new AdventureWorksModel.Product { ProductID = 1, Weight = 50.0M }; // verify expected test state - this test relies on the below attribute values PropertyDescriptor pd = TypeDescriptor.GetProperties(typeof(AdventureWorksModel.Product))["ReorderPoint"]; Assert.IsNull(pd.Attributes[typeof(RoundtripOriginalAttribute)]); pd = TypeDescriptor.GetProperties(typeof(AdventureWorksModel.Product))["Weight"]; Assert.IsNotNull(pd.Attributes[typeof(RoundtripOriginalAttribute)]); pd = TypeDescriptor.GetProperties(typeof(AdventureWorksModel.Product))["SafetyStockLevel"]; Assert.IsNotNull(pd.Attributes[typeof(ExcludeAttribute)]); ObjectContextExtensions.AttachAsModified(service.ObjectContext.Products, currProduct, origProduct); // verify the expected property modifications ObjectStateEntry stateEntry = service.ObjectContext.ObjectStateManager.GetObjectStateEntry(currProduct); string[] modifiedProperties = stateEntry.GetModifiedProperties().ToArray(); Assert.IsTrue(modifiedProperties.Contains("ReorderPoint")); // no RTO so this should be modified Assert.IsTrue(modifiedProperties.Contains("Weight")); // RTO so this is picked up by normal value comparison Assert.IsFalse(modifiedProperties.Contains("SafetyStockLevel")); // excluded member, so shouldn't be marked modified Assert.IsFalse(modifiedProperties.Contains("ProductID")); // key members shouldn't be marked modified }
public void TestDomainService_UpdateMemberToDefaultValue() { TestDomainServices.EF.Catalog service = ServerTestHelper.CreateInitializedDomainService <TestDomainServices.EF.Catalog>(DomainOperationType.Submit); DomainServiceDescription serviceDescription = DomainServiceDescription.GetDescription(service.GetType()); // in the below, non RTO is simulated by leaving ReorderPoint as its default value in the // original instance AdventureWorksModel.Product currProduct = new AdventureWorksModel.Product { ProductID = 1, ReorderPoint = 0, Weight = 0 }; AdventureWorksModel.Product origProduct = new AdventureWorksModel.Product { ProductID = 1, Weight = 50.0M }; // verify expected test state - this test relies on the below attribute values PropertyDescriptor pd = TypeDescriptor.GetProperties(typeof(AdventureWorksModel.Product))["ReorderPoint"]; Assert.IsNull(pd.Attributes[typeof(RoundtripOriginalAttribute)]); pd = TypeDescriptor.GetProperties(typeof(AdventureWorksModel.Product))["Weight"]; Assert.IsNotNull(pd.Attributes[typeof(RoundtripOriginalAttribute)]); pd = TypeDescriptor.GetProperties(typeof(AdventureWorksModel.Product))["SafetyStockLevel"]; Assert.IsNotNull(pd.Attributes[typeof(ExcludeAttribute)]); ObjectContextExtensions.AttachAsModified(service.ObjectContext.Products, currProduct, origProduct); // verify the expected property modifications ObjectStateEntry stateEntry = service.ObjectContext.ObjectStateManager.GetObjectStateEntry(currProduct); string[] modifiedProperties = stateEntry.GetModifiedProperties().ToArray(); Assert.IsTrue(modifiedProperties.Contains("ReorderPoint")); // no RTO so this should be modified Assert.IsTrue(modifiedProperties.Contains("Weight")); // RTO so this is picked up by normal value comparison Assert.IsFalse(modifiedProperties.Contains("SafetyStockLevel")); // excluded member, so shouldn't be marked modified Assert.IsFalse(modifiedProperties.Contains("ProductID")); // key members shouldn't be marked modified }