Beispiel #1
0
        public async Task PostScriptTest()
        {
            using (Database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
            {
                var dbDoc = await context.ReadForMemoryAsync(RequestBodyStream(), "TestSqlEtlScript");

                var testScript = JsonDeserializationServer.TestSqlEtlScript(dbDoc);

                var result = (SqlEtlTestScriptResult)SqlEtl.TestScript(testScript, Database, ServerStore, context);

                await using (var writer = new AsyncBlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    var djv = (DynamicJsonValue)TypeConverter.ToBlittableSupportedType(result);
                    writer.WriteObject(context.ReadObject(djv, "et/sql/test"));
                }
            }
        }
Beispiel #2
0
        public async Task CanTestDeletion(bool performRolledBackTransaction)
        {
            using (var store = GetDocumentStore())
            {
                CreateRdbmsSchema(store);

                using (var session = store.OpenAsyncSession())
                {
                    await session.StoreAsync(new Order
                    {
                        OrderLines = new List <OrderLine>
                        {
                            new OrderLine {
                                Cost = 3, Product = "Milk", Quantity = 3
                            },
                            new OrderLine {
                                Cost = 4, Product = "Bear", Quantity = 2
                            },
                        }
                    });

                    await session.SaveChangesAsync();
                }

                var result1 = store.Maintenance.Send(new PutConnectionStringOperation <SqlConnectionString>(new SqlConnectionString()
                {
                    Name             = "simulate",
                    ConnectionString = GetConnectionString(store),
                    FactoryName      = "System.Data.SqlClient",
                }));
                Assert.NotNull(result1.RaftCommandIndex);

                var database = GetDatabase(store.Database).Result;

                using (database.DocumentsStorage.ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                {
                    var result = (SqlEtlTestScriptResult)SqlEtl.TestScript(new TestSqlEtlScript
                    {
                        PerformRolledBackTransaction = performRolledBackTransaction,
                        DocumentId    = "orders/1-A",
                        IsDelete      = true,
                        Configuration = new SqlEtlConfiguration()
                        {
                            Name = "simulate",
                            ConnectionStringName = "simulate",
                            SqlTables            =
                            {
                                new SqlEtlTable {
                                    TableName = "Orders", DocumentIdColumn = "Id"
                                },
                                new SqlEtlTable {
                                    TableName = "OrderLines", DocumentIdColumn = "OrderId"
                                },
                                new SqlEtlTable {
                                    TableName = "NotUsedInScript", DocumentIdColumn = "OrderId"
                                },
                            },
                            Transforms =
                            {
                                new Transformation()
                                {
                                    Collections ={ "Orders"                   },
                                    Name        = "OrdersAndLines",
                                    Script      = defaultScript
                                }
                            }
                        }
                    }, database, database.ServerStore, context);

                    Assert.Equal(0, result.TransformationErrors.Count);
                    Assert.Equal(0, result.LoadErrors.Count);
                    Assert.Equal(0, result.SlowSqlWarnings.Count);

                    Assert.Equal(2, result.Summary.Count);

                    var orderLines = result.Summary.First(x => x.TableName == "OrderLines");

                    Assert.Equal(1, orderLines.Commands.Length); // delete

                    var orders = result.Summary.First(x => x.TableName == "Orders");

                    Assert.Equal(1, orders.Commands.Length); // delete
                }

                using (var session = store.OpenAsyncSession())
                {
                    Assert.NotNull(session.Query <Order>("orders/1-A"));
                }
            }
        }