Example #1
0
        public void TestCreateIndexNewChildItemExceptionMissingParentIdTest()
        {
            const int parentId = 21;

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

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

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

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

                Assert.AreEqual(testObject.Id, roundTripResult.Id);
            }
        }
Example #2
0
        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)))
            {
                var testObject = new ChildDocumentLevelTwo
                {
                    Id = 47,
                    D3 = "DoesNotExist.p332.p47"
                };

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

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

                Thread.Sleep(1500);

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

                var childDocs = context.Search <ChildDocumentLevelTwo>(BuildSearchForChildDocumentsWithIdAndParentType(parentId, "childdocumentlevelone"));
                Assert.IsNotNull(childDocs.PayloadResult.Hits.HitsResult.First(t => t.Id.ToString() == "47"));
                Assert.AreEqual(testObject.Id, roundTripResult.Id);
            }
        }
Example #3
0
        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)))
            {
                var testObject = new ChildDocumentLevelTwo
                {
                    Id = 46,
                    D3 = "p7.p21.p46"
                };

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

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

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

                var childDocs = context.Search <ChildDocumentLevelTwo>(BuildSearchForChildDocumentsWithIdAndParentType(parentId, "childdocumentlevelone"));
                Assert.IsNotNull(childDocs.PayloadResult.Hits.HitsResult.First(t => t.Id.ToString() == "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)))
            {
                var testObject = new ChildDocumentLevelTwo
                {
                    Id = 47,
                    D3 = "DoesNotExist.p332.p47"
                };

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

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

                Thread.Sleep(1500);

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

                var childDocs = context.Search<ChildDocumentLevelTwo>(BuildSearchForChildDocumentsWithIdAndParentType(parentId, "childdocumentlevelone"));
                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)))
            {
                var testObject = new ChildDocumentLevelTwo
                {
                    Id = 46,
                    D3 = "p7.p21.p46"
                };

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

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

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

                var childDocs = context.Search<ChildDocumentLevelTwo>(BuildSearchForChildDocumentsWithIdAndParentType(parentId, "childdocumentlevelone"));
                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)))
            {
                var testObject = new ChildDocumentLevelTwo
                {
                    Id = 46,
                    D3 = "p7.p21.p46"
                };

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

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

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

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