public void ValueSetAttributeWhenUnmodified() { EAVModelLibrary.ModelValue aValue = new EAVModelLibrary.ModelValue() { Attribute = new EAVModelLibrary.ModelAttribute() { AttributeID = rng.Next() }, Instance = new EAVModelLibrary.ModelChildInstance() { InstanceID = rng.Next() } }; Assert.AreEqual(EAV.Model.ObjectState.New, aValue.ObjectState, "Object state should be 'New' on creation."); aValue.Attribute.MarkUnmodified(); aValue.Instance.MarkUnmodified(); aValue.MarkUnmodified(); Assert.AreEqual(EAV.Model.ObjectState.Unmodified, aValue.ObjectState, "Object state failed to transition to 'Unmodified'."); EAVModelLibrary.ModelAttribute attribute = new EAVModelLibrary.ModelAttribute() { AttributeID = rng.Next() }; aValue.Attribute = attribute; Assert.AreEqual(attribute, aValue.Attribute, "Property 'Attribute' was not set properly."); Assert.AreEqual(attribute.AttributeID, aValue.AttributeID, "Property 'AttributeID' was not reported properly."); Assert.IsTrue(attribute.Values.Contains(aValue), "Property 'Values' was not updated properly."); Assert.AreEqual(EAV.Model.ObjectState.Modified, aValue.ObjectState, "Object state failed to transition to 'Modified'."); }
private void SaveAttribute(EAV.Model.IModelAttribute attribute) { HttpResponseMessage response; if (attribute.ObjectState == EAV.Model.ObjectState.New) { response = client.PostAsJsonAsync <EAV.Store.IStoreAttribute>(String.Format("api/metadata/containers/{0}/attributes", attribute.ContainerID.GetValueOrDefault()), attribute).Result; if (response.IsSuccessStatusCode) { EAVModelLibrary.ModelAttribute newAttribute = response.Content.ReadAsAsync <EAVModelLibrary.ModelAttribute>().Result; attribute.AttributeID = newAttribute.AttributeID; if (!attribute.VariableUnits.GetValueOrDefault(true)) { SaveAttributeUnits(attribute.AttributeID.Value, attribute.Units); } attribute.MarkUnmodified(); } else { throw (new ApplicationException("Attempt to create attribute failed.")); } } else if (attribute.ObjectState == EAV.Model.ObjectState.Modified) { response = client.PatchAsJsonAsync <EAV.Store.IStoreAttribute>("api/metadata/attributes", attribute).Result; if (response.IsSuccessStatusCode) { if (!attribute.VariableUnits.GetValueOrDefault(true)) { SaveAttributeUnits(attribute.AttributeID.Value, attribute.Units); } attribute.MarkUnmodified(); } else { throw (new ApplicationException("Attempt to update attribute failed.")); } } if (attribute.ObjectState == EAV.Model.ObjectState.Deleted) { response = client.DeleteAsync(String.Format("api/metadata/attributes/{0}", attribute.AttributeID.GetValueOrDefault())).Result; if (response.IsSuccessStatusCode) { } else { throw (new ApplicationException("Attempt to delete attribute failed.")); } } }
public void ValueSetAttributeWhenNew() { EAV.Model.IModelValue aValue = factory.Create <EAV.Model.IModelValue>(); Assert.AreEqual(EAV.Model.ObjectState.New, aValue.ObjectState, "Object state should be 'New' on creation."); EAVModelLibrary.ModelAttribute attribute = new EAVModelLibrary.ModelAttribute() { AttributeID = rng.Next() }; aValue.Attribute = attribute; Assert.AreEqual(attribute, aValue.Attribute, "Property 'Attribute' was not set properly."); Assert.AreEqual(attribute.AttributeID, aValue.AttributeID, "Property 'AttributeID' was not reported properly."); Assert.IsTrue(attribute.Values.Contains(aValue), "Property 'Values' was not updated properly."); Assert.AreEqual(EAV.Model.ObjectState.New, aValue.ObjectState, "Object state should remain 'New' when property set."); }