コード例 #1
0
        public void GivenAnImporter_WhenInitializingWithNullDatabase_ThenAnExceptionIsThrown()
        {
            var streamReader = new StreamStubBuilder().Build();
            var exception    = Assert.Throws <ArgumentException>(() => new CustomerImporter(null, streamReader));

            Assert.Equal(CustomerImporter.DATABASE_IS_NULL_EXCEPTION, exception.Message);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }