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);
        }
Example #2
0
 public CustomerShould()
 {
     _streamReader = new StreamStubBuilder()
                     .AddLine("C,Pepe,Sanchez,D,22333444")
                     .AddLine("A,San Martin,3322,Olivos,1636,BsAs")
                     .AddLine("A,Maipu,888,Florida,1122,Buenos Aires")
                     .AddLine("C,Juan,Perez,C,23-25666777-9")
                     .AddLine("A,Alem,1122,CABA,1001,CABA")
                     .Build();
     _dataBase         = new DataBase();
     _customerImporter = new CustomerImporter(_dataBase, _streamReader);
 }
        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);
        }
        public void Test1()
        {
            // Bad Smell 4: Que el test conozca como conectarse!
            using (_session = CreateSession())
                using (var inputStream = ValidDataStream())
                {
                    var transaction = _session.BeginTransaction();
                    CustomerImporter.Value(_session, inputStream);

                    Assert.AreEqual(2, _session.CreateCriteria <Customer>().List <Customer>().Count);

                    AssertPepeSanchezWasImportedCorrectly();
                    AssertJuanPerezWasImportedCorrectly();

                    transaction.Commit();
                }
        }