Пример #1
0
        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."));
            }
        }
Пример #2
0
        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."));
            }
        }
Пример #3
0
        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();
        }
Пример #4
0
        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();
        }
Пример #5
0
        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'.");
        }
Пример #6
0
        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.");
        }
Пример #7
0
        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'.");
        }
Пример #8
0
        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.");
        }
Пример #9
0
        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() };
        }
Пример #10
0
        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.");
        }
Пример #11
0
        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'.");
        }
Пример #12
0
        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."));
                }
            }
        }
Пример #13
0
        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."));
            }
        }
Пример #14
0
        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);
        }