public void Entity_ReadOnlyPropertyValidation() { ConfigurableEntityContainer ec = new ConfigurableEntityContainer(); ec.CreateSet <City>(EntitySetOperations.Add); ec.CreateSet <County>(EntitySetOperations.All); EntitySet <City> set = ec.GetEntitySet <City>(); City city = new City { Name = "Toledo", CountyName = "Lucas", StateName = "OH" }; InvalidOperationException expectedException = null; try { city.CalculatedCounty = "x"; } catch (InvalidOperationException e) { expectedException = e; } Assert.IsNotNull(expectedException); Assert.AreEqual(string.Format(Resource.Property_Is_ReadOnly, "CalculatedCounty"), expectedException.Message); }
public void Entity_RejectChanges_ParentAssociationRestored() { bool loaded = false; List <Employee> employeeList = new List <Employee>(); ConfigurableEntityContainer container = new ConfigurableEntityContainer(); container.CreateSet <Employee>(EntitySetOperations.All); ConfigurableDomainContext catalog = new ConfigurableDomainContext(new WebDomainClient <TestDomainServices.LTS.Catalog.ICatalogContract>(TestURIs.LTS_Catalog), container); Action <LoadOperation <Employee> > action = (lo) => { if (lo.HasError) { lo.MarkErrorAsHandled(); } loaded = true; }; catalog.Load(catalog.GetEntityQuery <Employee>("GetEmployees"), action, null); this.EnqueueConditional(() => loaded); this.EnqueueCallback(() => { Employee parent, child; parent = container.GetEntitySet <Employee>().OrderByDescending(e => e.Reports.Count).First(); while (parent != null) { // Track parent, get a report from it employeeList.Add(parent); child = parent.Reports.OrderByDescending(e => e.Reports.Count).FirstOrDefault(); // Track child if (child == null) { break; } // Remove child and continue parent.Reports.Remove(child); parent = child; } // By rejecting changes, our parent<=>child relationships should be restored. catalog.RejectChanges(); // Unwind, walking up management chain foreach (Employee employee in employeeList.Reverse <Employee>()) { Assert.AreSame(parent, employee, "Expected parent relationship to be restored."); parent = employee.Manager; Assert.IsTrue(parent.Reports.Contains(employee), "Expected child relationship to be restored."); } }); this.EnqueueTestComplete(); }
public void Entity_RaiseDataMemberChanged() { MockEntity_RaisePropertyChangedEvents entity = new MockEntity_RaisePropertyChangedEvents(); entity.StartTracking(); ConfigurableEntityContainer container = new ConfigurableEntityContainer(); container.CreateSet <MockEntity_RaisePropertyChangedEvents>(EntitySetOperations.All); container.GetEntitySet <MockEntity_RaisePropertyChangedEvents>().Add(entity); List <string> propertyChanges = new List <string>(); entity.PropertyChanged += (s, a) => propertyChanges.Add(a.PropertyName); // Real property, should have no errors entity.Mock_RaiseDataMemberChanging("Property1"); entity.Mock_RaiseDataMemberChanged("Property1"); entity.Mock_RaiseDataMemberChanged("Property1"); // Called twice to ensure we go through the Entity::PropertyHasChanged code path Assert.AreEqual(2, propertyChanges.Count(p => p == "Property1")); }
public void Entity_RaiseDataMemberChanged_NonChangeTrackedProperty() { MockEntity_RaisePropertyChangedEvents entity = new MockEntity_RaisePropertyChangedEvents(); entity.StartTracking(); ConfigurableEntityContainer container = new ConfigurableEntityContainer(); container.CreateSet <MockEntity_RaisePropertyChangedEvents>(EntitySetOperations.All); container.GetEntitySet <MockEntity_RaisePropertyChangedEvents>().Add(entity); List <string> propertyChanges = new List <string>(); entity.PropertyChanged += (s, a) => propertyChanges.Add(a.PropertyName); // Non-existent property - we don't do any validation internally // for this. The methods are protected, so we don't attempt to protect // the user from lying to themselves. entity.Mock_RaiseDataMemberChanging("CalculatedProperty1"); entity.Mock_RaiseDataMemberChanged("CalculatedProperty1"); entity.Mock_RaiseDataMemberChanged("CalculatedProperty1"); Assert.AreEqual(2, propertyChanges.Count(p => p == "CalculatedProperty1")); }
public void Entity_IsReadOnly() { ConfigurableEntityContainer ec = new ConfigurableEntityContainer(); ec.CreateSet <City>(EntitySetOperations.Add); ec.CreateSet <County>(EntitySetOperations.All); EntitySet <City> set = ec.GetEntitySet <City>(); // a new unattached city isn't read only City city = new City { Name = "Toledo", CountyName = "Lucas", StateName = "OH" }; Assert.IsFalse(city.IsReadOnly); // when new and attached, the entity is still not read only set.Add(city); Assert.IsFalse(city.IsReadOnly); // if the entity is being submitted, the entity should be readonly city.IsSubmitting = true; Assert.IsTrue(city.IsReadOnly); city.IsSubmitting = false; Assert.IsFalse(city.IsReadOnly); // if a custom method is being invoked, the entity should be readonly city.AutoAssignCityZone(); Assert.IsTrue(city.IsReadOnly); city.UndoAction(city.EntityActions.First()); Assert.IsFalse(city.IsReadOnly); // if a custom method is being invoked but validation errors are present, the entity should not be readonly city.AutoAssignCityZone(); city.ValidationResultCollection.ReplaceErrors(new ValidationResult[] { new ValidationResult(string.Empty) }); Assert.IsFalse(city.IsReadOnly); city.UndoAction(city.EntityActions.First()); city.ValidationErrors.Clear(); Assert.IsFalse(city.IsReadOnly); // if a custom method is being invoked but errors are present, the entity should not be readonly city.AutoAssignCityZone(); city.ValidationResultCollection.ReplaceErrors(new ValidationResult[] { new ValidationResult(string.Empty) }); Assert.IsFalse(city.IsReadOnly); city.UndoAction(city.EntityActions.First()); city.ValidationErrors.Clear(); Assert.IsFalse(city.IsReadOnly); // if a custom method is being invoked but conflicts are present, the entity should not be readonly city.AutoAssignCityZone(); city.EntityConflict = new EntityConflict(city, null, null, true); Assert.IsFalse(city.IsReadOnly); city.UndoAction(city.EntityActions.First()); city.EntityConflict = null; Assert.IsFalse(city.IsReadOnly); // after attaching as unmodified, the entity is readonly // since the set was configured as readonly set.Clear(); set.Attach(city); Assert.IsTrue(city.IsReadOnly); }