Example #1
0
 /// <summary>
 /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/>
 /// </summary>
 /// <param name="event"></param>
 public void Handle(CustomAttributeUpdatedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
        /// <summary>
        /// Implementation of <see cref="ICustomAttributesCommands.UpdateCustomAttribute(Guid, string, string, string, string, IEnumerable{object})"/>
        /// </summary>
        /// <param name="attributeId">The custom attribute id</param>
        /// <param name="name">The custom attribute name</param>
        /// <param name="type">The custom attribute data type</param>
        /// <param name="description">The custom attribute description</param>
        /// <param name="unitOfMeasure">The custom attribute unit of measure</param>
        /// <param name="values">The custom attribute available values</param>
        /// <returns></returns>
        public async Task UpdateCustomAttribute(Guid attributeId, string name, string type, string description, string unitOfMeasure, IEnumerable <object> values)
        {
            try
            {
                if (attributeId == Guid.Empty)
                {
                    throw new ArgumentException("value cannot be empty", nameof(attributeId));
                }

                var attribute = await Repository.GetByKeyAsync <CustomAttribute>(attributeId);

                if (attribute.Name != name)
                {
                    attribute.ChangeName(name);
                }

                if (attribute.DataType != type)
                {
                    attribute.ChangeDataType(type);
                }

                if (attribute.Description != description)
                {
                    attribute.ChangeDescription(description);
                }

                if (attribute.UnitOfMeasure != unitOfMeasure)
                {
                    attribute.SetUnitOfMeasure(unitOfMeasure);
                }

                UpdateCustomAttributeValues(attribute, values);

                await Repository.SaveChangesAsync();

                var @event = new CustomAttributeUpdatedEvent(attributeId, name, type, description, unitOfMeasure, values);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
        public void CustomAttributeUpdatedEvent_Ctor_Should_Set_Arguments_Correctly()
        {
            Guid   attributeId          = Guid.NewGuid();
            string name                 = "name";
            string type                 = "string";
            string description          = "description";
            string unitOfMeasure        = "unit";
            IEnumerable <object> values = new[] { "v1", "v2" };

            var @event = new CustomAttributeUpdatedEvent(attributeId, name, type, description, unitOfMeasure, values);

            Assert.Equal(attributeId, @event.AttributeId);
            Assert.Equal(name, @event.Name);
            Assert.Equal(type, @event.Type);
            Assert.Equal(description, @event.Description);
            Assert.Equal(unitOfMeasure, @event.UnitOfMeasure);
            Assert.Equal(values, @event.Values);

            Assert.Equal(attributeId, @event.AggregateId);
            Assert.Equal(typeof(Catalog.Models.CustomAttribute), @event.AggregateType);
        }