public void TestValidate_AddressAlreadyExists_ValidationError(
            [Frozen] Mock <IRepository <Entities.Customer> > customerRepoMock,
            Entities.StoreCustomer customer,
            UpdateCustomerAddressCommandValidator sut,
            UpdateCustomerAddressCommand command,
            Entities.CustomerAddress customerAddress
            )
        {
            //Arrange
            customer.AddAddress(customerAddress);

            command.AccountNumber = "1";
            var address = customer.Addresses.ToList()[0];

            command.CustomerAddress.AddressType               = address.AddressType;
            command.CustomerAddress.Address.AddressLine1      = address.Address.AddressLine1;
            command.CustomerAddress.Address.AddressLine2      = address.Address.AddressLine2;
            command.CustomerAddress.Address.PostalCode        = address.Address.PostalCode;
            command.CustomerAddress.Address.City              = address.Address.City;
            command.CustomerAddress.Address.StateProvinceCode = address.Address.StateProvinceCode;
            command.CustomerAddress.Address.CountryRegionCode = address.Address.CountryRegionCode;

            customerRepoMock.Setup(x => x.GetBySpecAsync(
                                       It.IsAny <GetCustomerSpecification>(),
                                       It.IsAny <CancellationToken>()
                                       ))
            .ReturnsAsync(customer);

            //Act
            var result = sut.TestValidate(command);

            //Assert
            result.ShouldHaveValidationErrorFor(command => command)
            .WithErrorMessage("Address must be unique");
        }
示例#2
0
        public IEnumerable <CustomerAddress> SearchCustomerByPhone(string keyword)
        {
            string storeName    = "admin_customer_addres_getbykeyword";
            var    lisCustomers = new List <Entities.CustomerAddress>();

            try
            {
                using (var db = new PostgresSQL(ConnectionEntity.DBPosition.Master))
                {
                    using (var command = db.CreateCommand(storeName, true))
                    {
                        command.Parameters.Add(NpgsqlParameter("@_keyword", keyword));
                        using (var reader = command.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    var obj = new Entities.CustomerAddress();
                                    EntityBase.SetObjectValue(reader, ref obj);
                                    lisCustomers.Add(obj);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("{0} => {1}", storeName, ex.ToString()));
            }
            return(lisCustomers);
        }
        private void OnCustomerAddressBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
        {
            _currentCustomerAddress = uxCustomerAddressBindingSource.Current as Entities.CustomerAddress;

            if (_currentCustomerAddress != null)
            {
                _currentCustomerAddress.Validate();
            }
            //_CustomerAddress.Validate();
            OnCurrentEntityChanged();
        }
		private void OnCustomerAddressBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentCustomerAddress = uxCustomerAddressBindingSource.Current as Entities.CustomerAddress;
			
			if (_currentCustomerAddress != null)
			{
				_currentCustomerAddress.Validate();
			}
			//_CustomerAddress.Validate();
			OnCurrentEntityChanged();
		}