private void LoadSubjectContext(EAV.Model.IModelSubject subject) { bool subjectWasUnmodified = subject.ObjectState == EAV.Model.ObjectState.Unmodified; HttpResponseMessage response = client.GetAsync(String.Format("api/metadata/contexts/{0}", subject.ContextID)).Result; if (response.IsSuccessStatusCode) { var context = response.Content.ReadAsAsync <EAVModelLibrary.ModelContext>().Result; context.MarkUnmodified(); subject.Context = context; context.MarkUnmodified(); if (subjectWasUnmodified) { subject.MarkUnmodified(); } } else { throw (new ApplicationException("Attempt to get subject context failed.")); } }
private void LoadSubjectEntity(EAV.Model.IModelSubject subject) { bool subjectWasUnmodified = subject.ObjectState == EAV.Model.ObjectState.Unmodified; HttpResponseMessage response = client.GetAsync(String.Format("api/entities/{0}", subject.EntityID)).Result; if (response.IsSuccessStatusCode) { var entity = response.Content.ReadAsAsync <EAVModelLibrary.ModelEntity>().Result; entity.MarkUnmodified(); subject.Entity = entity; entity.MarkUnmodified(); if (subjectWasUnmodified) { subject.MarkUnmodified(); } } else { throw (new ApplicationException("Attempt to get subject entity failed.")); } }
public void SubjectSetIDAfterUnmodified() { EAV.Model.IModelSubject aSubject = factory.Create<EAV.Model.IModelSubject>(); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should be 'New' on creation."); aSubject.MarkUnmodified(); }
public void SubjectStateTransitionNewToDeleted() { EAV.Model.IModelSubject aSubject = factory.Create<EAV.Model.IModelSubject>(); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should be 'New' on creation."); aSubject.MarkDeleted(); }
public void SubjectStateTransitionNewToUnmodifiedWithNullID() { EAV.Model.IModelSubject aSubject = factory.Create<EAV.Model.IModelSubject>(); 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'."); }
public void SubjectSetIdentifierWhenNew() { EAV.Model.IModelSubject aSubject = factory.Create<EAV.Model.IModelSubject>(); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should be 'New' on creation."); string value = Guid.NewGuid().ToString(); aSubject.Identifier = value; Assert.AreEqual(value, aSubject.Identifier, "Property 'Identifier' was not set properly."); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should remain 'New' when property set."); }
public void SubjectSetIDWhenNew() { EAV.Model.IModelSubject aSubject = factory.Create<EAV.Model.IModelSubject>(); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should be 'New' on creation."); int id = rng.Next(); aSubject.SubjectID = id; Assert.AreEqual(id, aSubject.SubjectID, "Property 'SubjectID' not properly set."); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state after setting property 'SubjectID' should be 'New'."); }
public void SubjectSetContextWhenNew() { EAV.Model.IModelSubject aSubject = factory.Create<EAV.Model.IModelSubject>(); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should be 'New' on creation."); ModelContext value = new EAVModelLibrary.ModelContext() { ContextID = rng.Next() }; aSubject.Context = value; Assert.AreEqual(value, aSubject.Context, "Property 'Context' was not set properly."); Assert.AreEqual(value.ContextID, aSubject.ContextID, "Property 'ContextID' was not reported properly."); Assert.IsTrue(value.Subjects.Contains(aSubject), "Property 'Subjects' was not updated properly."); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should remain 'New' when property set."); }
public void SubjectSetContextWhenDeleted() { EAV.Model.IModelSubject aSubject = factory.Create<EAV.Model.IModelSubject>(); 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'."); aSubject.MarkDeleted(); Assert.AreEqual(EAV.Model.ObjectState.Deleted, aSubject.ObjectState, "Object state failed to transition to 'Deleted'."); aSubject.Context = new EAVModelLibrary.ModelContext() { ContextID = rng.Next() }; }
public void SubjectCreate() { EAV.Model.IModelSubject aSubject = factory.Create<EAV.Model.IModelSubject>(); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should be 'New' on creation."); Assert.IsNull(aSubject.SubjectID, "Property 'SubjectID' should be null on creation."); Assert.IsNull(aSubject.Identifier, "Property 'Identifier' should be null on creation."); Assert.IsNull(aSubject.Entity, "Property 'Entity' should be null on creation."); Assert.IsNull(aSubject.Context, "Property 'Context' should be null on creation."); Assert.IsNotNull(aSubject.Instances, "Property 'Instances' should not be null on creation."); Assert.IsFalse(aSubject.Instances.Any(), "Property 'Instances' should be empty on creation."); }
public void SubjectSetIDBeforeUnmodified() { EAV.Model.IModelSubject aSubject = factory.Create<EAV.Model.IModelSubject>(); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state should be 'New' on creation."); int id = rng.Next(); aSubject.SubjectID = id; Assert.AreEqual(id, aSubject.SubjectID, "Property 'SubjectID' not properly set."); Assert.AreEqual(EAV.Model.ObjectState.New, aSubject.ObjectState, "Object state after setting property 'SubjectID' should be 'New'."); aSubject.MarkUnmodified(); Assert.AreEqual(EAV.Model.ObjectState.Unmodified, aSubject.ObjectState, "Object state failed to transition to 'Unmodified'."); }
public void SaveSubject(EAV.Model.IModelSubject subject) { HttpResponseMessage response; if (subject.ObjectState == EAV.Model.ObjectState.New) { response = client.PostAsJsonAsync <EAV.Store.IStoreSubject>(String.Format("api/metadata/subjects"), subject).Result; if (response.IsSuccessStatusCode) { EAVModelLibrary.ModelSubject newSubject = response.Content.ReadAsAsync <EAVModelLibrary.ModelSubject>().Result; subject.SubjectID = newSubject.SubjectID; subject.MarkUnmodified(); } else { throw (new ApplicationException("Attempt to create subject failed.")); } } else if (subject.ObjectState == EAV.Model.ObjectState.Modified) { response = client.PatchAsJsonAsync <EAV.Store.IStoreSubject>("api/metadata/subjects", subject).Result; if (response.IsSuccessStatusCode) { subject.MarkUnmodified(); } else { throw (new ApplicationException("Attempt to update subject failed.")); } } if (subject.ObjectState == EAV.Model.ObjectState.Deleted) { response = client.DeleteAsync(String.Format("api/metadata/subjects/{0}", subject.SubjectID.GetValueOrDefault())).Result; if (response.IsSuccessStatusCode) { } else { throw (new ApplicationException("Attempt to delete subject failed.")); } } }
public void LoadRootInstances(EAV.Model.IModelSubject subject, EAV.Model.IModelRootContainer container) { bool subjectWasUnmodified = subject.ObjectState == EAV.Model.ObjectState.Unmodified; bool containerWasUnmodified = container.ObjectState == EAV.Model.ObjectState.Unmodified; HttpResponseMessage response = client.GetAsync(String.Format("api/data/subjects/{0}/instances?container={1}", subject.SubjectID.GetValueOrDefault(), container != null ? container.ContainerID : null)).Result; if (response.IsSuccessStatusCode) { subject.Instances.Clear(); var rootInstances = response.Content.ReadAsAsync <IEnumerable <EAVModelLibrary.ModelRootInstance> >().Result; foreach (EAVModelLibrary.ModelRootInstance rootInstance in rootInstances) { rootInstance.MarkUnmodified(); rootInstance.Container = container; if (container.Attributes.Any()) { LoadValues(rootInstance, container.Attributes); } subject.Instances.Add(rootInstance); rootInstance.MarkUnmodified(); } if (containerWasUnmodified) { container.MarkUnmodified(); } if (subjectWasUnmodified) { subject.MarkUnmodified(); } } else { throw (new ApplicationException("Attempt to get root instances failed.")); } }
public static EAV.Model.IModelChildInstance Create(EAV.Model.IModelChildContainer container, EAV.Model.IModelSubject subject, EAV.Model.IModelInstance parentInstance) { ModelChildInstance instance = new ModelChildInstance() { ParentInstance = parentInstance, Container = container, }; foreach (ModelAttribute attribute in container.Attributes) { ModelValue.Create(attribute, instance); } foreach (ModelChildContainer childContainer in container.ChildContainers) { ModelChildInstance.Create(childContainer, subject, instance); } return(instance); }