Exemple #1
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);
        }