public void UpdateAttribute(EAV.Store.IStoreAttribute attribute) { using (EAVStoreClient.MicroEAVContext ctx = new MicroEAVContext()) { EAVStoreClient.Attribute dbAttribute = ctx.Attributes.SingleOrDefault(it => it.Attribute_ID == attribute.AttributeID); if (dbAttribute != null) { if (dbAttribute.Name != attribute.Name) { dbAttribute.Name = attribute.Name; } if (dbAttribute.Data_Name != attribute.DataName) { dbAttribute.Data_Name = attribute.DataName; } if (dbAttribute.Display_Text != attribute.DisplayText) { dbAttribute.Display_Text = attribute.DisplayText; } if (dbAttribute.Data_Type.Name != attribute.DataType.ToString()) { dbAttribute.Data_Type = ctx.Data_Type.Single(it => it.Name == attribute.DataType.ToString()); } if (dbAttribute.Sequence != attribute.Sequence) { dbAttribute.Sequence = attribute.Sequence; } if (dbAttribute.Is_Key != attribute.IsKey) { dbAttribute.Is_Key = attribute.IsKey; } if (dbAttribute.Variable_Units != attribute.VariableUnits) { dbAttribute.Variable_Units = attribute.VariableUnits; } ctx.SaveChanges(); } else { throw (new Exception(String.Format("Unable to retrieve attribute ID {0}.", attribute.AttributeID))); } } }
public void DeleteAttribute() { EAV.Store.Clients.IAttributeStoreClient client = factory.Create <EAV.Store.Clients.IAttributeStoreClient>(); EAVStoreClient.Container dbContainer = SelectRandomItem(this.DbContext.Containers); EAVStoreClient.Attribute dbAttributeIn = CreateAttribute(dbContainer.Container_ID, Guid.NewGuid().ToString(), EAV.EAVDataType.String, rng.Next(), true); client.DeleteAttribute(dbAttributeIn.Attribute_ID); using (EAVStoreClient.MicroEAVContext ctx = new EAVStoreClient.MicroEAVContext()) { EAVStoreClient.Attribute dbAttributeOut = ctx.Attributes.SingleOrDefault(it => it.Attribute_ID == dbAttributeIn.Attribute_ID); Assert.IsNull(dbAttributeOut, "Failed to delete attribute ID {0} from the database.", dbAttributeIn.Attribute_ID); } }
public void DeleteAttribute() { var dbContainer = SelectRandomItem(this.DbContext.Containers); EAVStoreClient.Attribute dbAttributeIn = CreateAttribute(dbContainer.Container_ID, Guid.NewGuid().ToString(), EAV.EAVDataType.String, rng.Next(), true); HttpResponseMessage response = WebClient.DeleteAsync(String.Format("api/metadata/attributes/{0}", dbAttributeIn.Attribute_ID)).Result; if (response.IsSuccessStatusCode) { ResetDatabaseContext(); EAVStoreClient.Attribute dbAttributeOut = this.DbContext.Attributes.SingleOrDefault(it => it.Attribute_ID == dbAttributeIn.Attribute_ID); Assert.IsNull(dbAttributeOut, "Failed to delete attribute ID {0} from the database.", dbAttributeIn.Attribute_ID); } else { Assert.Fail(response.Content.ReadAsStringAsync().Result); } }