public void FindMissingTiploc()
        {
            var records = ParserHelper.ParseRecords(Records);

            using (var connection = _fixture.CreateConnection())
            {
                connection.Open();
                var loader = new LocationLoader(connection, new Sequence(), Substitute.For <ILogger>());
                loader.Initialise();

                foreach (var record in records)
                {
                    loader.Add(record);
                }

                var id = loader.Find("WATRLOO");
                Assert.Equal(5L, id);

                var row = loader.Table.Rows[4];
                Assert.Equal(5L, row["Id"]);
                Assert.Equal("I", row["Action"]);
                Assert.Equal("WATRLOO", row["Tiploc"]);
                Assert.Equal("WATRLOO - MISSING", row["Description"]);
                Assert.Equal(DBNull.Value, row["Nlc"]);
                Assert.Equal(DBNull.Value, row["NlcCheckCharacter"]);
                Assert.Equal(DBNull.Value, row["NlcDescription"]);
                Assert.Equal(DBNull.Value, row["Stanox"]);
                Assert.Equal(DBNull.Value, row["ThreeLetterCode"]);
            }
        }
        public void LoadIntoDatabase()
        {
            var records = ParserHelper.ParseRecords(Records);

            using (var connection = _fixture.CreateConnection())
            {
                connection.Open();
                var loader = new LocationLoader(connection, new Sequence(), Substitute.For <ILogger>());
                loader.Initialise();

                foreach (var record in records)
                {
                    loader.Add(record);
                }

                using (var transaction = connection.BeginTransaction())
                {
                    loader.Load(transaction);

                    using (var command = connection.CreateCommand())
                    {
                        command.Transaction = transaction;
                        command.CommandText = "SELECT * FROM Locations";
                        using (var adapter = new SqlDataAdapter(command))
                        {
                            var table = new DataTable();
                            adapter.Fill(table);
                            Assert.Equal(4, table.Rows.Count);
                        };
                    }
                }
            }
        }
        public void CreateDataTableWithLocationColumns()
        {
            using (var connection = _fixture.CreateConnection())
            {
                connection.Open();
                var loader = new LocationLoader(connection, new Sequence(), Substitute.For <ILogger>());
                loader.Initialise();
                var table = loader.Table;

                Assert.Equal(9, table.Columns.Count);
                Assert.NotNull(table.Columns["Nlc"]);
            }
        }
        public void OtherRecordsNotAdded()
        {
            var records = ParserHelper.ParseRecords(Records);

            using (var connection = _fixture.CreateConnection())
            {
                connection.Open();
                var loader = new LocationLoader(connection, new Sequence(), Substitute.For <ILogger>());
                loader.Initialise();

                Assert.False(loader.Add(records[4]));

                Assert.Equal(0, loader.Table.Rows.Count);
            }
        }
        public void FindExistingTiploc()
        {
            var records = ParserHelper.ParseRecords(Records);

            using (var connection = _fixture.CreateConnection())
            {
                connection.Open();
                var loader = new LocationLoader(connection, new Sequence(), Substitute.For <ILogger>());
                loader.Initialise();

                foreach (var record in records)
                {
                    loader.Add(record);
                }

                var id = loader.Find("PRNC884");
                Assert.Equal(2L, id);
            }
        }
        public void CreatesLookup()
        {
            var records  = ParserHelper.ParseRecords(Records);
            var expected = records.OfType <Tiploc>().Select(r => r.Code);

            using (var connection = _fixture.CreateConnection())
            {
                connection.Open();
                var loader = new LocationLoader(connection, new Sequence(), Substitute.For <ILogger>());
                loader.Initialise();

                foreach (var record in records)
                {
                    loader.Add(record);
                }

                Assert.All(expected, t => Assert.True(loader.Lookup.ContainsKey(t)));
            }
        }
        public void AddDelete()
        {
            var records = ParserHelper.ParseRecords(Records);

            using (var connection = _fixture.CreateConnection())
            {
                connection.Open();
                var loader = new LocationLoader(connection, new Sequence(), Substitute.For <ILogger>());
                loader.Initialise();

                Assert.True(loader.Add(records[3]));

                var row = loader.Table.Rows[0];
                Assert.Equal(1L, row["Id"]);
                Assert.Equal("D", row["Action"]);
                Assert.Equal("LNDRBES", row["Tiploc"]);
                Assert.Equal(DBNull.Value, row["Description"]);
                Assert.Equal(DBNull.Value, row["Nlc"]);
                Assert.Equal(DBNull.Value, row["NlcCheckCharacter"]);
                Assert.Equal(DBNull.Value, row["NlcDescription"]);
                Assert.Equal(DBNull.Value, row["Stanox"]);
                Assert.Equal(DBNull.Value, row["ThreeLetterCode"]);
            }
        }