/// <summary>
 /// <see cref="IHandleEvent{TEvent}.Handle(TEvent)"/>
 /// </summary>
 /// <param name="event"></param>
 public void Handle(CustomerAccountSetEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
        public void ToString_Should_Return_Event_Formatted_As_String()
        {
            Guid   customerId = Guid.NewGuid();
            string userName   = "******";

            var ev = new CustomerAccountSetEvent(customerId, userName);

            string eventAsString = $"Account {userName} set for customer {customerId}";

            Assert.Equal(eventAsString, ev.ToString());
        }
        public void Ctor_Should_Set_All_Values_Correctly()
        {
            Guid   customerId = Guid.NewGuid();
            string userName   = "******";

            var ev = new CustomerAccountSetEvent(customerId, userName);

            Assert.Equal(customerId, ev.CustomerId);
            Assert.Equal(userName, ev.UserName);
            Assert.Equal(customerId, ev.AggregateId);
            Assert.Equal(typeof(Registries.Models.Customer), ev.AggregateType);
        }
Beispiel #4
0
        /// <summary>
        /// Implementation of <see cref="ICustomerCommands.SetCustomerAccount(Guid, string, string)"/>
        /// </summary>
        /// <param name="customerId">The customer id</param>
        /// <param name="userName">The username</param>
        /// <param name="password">The password</param>
        /// <returns></returns>
        public async Task SetCustomerAccount(Guid customerId, string userName, string password)
        {
            if (customerId == Guid.Empty)
            {
                throw new ArgumentException("value cannot be empty", nameof(customerId));
            }

            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentException("value cannot be empty", nameof(userName));
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("value cannot be empty", nameof(password));
            }

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

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

            try
            {
                var userId = await AuthClient.FindOrRegisterAccount(userName, password);

                customer.SetAccount(userId, userName);

                await Repository.SaveChangesAsync();

                var @event = new CustomerAccountSetEvent(customerId, userName);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }