public void ValueSetUnitWhenUnmodifiedVariableUnitsIsFalse() { EAVModelLibrary.ModelValue aValue = new EAVModelLibrary.ModelValue() { Instance = new EAVModelLibrary.ModelRootInstance() { InstanceID = rng.Next() }, Attribute = new EAVModelLibrary.ModelAttribute() { AttributeID = rng.Next(), VariableUnits = false } }; Assert.AreEqual(EAV.Model.ObjectState.New, aValue.ObjectState, "Object state should be 'New' on creation."); aValue.Instance.MarkUnmodified(); aValue.Attribute.MarkUnmodified(); aValue.MarkUnmodified(); Assert.AreEqual(EAV.Model.ObjectState.Unmodified, aValue.ObjectState, "Object state failed to transition to 'Unmodified'."); EAVModelLibrary.ModelUnit aUnit = new EAVModelLibrary.ModelUnit() { UnitID = rng.Next() }; aValue.Unit = aUnit; Assert.AreEqual(aUnit, aValue.Unit, "Property 'Units' was not set properly."); Assert.AreEqual(aUnit.UnitID, aValue.UnitID, "Property 'UnitID' was not reported properly."); Assert.AreEqual(EAV.Model.ObjectState.Modified, aValue.ObjectState, "Object state failed to transition to 'Modified'."); Assert.AreEqual(EAV.Model.ObjectState.New, aUnit.ObjectState, String.Format("Object state for Unit object incorrectly transitioned to '{0}' when 'Unit' property set.", aUnit.ObjectState)); }
public void ValueSetUnitWhenNewWithNewUnit() { 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.ModelUnit aUnit = new EAVModelLibrary.ModelUnit() { UnitID = rng.Next() }; aValue.Unit = aUnit; Assert.AreEqual(aUnit, aValue.Unit, "Property 'Units' was not set properly."); Assert.AreEqual(aUnit.UnitID, aValue.UnitID, "Property 'UnitID' was not reported properly."); Assert.AreEqual(EAV.Model.ObjectState.New, aValue.ObjectState, "Object state should remain 'New' when property set."); Assert.AreEqual(EAV.Model.ObjectState.New, aUnit.ObjectState, String.Format("Object state for Unit object incorrectly transitioned to '{0}' when 'Unit' property set.", aUnit.ObjectState)); }
private void SaveValueUnit(EAV.Model.IModelUnit unit) { HttpResponseMessage response; if (unit.ObjectState == EAV.Model.ObjectState.New) { response = client.PostAsJsonAsync <EAV.Store.IStoreUnit>("api/metadata/units", unit).Result; if (response.IsSuccessStatusCode) { EAVModelLibrary.ModelUnit newUnit = response.Content.ReadAsAsync <EAVModelLibrary.ModelUnit>().Result; unit.UnitID = newUnit.UnitID; unit.MarkUnmodified(); } else { throw (new ApplicationException("Attempt to create unit failed.")); } } else if (unit.ObjectState == EAV.Model.ObjectState.Modified) { response = client.PatchAsJsonAsync <EAV.Store.IStoreUnit>("api/metadata/units", unit).Result; if (response.IsSuccessStatusCode) { unit.MarkUnmodified(); } else { throw (new ApplicationException("Attempt to update unit failed.")); } } if (unit.ObjectState == EAV.Model.ObjectState.Deleted) { response = client.DeleteAsync(String.Format("api/metadata/units/{0}", unit.UnitID.GetValueOrDefault())).Result; if (response.IsSuccessStatusCode) { // Nothing to do } else { throw (new ApplicationException("Attempt to delete unit failed.")); } } }
public void ValueSetUnitWhenNewWithDeletedUnit() { 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.ModelUnit aUnit = new EAVModelLibrary.ModelUnit() { UnitID = rng.Next() }; aUnit.MarkUnmodified(); Assert.AreEqual(EAV.Model.ObjectState.Unmodified, aUnit.ObjectState, "Object state for 'Unit' object failed to transition to 'Unmodified'."); aUnit.MarkDeleted(); Assert.AreEqual(EAV.Model.ObjectState.Deleted, aUnit.ObjectState, "Object state for 'Unit' object failed to transition to 'Deleted'."); aValue.Unit = aUnit; }