コード例 #1
0
        public void TestAddessIsEmptyReturnsFalseWhenNotEmpty()
        {
            var customerWithAddress = new Customer();

            customerWithAddress.AddAddress(new Address());
            Assert.IsFalse(customerWithAddress.AddressesIsEmpty());
        }
コード例 #2
0
        public void Value()
        {
            _newCustomer = null;
            var line = _stream.ReadLine();

            while (line != null)
            {
                // 1: Extract variable, reemplazando dos ocurrencias
                _record = line.Split(',');
                if (line.StartsWith("C"))
                {
                    // 2: Inline de customerData
                    // 3: Extract method, pero antes Introduce Field de record y newCustomer para
                    // no tener que estar pasandolo como parametro
                    ImportCustomer();
                }
                else if (line.StartsWith("A"))
                {
                    // 2: Inline de addressData
                    var newAddress = new Address();

                    _newCustomer.AddAddress(newAddress);
                    newAddress.StreetName   = _record[1];
                    newAddress.StreetNumber = Int32.Parse(_record[2]);
                    newAddress.Town         = _record[3];
                    newAddress.ZipCode      = Int32.Parse(_record[4]);
                    newAddress.Province     = _record[5];
                }

                line = _stream.ReadLine();
            }
        }
コード例 #3
0
        private static void addAddressToCostumer()
        {
            var newAddress = new Address();

            _newCustomer.AddAddress(newAddress);
            newAddress.StreetName   = _lineData[1];
            newAddress.StreetNumber = Int32.Parse(_lineData[2]);
            newAddress.Town         = _lineData[3];
            newAddress.ZipCode      = Int32.Parse(_lineData[4]);
            newAddress.Province     = _lineData[5];
        }
コード例 #4
0
        private void ImportAddress()
        {
            // 2: Inline de addressData
            var newAddress = new Address();
            // 4: hmm bad smell, escribir test!
            // 5: Hacer pasar el test
            if (_newCustomer == null) throw new Exception(CustomerNotDefined);

            _newCustomer.AddAddress(newAddress);
            newAddress.StreetName = _record[1];
            newAddress.StreetNumber = Int32.Parse(_record[2]);
            newAddress.Town = _record[3];
            newAddress.ZipCode = Int32.Parse(_record[4]);
            newAddress.Province = _record[5];
        }
コード例 #5
0
        private void ImportAddress()
        {
            if (_newCustomer == null)
            {
                throw new Exception(CustomerNotDefined);
            }
            var newAddress = new Address();

            // Test para registro de menos de 6 campos y mas de 6 campos
            _newCustomer.AddAddress(newAddress);
            newAddress.StreetName   = _record[1];
            newAddress.StreetNumber = Int32.Parse(_record[2]);
            newAddress.Town         = _record[3];
            newAddress.ZipCode      = Int32.Parse(_record[4]);
            newAddress.Province     = _record[5];
        }
コード例 #6
0
        private void ImportAddress()
        {
            _ = _newCustomer ?? throw new ArgumentException(CUSTOMER_IS_NULL_EXCEPTION);
            if (_currentRecord.Length != 6)
            {
                throw new ArgumentException(FIELD_AMOUNT_IS_INVALID_EXCEPTION);
            }

            _newCustomer.AddAddress(new Address
            {
                StreetName   = _currentRecord[1],
                StreetNumber = int.Parse(_currentRecord[2]),
                Town         = _currentRecord[3],
                ZipCode      = int.Parse(_currentRecord[4]),
                Province     = _currentRecord[5]
            });
        }
コード例 #7
0
        private void ImportAddress()
        {
            if (HasNotImportedCustomer())
            {
                throw new Exception(CustomerNotDefined);
            }
            if (AddressRecordSizeIsNotCorrect())
            {
                throw new Exception(InvalidAddressRecord);
            }

            var newAddress = new Address
            {
                StreetName   = _record[1],
                StreetNumber = Int32.Parse(_record[2]),
                Town         = _record[3],
                ZipCode      = Int32.Parse(_record[4]),
                Province     = _record[5]
            };

            _newCustomer.AddAddress(newAddress);
        }
コード例 #8
0
        private void importAddress()
        {
            if (_record.Length == 6)
            {
                var newAddress = new Address();
                int integerParseValue;
                newAddress.StreetName = _record[1];

                if (!Int32.TryParse(_record[2], out integerParseValue))
                {
                    throw new ImportException("Could not import Address. Value is not in correct format");
                }
                newAddress.StreetNumber = integerParseValue;

                newAddress.Town = _record[3];
                if (!Int32.TryParse(_record[4], out integerParseValue))
                {
                    throw new ImportException("Could not import Address. Value is not in correct format");
                }
                newAddress.ZipCode = integerParseValue;

                newAddress.Province = _record[5];

                if (_newCustomer != null)
                {
                    _newCustomer.AddAddress(newAddress);
                }
                else
                {
                    throw new ImportException("Could not import Address. Customer not exist");
                }
            }
            else
            {
                throw new ImportException("Could not import Address. Data is missing");
            }
        }