Esempio n. 1
0
        /// <summary>
        /// Implementation of <see cref="ICustomerCommands.RestoreCustomer(Guid)"/>
        /// </summary>
        /// <param name="customerId">The customer id</param>
        /// <returns></returns>
        public async Task RestoreCustomer(Guid customerId)
        {
            if (customerId == Guid.Empty)
            {
                throw new ArgumentException("value cannot be empty", nameof(customerId));
            }

            var customer = await Repository.GetByKeyAsync <Customer>(customerId);

            if (customer == null)
            {
                throw new ArgumentOutOfRangeException(nameof(customerId));
            }

            try
            {
                customer.Restore();
                if (customer.HasAccount && customer.Account.IsLocked)
                {
                    await AuthClient.EnableAccount(customer.Account.UserId);

                    customer.UnlockAccount();
                }

                await Repository.SaveChangesAsync();

                var @event = new CustomerRestoredEvent(customerId);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
        public void Ctor_Should_Set_All_Values_Correctly()
        {
            var customerId = Guid.NewGuid();
            var ev         = new CustomerRestoredEvent(customerId);

            Assert.Equal(customerId, ev.CustomerId);
            Assert.Equal(customerId, ev.AggregateId);
            Assert.Equal(typeof(Registries.Models.Customer), ev.AggregateType);
        }
        public void ToString_Should_Return_Event_Formatted_As_String()
        {
            var customerId = Guid.NewGuid();
            var ev         = new CustomerRestoredEvent(customerId);

            string eventAsString = $"Customer {customerId} restored";

            Assert.Equal(eventAsString, ev.ToString());
        }
 /// <summary>
 /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/>
 /// </summary>
 /// <param name="event"></param>
 public void Handle(CustomerRestoredEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }