/// <summary> /// Implementation of <see cref="ICustomAttributesCommands.CreateNewCustomAttribute(string, string, string, string, IEnumerable{object})"/> /// </summary> /// <param name="name">The custom attribute's name</param> /// <param name="type">The data type of the custom attribute</param> /// <param name="description">The custom attribute's description</param> /// <param name="unitOfMeasure">The unit of measure of the custom attribute</param> /// <param name="values">The available values for the custom attribute</param> /// <returns>The custom attribute id</returns> public async Task <Guid> CreateNewCustomAttribute(string name, string type, string description, string unitOfMeasure, IEnumerable <object> values) { try { var attribute = CustomAttribute.Create(name, type); if (!string.IsNullOrWhiteSpace(description)) { attribute.ChangeDescription(description); } if (!string.IsNullOrWhiteSpace(unitOfMeasure)) { attribute.SetUnitOfMeasure(unitOfMeasure); } if (values != null && values.Count() > 0) { values.ToList().ForEach(v => attribute.AddValue(v)); } Repository.Add(attribute); await Repository.SaveChangesAsync(); var @event = new CustomAttributeCreatedEvent(attribute.Id, attribute.Name, attribute.DataType); EventBus.RaiseEvent(@event); return(attribute.Id); } catch { throw; } }
public void CustomAttributeCreatedEvent_Ctor_Should_Set_Arguments_Correctly() { Guid attributeId = Guid.NewGuid(); string name = "attribute"; string type = "string"; var @event = new CustomAttributeCreatedEvent(attributeId, name, type); Assert.Equal(attributeId, @event.AttributeId); Assert.Equal(name, @event.Name); Assert.Equal(type, @event.Type); Assert.Equal(attributeId, @event.AggregateId); Assert.Equal(typeof(Catalog.Models.CustomAttribute), @event.AggregateType); }