Example #1
0
        public void Connection_Is_Reused_When_Configured()
        {
            var client = new SqlDatabaseClient(true)
            {
                ConnectionString = connectionString
            };

            client.ExecuteCommand(createTempTableCommand);

            Action action = () => client.ExecuteCommand(verifyIfTempTableExistsQuery);

            action.Should().NotThrow();
        }
Example #2
0
        public void Connection_Is_Not_Reused()
        {
            var client = new SqlDatabaseClient(false)
            {
                ConnectionString = connectionString
            };

            client.ExecuteCommand(createTempTableCommand);

            Action action = () => client.ExecuteCommand(verifyIfTempTableExistsQuery);

            action.Should().Throw <SqlException>();
        }
Example #3
0
        public void Connection_is_not_reused()
        {
            // This test uses a global temp table (GTT) since a GTT is deleted when the connection that created it goes out of scope.
            var target = new SqlDatabaseClient(false)
            {
                ConnectionString = _connectionString
            };

            target.ExecuteCommand(_createGlobalTempTableCommand);

            var formatterManager = new FormatterManager();
            var actual           = target.ReadTable(_verifyIfTempTableExistsQuery, formatterManager);

            var expectedDatasetXml = @"
<dataset name=""a-name"" table=""a-name"">
  <data>
    <row TempTableExists=""0"" />
  </data>
</dataset>
";
            var xml             = XElement.Parse(expectedDatasetXml);
            var expectedDataset = DatasetElement.Load(xml);

            Assert.AreEqual(expectedDataset.Data.ToString(), actual.Data.ToString());
        }
Example #4
0
        public void Initialize()
        {
            _target = new SqlDatabaseClient();
            _target.ConnectionString = "data source=localhost;initial catalog=Product_Build;integrated security=True;MultipleActiveResultSets=True;App=SqlDatabaseClientTest";

            var deleteDataCommand = @"
DELETE [dbo].[Product];
DELETE [dbo].[Category];
DELETE [dbo].[Supplier];
";

            _target.ExecuteCommand(deleteDataCommand);
        }
Example #5
0
        public void Write_read_and_compare_records()
        {
            var target = new SqlDatabaseClient(false)
            {
                ConnectionString = _connectionString
            };

            var deleteDataCommand = @"
DELETE [dbo].[Product];
DELETE [dbo].[Category];
DELETE [dbo].[Supplier];
";

            target.ExecuteCommand(deleteDataCommand);

            var datasetXml = @"
<dataset name=""suppliers"" setIdentityInsert=""true"" table=""Supplier"">
  <data>
    <row Id=""1"" Name=""supplier-1"" ContactName=""contact-name-1"" ContactPhone=""100-200-0001"" ContactEmail=""*****@*****.**"" />
    <row Id=""2"" Name=""supplier-2"" ContactName=""contact-name-2"" ContactPhone=""100-200-0002"" ContactEmail=""*****@*****.**"" />
    <row Id=""3"" Name=""supplier-3"" ContactName=""contact-name-3"" ContactPhone=""100-200-0003"" ContactEmail=""*****@*****.**"" />
  </data>
</dataset>
";
            var xml        = XElement.Parse(datasetXml);
            var dataset    = DatasetElement.Load(xml);

            target.WriteTable(dataset);

            var formatterManager = new FormatterManager();

            var selectRecordsQuery = "SELECT * FROM [dbo].[Supplier];";

            var actual = target.ReadTable(selectRecordsQuery, formatterManager);

            DbSafeManagerHelper.CompareDatasets(dataset, actual, new string[] { "Id" }, false, false);
        }
Example #6
0
        public void Write_Read_And_Compare_Results()
        {
            var client = new SqlDatabaseClient(false)
            {
                ConnectionString = connectionString
            };
            var deleteCmd = @"
                DELETE FROM public.product;
                DELETE FROM public.category;
                DELETE FROM public.supplier;
            ";

            client.ExecuteCommand(deleteCmd);

            var expectedDatasetJson = @"
                 {
                    ""name"": ""suppliers"",
                    ""table"": ""Supplier"",
                    ""rows"": [
                        {
                        ""columns"": [
                                {
                                    ""name"": ""id"",
                                    ""value"": ""1""
                                },
                                {
                                    ""name"": ""name"",
                                    ""value"": ""supplier-1""
                                },
                                {
                                    ""name"": ""contact_name"",
                                    ""value"": ""contact-name-1""
                                },
                                {
                                    ""name"": ""contact_phone"",
                                    ""value"": ""100-200-0001""
                                },
                                {
                                    ""name"": ""contact_email"",
                                    ""value"": ""*****@*****.**""
                                }
                            ]
                        },
                        {
                        ""columns"": [
                                {
                                    ""name"": ""id"",
                                    ""value"": ""2""
                                },
                                {
                                    ""name"": ""name"",
                                    ""value"": ""supplier-2""
                                },
                                {
                                    ""name"": ""contact_name"",
                                    ""value"": ""contact-name-2""
                                },
                                {
                                    ""name"": ""contact_phone"",
                                    ""value"": ""100-200-0002""
                                },
                                {
                                    ""name"": ""contact_email"",
                                    ""value"": ""*****@*****.**""
                                }
                            ]
                        },
                        {
                        ""columns"": [
                                {
                                    ""name"": ""id"",
                                    ""value"": ""3""
                                },
                                {
                                    ""name"": ""name"",
                                    ""value"": ""supplier-3""
                                },
                                {
                                    ""name"": ""contact_name"",
                                    ""value"": ""contact-name-3""
                                },
                                {
                                    ""name"": ""contact_phone"",
                                    ""value"": ""100-200-0003""
                                },
                                {
                                    ""name"": ""contact_email"",
                                    ""value"": ""*****@*****.**""
                                }
                            ]
                        }
                    ]
                }
            ";

            var jsonDoc         = JsonDocument.Parse(expectedDatasetJson);
            var expectedDataset = Dataset.Parse(jsonDoc.RootElement);

            client.InsertTableData(expectedDataset);

            var formatterManager = new FormatterManager();
            var selectQuery      = "SELECT * FROM public.supplier;";

            var actualDataset = client.ReadTableData(selectQuery, formatterManager);

            expectedDataset.Rows.Should().BeEquivalentTo(actualDataset.Rows);
        }