public void SubjectClearInstancesWhenModified() { ModelSubject aSubject = new EAVModelLibrary.ModelSubject() { SubjectID = rng.Next() }; Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should be 'New' on creation."); aSubject.MarkUnmodified(); Assert.AreEqual(EAV.Model.ObjectState.Unmodified, aSubject.ObjectState, "Object state failed to transition to 'Unmodified'."); ModelRootInstance value = new EAVModelLibrary.ModelRootInstance() { InstanceID = rng.Next() }; aSubject.Instances.Add(value); value = new EAVModelLibrary.ModelRootInstance() { InstanceID = rng.Next() }; aSubject.Instances.Add(value); Assert.IsTrue(aSubject.Instances.Contains(value), "Property 'Instances' was not updated properly."); Assert.AreEqual(aSubject, value.Subject, "Property 'Subject' was not set properly."); Assert.AreEqual(aSubject.SubjectID, value.SubjectID, "Property 'SubjectID' was not set properly."); Assert.AreEqual(EAV.Model.ObjectState.Modified, aSubject.ObjectState, "Object state failed to transition to 'Modified'."); aSubject.Instances.Clear(); Assert.IsFalse(aSubject.Instances.Contains(value), "Property 'Instances' was not updated properly."); Assert.IsNull(value.Subject, "Property 'Subject' was not set properly."); Assert.IsNull(value.SubjectID, "Property 'SubjectID' was not set properly."); Assert.IsFalse(aSubject.Instances.Any(), "Property 'Instances' was not updated properly."); Assert.AreEqual(EAV.Model.ObjectState.Modified, aSubject.ObjectState, "Object state should remain 'Modified' when property set."); }
public void SubjectAddToInstancesWhenNew() { ModelSubject aSubject = new EAVModelLibrary.ModelSubject() { SubjectID = rng.Next() }; Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should be 'New' on creation."); ModelRootInstance value = new EAVModelLibrary.ModelRootInstance() { InstanceID = rng.Next() }; aSubject.Instances.Add(value); Assert.IsTrue(aSubject.Instances.Contains(value), "Property 'Instances' was not updated properly."); Assert.AreEqual(aSubject, value.Subject, "Property 'Subject' was not set properly."); Assert.AreEqual(aSubject.SubjectID, value.SubjectID, "Property 'SubjectID' was not set properly."); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should remain 'New' when property set."); }
public static EAV.Model.IModelRootInstance Create(EAV.Model.IModelRootContainer container, EAV.Model.IModelSubject subject) { ModelRootInstance instance = new ModelRootInstance() { Container = container, Subject = subject, }; foreach (ModelAttribute attribute in container.Attributes) { ModelValue.Create(attribute, instance); } foreach (ModelChildContainer childContainer in container.ChildContainers) { ModelChildInstance.Create(childContainer, subject, instance); } return(instance); }
public void SubjectClearInstancesWhenDeleted() { ModelSubject aSubject = new EAVModelLibrary.ModelSubject() { SubjectID = rng.Next() }; Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should be 'New' on creation."); ModelRootInstance value = new EAVModelLibrary.ModelRootInstance() { InstanceID = rng.Next() }; aSubject.Instances.Add(value); aSubject.MarkUnmodified(); value.MarkUnmodified(); Assert.AreEqual(EAV.Model.ObjectState.Unmodified, aSubject.ObjectState, "Object state failed to transition to 'Unmodified'."); Assert.AreEqual(EAV.Model.ObjectState.Unmodified, value.ObjectState, "Object state failed to transition to 'Unmodified'."); aSubject.MarkDeleted(); Assert.AreEqual(EAV.Model.ObjectState.Deleted, aSubject.ObjectState, "Object state failed to transition to 'Deleted'."); Assert.AreEqual(EAV.Model.ObjectState.Deleted, value.ObjectState, "Object state failed to transition to 'Deleted'."); aSubject.Instances.Clear(); }