public void TestCreateIndexNewChildItemExceptionMissingParentIdTest()
        {
            const int parentId = 21;

            using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex, UserDefinedRouting)))
            {
                var testObject = new ChildDocumentLevelTwoUserDefinedRouting()
                {
                    Id = 46,
                    D3 = "p7.p21.p46"
                };

                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(testObject, testObject.Id, new RoutingDefinition {
                    ParentId = parentId, RoutingId = 7
                });

                // Save to Elasticsearch
                var ret = context.SaveChanges();
                Assert.AreEqual(ret.Status, HttpStatusCode.OK);

                var roundTripResult = context.GetDocument <ChildDocumentLevelTwoUserDefinedRouting>(testObject.Id);

                Assert.AreEqual(testObject.Id, roundTripResult.Id);
            }
        }
        public void TestCreateIndexNewChildItemTestParentDoesNotExist()
        {
            const int parentId = 332;

            // This creates a new child doc with the parent 332 even though no parent for 332 exists

            using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex, UserDefinedRouting)))
            {
                var testObject = new ChildDocumentLevelTwoUserDefinedRouting
                {
                    Id = 47,
                    D3 = "DoesNotExist.p332.p47"
                };

                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(testObject, testObject.Id, new RoutingDefinition {
                    ParentId = parentId, RoutingId = 7
                });

                // Save to Elasticsearch
                var ret = context.SaveChanges();
                Assert.AreEqual(ret.Status, HttpStatusCode.OK);

                Thread.Sleep(1500);

                var roundTripResult = context.GetDocument <ChildDocumentLevelTwoUserDefinedRouting>(testObject.Id, new RoutingDefinition {
                    ParentId = parentId, RoutingId = 7
                });

                var childDocs = context.Search <ChildDocumentLevelTwoUserDefinedRouting>(BuildSearchForChildDocumentsWithIdAndParentType(parentId, "childdocumentleveloneuserdefinedrouting"));
                Assert.IsNotNull(childDocs.PayloadResult.Hits.HitsResult.First(t => t.Id == 47));
                Assert.AreEqual(testObject.Id, roundTripResult.Id);
            }
        }
        public void TestCreateIndexNewChildItemTest()
        {
            const int parentId = 21;

            // This could return NOT FOUND 404 or OK 200. It all depends is the routing matches the same shard. It does not search for the exact parent

            using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex, UserDefinedRouting)))
            {
                var testObject = new ChildDocumentLevelTwoUserDefinedRouting()
                {
                    Id = 46,
                    D3 = "p7.p21.p46"
                };

                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(testObject, testObject.Id, new RoutingDefinition {
                    ParentId = parentId, RoutingId = 7
                });

                // Save to Elasticsearch
                var ret = context.SaveChanges();
                Assert.AreEqual(ret.Status, HttpStatusCode.OK);

                Thread.Sleep(1500);
                var roundTripResult = context.GetDocument <ChildDocumentLevelTwoUserDefinedRouting>(testObject.Id, new RoutingDefinition {
                    ParentId = parentId, RoutingId = 7
                });

                var childDocs = context.Search <ChildDocumentLevelTwoUserDefinedRouting>(BuildSearchForChildDocumentsWithIdAndParentType(parentId, "childdocumentleveloneuserdefinedrouting"));
                Assert.IsNotNull(childDocs.PayloadResult.Hits.HitsResult.First(t => t.Id == 46));
                Assert.AreEqual(testObject.Id, roundTripResult.Id);
            }
        }
        public void TestCreateIndexNewChildItemTestParentDoesNotExist()
        {
            const int parentId = 332;
            // This creates a new child doc with the parent 332 even though no parent for 332 exists

            using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex, UserDefinedRouting)))
            {
                var testObject = new ChildDocumentLevelTwoUserDefinedRouting
                {
                    Id = 47,
                    D3 = "DoesNotExist.p332.p47"
                };

                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(testObject, testObject.Id, new RoutingDefinition { ParentId = parentId, RoutingId = 7});

                // Save to Elasticsearch
                var ret = context.SaveChanges();
                Assert.AreEqual(ret.Status, HttpStatusCode.OK);

                Thread.Sleep(1500);

                var roundTripResult = context.GetDocument<ChildDocumentLevelTwoUserDefinedRouting>(testObject.Id, new RoutingDefinition { ParentId = parentId, RoutingId = 7 });

                var childDocs = context.Search<ChildDocumentLevelTwoUserDefinedRouting>(BuildSearchForChildDocumentsWithIdAndParentType(parentId, "childdocumentleveloneuserdefinedrouting"));
                Assert.IsNotNull(childDocs.PayloadResult.Hits.HitsResult.First(t => t.Id.ToString() == "47"));
                Assert.AreEqual(testObject.Id, roundTripResult.Id);
            }
        }
        public void TestCreateIndexNewChildItemTest()
        {
            const int parentId = 21;
            // This could return NOT FOUND 404 or OK 200. It all depends is the routing matches the same shard. It does not search for the exact parent

            using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex, UserDefinedRouting)))
            {
                var testObject = new ChildDocumentLevelTwoUserDefinedRouting()
                {
                    Id = 46,
                    D3 = "p7.p21.p46"
                };

                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(testObject, testObject.Id, new RoutingDefinition { ParentId = parentId, RoutingId = 7});

                // Save to Elasticsearch
                var ret = context.SaveChanges();
                Assert.AreEqual(ret.Status, HttpStatusCode.OK);

                Thread.Sleep(1500);
                var roundTripResult = context.GetDocument<ChildDocumentLevelTwoUserDefinedRouting>(testObject.Id, new RoutingDefinition { ParentId = parentId, RoutingId = 7 });

                var childDocs = context.Search<ChildDocumentLevelTwoUserDefinedRouting>(BuildSearchForChildDocumentsWithIdAndParentType(parentId, "childdocumentleveloneuserdefinedrouting"));
                Assert.IsNotNull(childDocs.PayloadResult.Hits.HitsResult.First(t => t.Id.ToString() == "46"));
                Assert.AreEqual(testObject.Id, roundTripResult.Id);
            }
        }
        public void TestCreateIndexNewChildItemExceptionMissingParentIdTest()
        {
            const int parentId = 21;
            using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex, UserDefinedRouting)))
            {
                var testObject = new ChildDocumentLevelTwoUserDefinedRouting()
                {
                    Id = 46,
                    D3 = "p7.p21.p46"
                };

                context.TraceProvider = new ConsoleTraceProvider();
                context.AddUpdateDocument(testObject, testObject.Id, new RoutingDefinition { ParentId = parentId, RoutingId = 7});

                // Save to Elasticsearch
                var ret = context.SaveChanges();
                Assert.AreEqual(ret.Status, HttpStatusCode.OK);

                var roundTripResult = context.GetDocument<ChildDocumentLevelTwoUserDefinedRouting>(testObject.Id);

                Assert.AreEqual(testObject.Id, roundTripResult.Id);
            }
        }