Пример #1
0
        static void Test(Func <string, int> fn, Func <FileInfo, IEnumerable <Mock> > convert)
        {
            using (var testDirectory = new TestDirectory())
            {
                var _ = TestHarness.Run(
                    () => fn(testDirectory.AbsolutePath),
                    new[] {
                    new Query {
                        Name        = "data",
                        CommandText = @"
                                SELECT 123 [Number], 'ABC' [Text]
                                UNION ALL SELECT 456 [Number], 'DEF' [Text]
                            "
                    }
                }
                    );

                var file = Assert.Single(testDirectory.GetFiles());

                var actual   = convert(file);
                var expected = new[] {
                    new Mock {
                        Number = 123, Text = "ABC"
                    },
                    new Mock {
                        Number = 456, Text = "DEF"
                    }
                };
                Assert.Equal(expected, actual);
            }
        }
Пример #2
0
        public void ShouldPersistFilesGivenOutDir()
        {
            using (var testDirectory = new TestDirectory())
            {
                var _ = TestHarness.Run(
                    () => Program.AsJson(Sql.ConnectionString, testDirectory.AbsolutePath),
                    new[]
                {
                    new Query {
                        Name = "Query1", CommandText = "SELECT 1 [Num]"
                    },
                    new Query {
                        Name = "Query2", CommandText = "SELECT 2 [Num]"
                    },
                    new Query {
                        Name = "Query3", CommandText = "SELECT 3 [Num]"
                    },
                    new Query {
                        Name = "Query4", CommandText = "SELECT 4 [Num]"
                    }
                }
                    );

                var actual   = testDirectory.GetFiles().Select(x => x.Name).OrderBy(x => x);
                var expected = new[] { "Query1", "Query2", "Query3", "Query4" };
                Assert.Equal(expected, actual);
            }
        }
Пример #3
0
        public void ShouldHandleSimpleCommandText()
        {
            var commandText = "SELECT 1 [Num]";

            var(exitCode, stdOut, stdError) = TestHarness.Run(
                () => Program.AsTabbed(Sql.ConnectionString),
                commandText
                );

            Assert.Equal(0, exitCode);
            Assert.Empty(stdError);
            var hashes = stdOut.Split(Environment.NewLine)
                         .Where(IsNotEmpty)
                         .Select(AsHash)
                         .ToArray();

            var actual   = Assert.Single(hashes);
            var expected = new Hash(
                "Query",
                "0x313EA196881D370AEEAF78E274B0D08541F6CBF0DDFC7BE57A4594AD0A752A5C"
                );

            Assert.Equal(expected, actual);

            bool IsNotEmpty(string s) => !string.IsNullOrWhiteSpace(s);

            Hash AsHash(string s)
            {
                string[] parts = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                return(new Hash(parts[0], parts[1]));
            }
        }
Пример #4
0
        public void ShouldWriteErrorsToStdErrorGivenError()
        {
            var queries = new []
            {
                new Query {
                    Name = "1", CommandText = "SELECT x"
                }
            };

            var(_, __, stdError) = TestHarness.Run(() => Program.AsTabbed("abc"), queries);
            Assert.NotEmpty(stdError);
        }
Пример #5
0
        public void ShouldSetExitCodeOneGivenAnyError(int insertPosition)
        {
            var queries = new List <Query>
            {
                new Query {
                    Name = "1", CommandText = "SELECT 1"
                },
                new Query {
                    Name = "2", CommandText = "SELECT 2"
                }
            };

            queries.Insert(insertPosition, new Query
            {
                Name        = "3",
                CommandText = "SELECT X"
            });

            var(exitCode, _, __) = TestHarness.Run(() => Program.AsTabbed(Sql.ConnectionString), queries);
            Assert.Equal(1, exitCode);
        }