Exemplo n.º 1
0
        public void GivenAnEmptyDatabase_WhenImportingSampleData_TwoCustomersAreImported()
        {
            _customerImporter.Import();

            var customers = _dataBase.GetCustomers();

            Assert.Equal(2, customers.Count);
        }
        public void GivenAnImporter_WhenImportingFromEmptyStream_ThenNoCustomerIsImported()
        {
            var streamReader     = new StreamStubBuilder().Build();
            var dataBase         = new MemoryDataBase();
            var customerImporter = new CustomerImporter(dataBase, streamReader);

            customerImporter.Import();

            var customers = dataBase.GetCustomers();

            Assert.Empty(customers);
        }
        public void GivenAnImporter_WhenImportingStreamWithCustomerWithInvalidAmountOfFields_ThenAnExceptionIsThrown(string invalidRecord)
        {
            var streamReader = new StreamStubBuilder()
                               .AddLine(invalidRecord)
                               .Build();

            var dataBase         = new MemoryDataBase();
            var customerImporter = new CustomerImporter(dataBase, streamReader);

            var exception = Assert.Throws <ArgumentException>(() => customerImporter.Import());

            Assert.Equal(CustomerImporter.FIELD_AMOUNT_IS_INVALID_EXCEPTION, exception.Message);
        }
        public void GivenAnImporter_WhenImportingUnrecognizedRecord_ThenAnExceptionIsThrown(string unrecognizedRecord)
        {
            var streamReader = new StreamStubBuilder()
                               .AddLine(unrecognizedRecord)
                               .Build();

            var dataBase         = new MemoryDataBase();
            var customerImporter = new CustomerImporter(dataBase, streamReader);

            var exception = Assert.Throws <ArgumentException>(() => customerImporter.Import());

            Assert.Equal(CustomerImporter.RECORD_IS_UNRECOGNIZED_EXCEPTION, exception.Message);
        }
        public void GivenAnImporter_WhenImportingStreamWithIncompleteAddress_ThenAnExceptionIsThrown()
        {
            var streamReader = new StreamStubBuilder()
                               .AddLine("C,Juan,Perez,C,23-25666777-9")
                               .AddLine("A,Alem,1122,CABA,1001")
                               .Build();

            var dataBase         = new MemoryDataBase();
            var customerImporter = new CustomerImporter(dataBase, streamReader);

            var exception = Assert.Throws <ArgumentException>(() => customerImporter.Import());

            Assert.Equal(CustomerImporter.FIELD_AMOUNT_IS_INVALID_EXCEPTION, exception.Message);
        }