Example #1
0
 public void should_be_able_to_query_test_data()
 {
     using (IDocumentSession db = ReusableDocumentStore.OpenSession())
     {
         db.Query <Record>().Count().Should().BePositive();
     }
 }
Example #2
0
 private RecordServiceResult GetSignOffPublishingResponse(Record record)
 {
     using (var db = ReusableDocumentStore.OpenSession())
     {
         return(GetSignOffPublishingResponse(db, record));
     }
 }
        public new void SetUp()
        {
            var store = GetDocumentStore();

            store.Initialize();
            IndexCreation.CreateIndexes(typeof(Record).Assembly, store);
            WaitForIndexing(store);
            ReusableDocumentStore = store;

            Db = ReusableDocumentStore.OpenSession();

            var record1 = QueryTestHelper.SimpleRecord().With(m => { m.Gemini.Title = "sea"; });
            var record2 = QueryTestHelper.SimpleRecord().With(m => { m.Gemini.Title = "seabirds"; });
            var record3 = QueryTestHelper.SimpleRecord().With(m => { m.Gemini.Title = "birds"; });
            var record4 = QueryTestHelper.SimpleRecord().With(m => { m.Gemini.Title = "coastal birds"; });
            var record5 = QueryTestHelper.SimpleRecord().With(m => { m.Gemini.Title = "1234"; });
            var record6 = QueryTestHelper.SimpleRecord().With(m => { m.Gemini.Title = "sea1234"; });
            var record7 = QueryTestHelper.SimpleRecord().With(m => { m.Gemini.Title = "sea 1234"; });

            Db.Store(record1);
            Db.Store(record2);
            Db.Store(record3);
            Db.Store(record4);
            Db.Store(record5);
            Db.Store(record6);
            Db.Store(record7);
            Db.SaveChanges();
            WaitForIndexing(ReusableDocumentStore);
        }
        public void test_results_sorted_by_title_works_with_bolding()
        {
            using (var db = ReusableDocumentStore.OpenSession())
            {
                var helper = new RecordQueryer(db);

                var record = SimpleRecord().With(m =>
                {
                    m.Gemini.Title = "cowsea";
                    m.Gemini.DatasetReferenceDate = "2017-10-11";
                });

                db.Store(record);
                db.SaveChanges();
                WaitForIndexing(ReusableDocumentStore);

                var input = new RecordQueryInputModel
                {
                    Q = "sea",
                    F = null,
                    P = 0,
                    N = 25,
                    O = SortOptions.TitleAZ
                };

                var results = helper.Search(input).Results;
                results.Count.Should().Be(3);
                results.ToList()[0].Title.Should().Be("cow<b>sea</b>");
                results.ToList()[1].Title.Should().Be("<b>sea</b>");
                results.ToList()[2].Title.Should().Be("<b>sea</b>birds");

                input = new RecordQueryInputModel
                {
                    Q = "sea",
                    F = null,
                    P = 0,
                    N = 25,
                    O = SortOptions.TitleZA
                };

                results = helper.Search(input).Results;
                results.Count.Should().Be(3);
                results.ToList()[0].Title.Should().Be("<b>sea</b>birds");
                results.ToList()[1].Title.Should().Be("<b>sea</b>");
                results.ToList()[2].Title.Should().Be("cow<b>sea</b>");
            }
        }
Example #5
0
        private Record TestAssessment(Record record)
        {
            using (var db = ReusableDocumentStore.OpenSession())
            {
                db.Store(record);
                db.SaveChanges();

                var publishingController = GetTestPublishingController(db);

                var request = new AssessmentRequest
                {
                    Id = Helpers.RemoveCollection(record.Id)
                };

                return(((RecordServiceResult)publishingController.Assess(request)).Record);
            }
        }
        public void test_exact_search_checks_abstract_too()
        {
            using (var db = ReusableDocumentStore.OpenSession())
            {
                var record1 = QueryTestHelper.SimpleRecord().With(m =>
                {
                    m.Gemini.Title    = "marine conservation zone";
                    m.Gemini.Abstract = "population analysis data for zone";
                });
                var record2 = QueryTestHelper.SimpleRecord().With(m =>
                {
                    m.Gemini.Title    = "habitat data";
                    m.Gemini.Abstract = "marine conservation analysis data";
                });

                db.Store(record1);
                db.Store(record2);
                db.SaveChanges();
                WaitForIndexing(ReusableDocumentStore);

                var helper = new RecordQueryer(db);

                var input = QueryTestHelper.EmptySearchInput().With(x => x.Q = @"""marine conservation""");

                var results = helper.Search(input).Results;
                results.Count.Should().Be(2);
                results.ToList()[0].Title.Should().Be("<b>marine conservation</b> zone");
                results.ToList()[1].Title.Should().Be("habitat data");

                input = QueryTestHelper.EmptySearchInput().With(x => x.Q = @"""analysis data""");

                results = helper.Search(input).Results;
                results.Count.Should().Be(2);
                results.ToList()[0].Title.Should().Be("marine conservation zone");
                results.ToList()[1].Title.Should().Be("habitat data");

                input = QueryTestHelper.EmptySearchInput().With(x => x.Q = @"""population analysis""");

                results = helper.Search(input).Results;
                results.Count.Should().Be(1);
                results.ToList()[0].Title.Should().Be("marine conservation zone");
            }
        }
        public void highlighting_should_work_with_wildcard_queries()
        {
            using (IDocumentSession db = ReusableDocumentStore.OpenSession())
            {
                db.Store(new Item
                {
                    Title =
                        "On the 9th. William Findley and David Redick--deputed by the Committee of Safety (as it is designated) which met on the 2d. of this month at Parkinson Ferry arrived in Camp with the Resolutions of the said Committee; and to give information of the State of things in the four Western Counties of Pennsylvania to wit--Washington Fayette Westd. & Alligany in order to see if it would prevent the March of the Army into them."
                });
                db.Store(new Item
                {
                    Title =
                        "At 10 oclock I had a meeting with these persons in presence of Govr. Howell (of New Jersey) the Secretary of the Treasury, Colo. Hamilton, & Mr. Dandridge: Govr. Mifflin was invited to be present, but excused himself on acct. of business."
                });
                db.Store(new Item
                {
                    Title =
                        "Mr. Findley began. He confined his information to such parts of the four Counties as he was best acquainted with; referring to Mr. Reddick for a recital of what fell within his knowledge, in the other parts of these Counties"
                });
                db.SaveChanges();
            }

            new SearchIndex().Execute(ReusableDocumentStore);
            WaitForIndexing(ReusableDocumentStore);

            using (IDocumentSession db = ReusableDocumentStore.OpenSession())
            {
                Func <string, Highlightings> execute = q =>
                {
                    Highlightings lites;
                    db.Advanced.DocumentQuery <Item>("SearchIndex")
                    .WaitForNonStaleResults()
                    .Highlight("Title", 128, 2, out lites)
                    .Search("Title", q)
                    .ToList();
                    return(lites);
                };

                execute("committee").ResultIndents.Should().NotBeEmpty();  // succeeds
                execute("committee*").ResultIndents.Should().NotBeEmpty(); // fails
            }
        }
Example #8
0
        public void ShouldGetRightResults()
        {
            using (var db = ReusableDocumentStore.OpenSession())
            {
                var records = new[] { "foo", "foo (bar)" }.Select(MakeRecord);

                foreach (var record in records)
                {
                    db.Store(record);
                }

                db.SaveChanges();
            }

            WaitForIndexing(ReusableDocumentStore);

            using (var db = ReusableDocumentStore.OpenSession())
            {
                Action <string, int> testCase = (k, n) =>
                {
//                    var query = db.Query<MyIndex.Result, MyIndex>()
//                        .Where(r => r.Keywords.Contains(k));
//                    var results = query.As<Record>().Take(10).ToList();
//                    results.Count.Should().Be(n);

                    var input  = EmptyQuery().With(q => q.F.Keywords = new[] { k });
                    var output = new RecordQueryer(db).Search(input);
                    output.Total.Should().Be(n);
                };

                // todo how to deal with empty keyword?
//                testCase("", 0);
                testCase("http://vocab/xxx", 0);
//                testCase("http://vocab/foo", 1);
//                testCase("http://vocab/foo (xxx)", 0);
//                testCase("http://vocab/foo (bar)", 1);
//                testCase("http://vocab/foo - (xxx)", 0);
            }
        }
        public new void SetUp()
        {
            var store = GetDocumentStore();

            store.Initialize();
            IndexCreation.CreateIndexes(typeof(Record).Assembly, store);
            WaitForIndexing(store);
            ReusableDocumentStore = store;

            Db = ReusableDocumentStore.OpenSession();

            var record1 = SimpleRecord().With(m =>
            {
                m.Gemini.Title = "sea";
                m.Gemini.DatasetReferenceDate = "2017-10-10";
            });
            var record2 = SimpleRecord().With(m =>
            {
                m.Gemini.Title = "seabirds";
                m.Gemini.DatasetReferenceDate = "2017-10-19";
            });
            var record3 = SimpleRecord().With(m =>
            {
                m.Gemini.Title = "birds";
                m.Gemini.DatasetReferenceDate = "2017-10-15";
            });
            var record4 = SimpleRecord().With(m =>
            {
                m.Gemini.Title = "coastal birds";
                m.Gemini.DatasetReferenceDate = "2017-10-17";
            });

            Db.Store(record1);
            Db.Store(record2);
            Db.Store(record3);
            Db.Store(record4);
            Db.SaveChanges();
            WaitForIndexing(ReusableDocumentStore);
        }
        public void search_by_metadata_date()
        {
            //Save some data
            using (var db1 = ReusableDocumentStore.OpenSession())
            {
                var record = new Record
                {
                    Path   = @"X:\some\path",
                    Gemini = Library.Blank().With(m =>
                    {
                        m.Title        = "Some title";
                        m.MetadataDate = DateTime.Parse("2020-01-01");
                    }),
                    Footer = new Footer()
                };

                Db.Store(record);
                Db.SaveChanges();
            }

            using (var db2 = ReusableDocumentStore.OpenSession())
            {
                var helper = new RecordQueryer(db2);

                var input = new RecordQueryInputModel
                {
                    Q = "",
                    F = new FilterOptions {
                        MetadataDate = DateTime.Parse("2020-01-01")
                    },
                    P = 0,
                    N = 25,
                    O = 0
                };

                helper.Query(input).Count().Should().Be(1);
            }
        }
Example #11
0
        public void fail_when_reassessing_up_to_date_record_at_upload_stage()
        {
            var recordId = Helpers.AddCollection("593177d9-885f-4450-903b-ecb9ea667575");
            var record   = new Record().With(r =>
            {
                r.Id         = recordId;
                r.Path       = @"X:\path\to\assessment\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.MetadataDate = new DateTime(2017, 07, 30);
                });
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed       = true,
                        CompletedOnUtc  = new DateTime(2017, 07, 21),
                        CompletedByUser = new UserInfo
                        {
                            DisplayName = "Pete",
                            Email       = "*****@*****.**"
                        },
                        InitialAssessmentWasDoneOnSpreadsheet = false
                    },
                    SignOff = new SignOffInfo
                    {
                        DateUtc = new DateTime(2017, 07, 29)
                    },
                    Target = new TargetInfo
                    {
                        Gov = new GovPublicationInfo
                        {
                            Publishable = true,
                            LastAttempt = new PublicationAttempt
                            {
                                DateUtc = new DateTime(2017, 07, 30)
                            }
                        }
                    }
                };
                r.Footer = new Footer();
            });

            using (var db = ReusableDocumentStore.OpenSession())
            {
                db.Store(record);
                db.SaveChanges();

                var publishingController = GetTestPublishingController(db);

                var request = new AssessmentRequest
                {
                    Id = Helpers.RemoveCollection(record.Id)
                };

                Action a = () => publishingController.Assess(request);
                a.Should().Throw <InvalidOperationException>().And.Message.Should().Be("Assessment has already been completed and is up to date");

                var resultRecord = db.Load <Record>(record.Id);
                resultRecord.Publication.Should().NotBeNull();

                var publicationInfo = resultRecord.Publication;
                publicationInfo.Should().NotBeNull();
                publicationInfo.Assessment.Completed.Should().BeTrue();
                publicationInfo.Assessment.CompletedByUser.DisplayName.Should().Be("Pete");
                publicationInfo.Assessment.CompletedByUser.Email.Should().Be("*****@*****.**");
                publicationInfo.Assessment.CompletedOnUtc.Should().Be(new DateTime(2017, 07, 21));
                resultRecord.Gemini.MetadataDate.Should().NotBe(publicationInfo.Assessment.CompletedOnUtc);
            }
        }
Example #12
0
        private void TestSuccessfulGovPublishing(string resourceType, List <Resource> resources)
        {
            var recordId = Guid.NewGuid().ToString();
            var record   = new Record().With(r =>
            {
                r.Id          = Helpers.AddCollection(recordId);
                r.Path        = @"X:\path\to\working\folder";
                r.Validation  = Validation.Gemini;
                r.Gemini      = Library.Example().With(m => m.ResourceType = resourceType);
                r.Resources   = resources;
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo {
                        Completed = true
                    },
                    SignOff = new SignOffInfo
                    {
                        DateUtc = new DateTime(2017, 08, 02),
                        User    = TestUserInfo.TestUser
                    },
                    Target = new TargetInfo
                    {
                        Gov = new GovPublicationInfo
                        {
                            Publishable = true
                        }
                    }
                };
                r.Footer = new Footer();
            });

            using (var db = ReusableDocumentStore.OpenSession())
            {
                db.Store(record);
                db.SaveChanges();

                var currentTime = Clock.CurrentUtcDateTimeGetter;
                var testTime    = new DateTime(2017, 08, 18, 12, 0, 0);
                Clock.CurrentUtcDateTimeGetter = () => testTime;

                var vocabQueryerMock     = new Mock <IVocabQueryer>();
                var uploadService        = new PublishingUploadRecordService(db, new RecordValidator(vocabQueryerMock.Object));
                var dataServiceMock      = new Mock <IDataService>();
                var metadataUploaderMock = new Mock <IGovService>();
                var hubServiceMock       = new Mock <IHubService>();
                var redactorMock         = new Mock <IRecordRedactor>();
                var uploader             = new RobotPublisher(env, db, redactorMock.Object, uploadService, dataServiceMock.Object, metadataUploaderMock.Object, hubServiceMock.Object);
                vocabQueryerMock.Setup(x => x.GetVocab(It.IsAny <string>())).Returns(new Vocabulary());
                redactorMock.Setup(x => x.RedactRecord(It.IsAny <Record>())).Returns(record);

                uploader.PublishRecord(record);
                var updatedRecord = db.Load <Record>(record.Id);

                DataPublishedSuccessfully(updatedRecord, testTime);
                updatedRecord.Publication.Target.Hub.Should().BeNull();
                GovPublishedSuccessfully(updatedRecord, testTime);
                ResourcesUpdatedCorrectly(recordId, record.Resources, updatedRecord.Resources);

                updatedRecord.Gemini.MetadataDate.Should().Be(testTime);
                var fileCount = CountFileResources(record.Resources);

                dataServiceMock.Verify(x => x.UploadDataFile(Helpers.RemoveCollection(record.Id), It.IsAny <string>()), Times.Exactly(fileCount));
                hubServiceMock.Verify(x => x.Publish(It.IsAny <Record>()), Times.Never);
                metadataUploaderMock.Verify(x => x.UploadGeminiXml(record), Times.Once);
                metadataUploaderMock.Verify(x => x.UpdateDguIndex(record), Times.Once);
                redactorMock.Verify(x => x.RedactRecord(It.IsAny <Record>()), Times.Once);

                Clock.CurrentUtcDateTimeGetter = currentTime;
            }
        }
Example #13
0
        public void recently_modified_records()
        {
            var dateTest7 = new RecentlyModifiedRecord
            {
                Id    = Helpers.AddCollection("1458dfd1-e356-4287-9190-65e5f9ffd1df"),
                Title = "DateTest_7",
                Date  = new DateTime(2017, 07, 12, 15, 00, 00),
                User  = "******",
                Event = "created"
            };

            var dateTest5 = new RecentlyModifiedRecord
            {
                Id    = Helpers.AddCollection("80de0c30-325a-4392-ab4e-64b0654ca6ec"),
                Title = "DateTest_5",
                Date  = new DateTime(2017, 07, 11, 10, 00, 00),
                User  = "******",
                Event = "created"
            };

            var dateTest4 = new RecentlyModifiedRecord
            {
                Id    = Helpers.AddCollection("f5a48ac7-13f6-40ba-85a2-f4534d9806a5"),
                Title = "DateTest_4",
                Date  = new DateTime(2017, 07, 01, 15, 05, 0),
                User  = "******",
                Event = "edited"
            };

            var dateTest3 = new RecentlyModifiedRecord
            {
                Id    = Helpers.AddCollection("8c88dd97-3317-43e4-b59e-239e0604a094"),
                Title = "DateTest_3",
                Date  = new DateTime(2017, 07, 01, 15, 00, 00),
                User  = "******",
                Event = "edited"
            };

            var dateTest2 = new RecentlyModifiedRecord
            {
                Id    = Helpers.AddCollection("3ad98517-110b-40d7-aa0d-f0e3b1273007"),
                Title = "DateTest_2",
                Date  = new DateTime(2017, 06, 05, 09, 00, 00),
                User  = "******",
                Event = "edited"
            };

            var dateTest1 = new RecentlyModifiedRecord
            {
                Id    = Helpers.AddCollection("8f4562ea-9d8a-45a0-afd3-bc5072d342a0"),
                Title = "DateTest_1",
                Date  = new DateTime(2016, 01, 03, 09, 00, 00),
                User  = "******",
                Event = "edited"
            };

            var testRecords = new List <RecentlyModifiedRecord> {
                dateTest7, dateTest5, dateTest4, dateTest3, dateTest2, dateTest1
            };
            var expectedValues = new List <Tuple <string, string, string> >
            {
                new Tuple <string, string, string>("DateTest_7", "Cathy", "created"),
                new Tuple <string, string, string>("DateTest_5", "Pete", "created"),
                new Tuple <string, string, string>("DateTest_4", "Pete", "edited"),
                new Tuple <string, string, string>("DateTest_3", "Cathy", "edited"),
                new Tuple <string, string, string>("DateTest_2", "Pete", "edited")
            };

            using (var db = ReusableDocumentStore.OpenSession())
            {
                var vocabQueryerMock = new Mock <IVocabQueryer>();
                vocabQueryerMock.Setup(x => x.GetVocab(It.IsAny <string>())).Returns(new Vocabulary());

                IRecordService recordService = new RecordService(db, new RecordValidator(vocabQueryerMock.Object));
                AddLastModifiedDateRecords(testRecords, recordService);
                db.SaveChanges();

                var usageController         = new UsageController(db);
                var usageResult             = usageController.GetRecentlyModifiedRecords();
                var recentlyModifiedRecords = usageResult.RecentlyModifiedRecords;

                recentlyModifiedRecords.Select(r => new Tuple <string, string, string>(r.Title, r.User, r.Event.ToString())).Should().ContainInOrder(expectedValues);
            }
        }
Example #14
0
        public void should_count_records_with_duplicate_titles()
        {
            using (var db = ReusableDocumentStore.OpenSession())
            {
                var vocabQueryerMock = new Mock <IVocabQueryer>();
                vocabQueryerMock.Setup(x => x.GetVocab(It.IsAny <string>())).Returns(new Vocabulary());
                var service = new RecordService(db, new RecordValidator(vocabQueryerMock.Object));

                var record1 = new Record().With(r =>
                {
                    r.Id     = Helpers.AddCollection("7ce85158-f6f9-491d-902e-b3f2c8bb5264");
                    r.Path   = @"X:\path\to\duplicate\record\1";
                    r.Gemini = new Metadata().With(m =>
                    {
                        m.Title = "This is a duplicate record";
                        m.Keywords.Add(new MetadataKeyword
                        {
                            Vocab = "http://vocab.jncc.gov.uk/jncc-domain", Value = "Marine"
                        });
                        m.Keywords.Add(new MetadataKeyword
                        {
                            Vocab = "http://vocab.jncc.gov.uk/jncc-category", Value = "Example"
                        });
                        m.ResourceType = "dataset";
                    });
                });
                var record2 = new Record().With(r =>
                {
                    r.Id     = Helpers.AddCollection("afb4ebbf-4286-47ed-b09f-a4d40af139e1");
                    r.Path   = @"X:\path\to\duplicate\record\2";
                    r.Gemini = new Metadata().With(m =>
                    {
                        m.Title = "This is a duplicate record";
                        m.Keywords.Add(new MetadataKeyword
                        {
                            Vocab = "http://vocab.jncc.gov.uk/jncc-domain", Value = "Marine"
                        });
                        m.Keywords.Add(new MetadataKeyword
                        {
                            Vocab = "http://vocab.jncc.gov.uk/jncc-category", Value = "Example"
                        });
                        m.ResourceType = "dataset";
                    });
                });

                service.Insert(record1, TestUser);
                service.Insert(record2, TestUser);

                db.SaveChanges();
                WaitForIndexing(ReusableDocumentStore);

                var results = db
                              .Query <RecordsWithDuplicateTitleCheckerIndex.Result, RecordsWithDuplicateTitleCheckerIndex>()
                              .Where(x => x.Count > 1)
                              .Take(100)
                              .ToList();

                // looks like we have some duplicates created by the seeder!
                results.Count.Should()
                .BeInRange(1, 10);     // perhaps prevent more duplicate titles being seeded in the future!
                results.Should().Contain(r => r.Title == "This is a duplicate record");
            }
        }
Example #15
0
        public void awaiting_sign_off_test()
        {
            var retrieveSignOffTest1Record = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection("af8e531f-2bed-412e-9b03-2b339c672bff");
                r.Path       = @"X:\path\to\assessment\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.Title        = "Retrieve Sign Off Test 1";
                    m.MetadataDate = new DateTime(2017, 09, 25);
                });
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed       = true,
                        CompletedOnUtc  = new DateTime(2017, 09, 25),
                        CompletedByUser = new UserInfo
                        {
                            DisplayName = "test",
                            Email       = "*****@*****.**"
                        }
                    },
                    SignOff = null,
                    Target  = new TargetInfo
                    {
                        Hub = new HubPublicationInfo {
                            Publishable = true
                        },
                        Gov = new GovPublicationInfo {
                            Publishable = true
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest2Record = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection("f4b6dd32-93ad-41cd-a7a0-2df0f5c7410b");
                r.Path       = @"X:\path\to\assessment\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.Title        = "Retrieve Sign Off Test 2";
                    m.MetadataDate = new DateTime(2017, 09, 25);
                });
                r.Publication = null;
                r.Footer      = new Footer();
            });

            var retrieveSignOffTest3Record = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection("dbb9bf6e-c128-4611-bd3f-73bd7a9ae4e9");
                r.Path       = @"X:\path\to\assessment\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.Title        = "Retrieve Sign Off Test 3";
                    m.MetadataDate = new DateTime(2017, 09, 26);
                });
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed      = true,
                        CompletedOnUtc = new DateTime(2017, 09, 25)
                    },
                    SignOff = new SignOffInfo
                    {
                        DateUtc = new DateTime(2017, 09, 26),
                        User    = TestUserInfo.TestUser
                    },
                    Target = new TargetInfo
                    {
                        Hub = new HubPublicationInfo {
                            Publishable = true
                        },
                        Gov = new GovPublicationInfo {
                            Publishable = true
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest4Record = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection("e1255428-90ec-4d8e-a9d9-0cf210c64dbd");
                r.Path       = @"X:\path\to\assessment\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.Title        = "Retrieve Sign Off Test 4";
                    m.MetadataDate = new DateTime(2017, 09, 25);
                });
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed = false
                    },
                    SignOff = new SignOffInfo
                    {
                        DateUtc = new DateTime(2017, 09, 25),
                        User    = TestUserInfo.TestUser
                    },
                    Target = new TargetInfo
                    {
                        Hub = new HubPublicationInfo {
                            Publishable = true
                        },
                        Gov = new GovPublicationInfo {
                            Publishable = true
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest5Record = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection("f37efe7f-3033-42d4-83a0-f6d7ab59d0c2");
                r.Path       = @"X:\path\to\assessment\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.Title        = "Retrieve Sign Off Test 5";
                    m.MetadataDate = new DateTime(2017, 09, 25);
                });
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed      = true,
                        CompletedOnUtc = new DateTime(2017, 09, 25)
                    },
                    SignOff = new SignOffInfo
                    {
                        DateUtc = new DateTime(2017, 09, 20),
                        User    = TestUserInfo.TestUser
                    },
                    Data = new DataInfo
                    {
                        LastAttempt = new PublicationAttempt
                        {
                            DateUtc = new DateTime(2017, 09, 21)
                        }
                    },
                    Target = new TargetInfo
                    {
                        Hub = new HubPublicationInfo
                        {
                            Publishable = true,
                            LastAttempt = new PublicationAttempt
                            {
                                DateUtc = new DateTime(2017, 09, 21)
                            }
                        },
                        Gov = new GovPublicationInfo
                        {
                            Publishable = true,
                            LastAttempt = new PublicationAttempt
                            {
                                DateUtc = new DateTime(2017, 09, 21)
                            }
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest6Record = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection("d038b054-269e-4d4f-a635-da75929e8fee");
                r.Path       = @"X:\path\to\assessment\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.Title        = "Retrieve Sign Off Test 6";
                    m.MetadataDate = new DateTime(2017, 09, 28);
                });
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed      = true,
                        CompletedOnUtc = new DateTime(2017, 09, 25)
                    },
                    SignOff = new SignOffInfo
                    {
                        DateUtc = new DateTime(2017, 09, 28),
                        User    = TestUserInfo.TestUser
                    },
                    Target = new TargetInfo
                    {
                        Gov = new GovPublicationInfo
                        {
                            Publishable = true,
                            LastAttempt = new PublicationAttempt
                            {
                                DateUtc = new DateTime(2017, 09, 28)
                            }
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest7Record = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection("7ec978bc-2ecd-4ab4-a233-5aead4947ab2");
                r.Path       = @"X:\path\to\assessment\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.Title        = "Retrieve Sign Off Test 7";
                    m.MetadataDate = new DateTime(2017, 09, 30);
                });
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed      = false,
                        CompletedOnUtc = new DateTime(2017, 09, 25)
                    },
                    SignOff = new SignOffInfo
                    {
                        DateUtc = new DateTime(2017, 09, 20),
                        User    = TestUserInfo.TestUser
                    },
                    Target = new TargetInfo
                    {
                        Gov = new GovPublicationInfo
                        {
                            Publishable = true,
                            LastAttempt = new PublicationAttempt
                            {
                                DateUtc = new DateTime(2017, 09, 21)
                            }
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest8Record = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection("fd32ba72-41d4-4769-a365-34ad570fbf7b");
                r.Path       = @"X:\path\to\assessment\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.Title        = "Retrieve Sign Off Test 8";
                    m.MetadataDate = new DateTime(2017, 09, 30);
                });
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed      = true,
                        CompletedOnUtc = new DateTime(2017, 09, 25)
                    },
                    SignOff = new SignOffInfo
                    {
                        DateUtc = new DateTime(2017, 09, 26),
                        User    = TestUserInfo.TestUser
                    },
                    Target = new TargetInfo
                    {
                        Gov = new GovPublicationInfo
                        {
                            Publishable = true,
                            LastAttempt = new PublicationAttempt
                            {
                                DateUtc = new DateTime(2017, 09, 30)
                            }
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var testRecords = new List <Record>(new [] { retrieveSignOffTest1Record, retrieveSignOffTest2Record,
                                                         retrieveSignOffTest3Record, retrieveSignOffTest4Record, retrieveSignOffTest5Record,
                                                         retrieveSignOffTest6Record, retrieveSignOffTest7Record, retrieveSignOffTest8Record });

            using (var db = ReusableDocumentStore.OpenSession())
            {
                foreach (var record in testRecords)
                {
                    db.Store(record);
                }
                db.SaveChanges();

                WaitForIndexing(ReusableDocumentStore); // Allow time for indexing

                var publishingController = GetTestPublishingController(db);
                var result = publishingController.PendingSignOff();
                result.Count.Should().Be(2);
                result.Count(r => string.Equals(r.Title, "Retrieve Sign Off Test 1", StringComparison.CurrentCulture)).Should().Be(1);
                result.Count(r => string.Equals(r.Title, "Retrieve Sign Off Test 5", StringComparison.CurrentCulture)).Should().Be(1);
            }
        }
Example #16
0
        public void sign_off_out_of_date_record()
        {
            var record = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection("d2183557-a36b-4cfb-8a57-279febdc4de5");
                r.Path       = @"X:\path\to\signoff\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.MetadataDate = new DateTime(2017, 07, 12);
                });
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed      = true,
                        CompletedOnUtc = new DateTime(2017, 07, 09)
                    },
                    SignOff = new SignOffInfo
                    {
                        User = new UserInfo
                        {
                            DisplayName = "Cathy",
                            Email       = "*****@*****.**"
                        },
                        DateUtc = new DateTime(2017, 07, 10)
                    },
                    Target = new TargetInfo
                    {
                        Gov = new GovPublicationInfo
                        {
                            Publishable = true,
                            LastAttempt = new PublicationAttempt
                            {
                                DateUtc = new DateTime(2017, 07, 11)
                            },
                            LastSuccess = new PublicationAttempt
                            {
                                DateUtc = new DateTime(2017, 07, 11)
                            }
                        }
                    }
                };
                r.Footer = new Footer();
            });

            using (var db = ReusableDocumentStore.OpenSession())
            {
                Action a = () => GetSignOffPublishingResponse(db, record);
                a.Should().Throw <InvalidOperationException>().And.Message.Should().Be(
                    "Couldn't sign-off record for publication - assessment not completed or out of date");

                var resultRecord = db.Load <Record>(record.Id);
                resultRecord.Publication.Should().NotBeNull();

                var publicationInfo = resultRecord.Publication;
                publicationInfo.Should().NotBeNull();
                publicationInfo.Target.Gov.LastAttempt.DateUtc.Should().Be(new DateTime(2017, 07, 11));
                publicationInfo.Target.Gov.LastSuccess.DateUtc.Should().Be(new DateTime(2017, 07, 11));
                resultRecord.Publication.Data.Should().BeNull();
                publicationInfo.SignOff.User.DisplayName.Should().Be("Cathy");
                publicationInfo.SignOff.User.Email.Should().Be("*****@*****.**");
                publicationInfo.SignOff.DateUtc.Should().Be(new DateTime(2017, 07, 10));
                resultRecord.Gemini.MetadataDate.Should().NotBe(publicationInfo.SignOff.DateUtc);
            }
        }
Example #17
0
        public void sign_off_record_with_failed_upload_attempt()
        {
            var record = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection("5d8ce359-4475-4a0e-9f31-0f70dbbc8bfc");
                r.Path       = @"X:\path\to\signoff\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.MetadataDate = new DateTime(2017, 07, 12);
                });
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed      = true,
                        CompletedOnUtc = new DateTime(2017, 07, 09)
                    },
                    SignOff = new SignOffInfo
                    {
                        User = new UserInfo
                        {
                            DisplayName = "Cathy",
                            Email       = "*****@*****.**"
                        },
                        DateUtc = new DateTime(2017, 07, 10)
                    },
                    Target = new TargetInfo
                    {
                        Gov = new GovPublicationInfo
                        {
                            Publishable = true,
                            LastAttempt = new PublicationAttempt
                            {
                                DateUtc = new DateTime(2017, 07, 12)
                            }
                        }
                    }
                };
                r.Footer = new Footer();
            });

            using (var db = ReusableDocumentStore.OpenSession())
            {
                Action a = () => GetSignOffPublishingResponse(db, record);
                a.Should().Throw <InvalidOperationException>().And.Message.Should()
                .Be("The record has already been signed off");

                var resultRecord = db.Load <Record>(record.Id);
                resultRecord.Publication.Should().NotBeNull();

                var publicationInfo = resultRecord.Publication;
                publicationInfo.Should().NotBeNull();
                publicationInfo.Target.Gov.LastAttempt.DateUtc.Should().Be(new DateTime(2017, 07, 12));
                publicationInfo.Target.Gov.LastSuccess.Should().BeNull();
                resultRecord.Publication.Data.Should().BeNull();
                publicationInfo.SignOff.User.DisplayName.Should().Be("Cathy");
                publicationInfo.SignOff.User.Email.Should().Be("*****@*****.**");
                publicationInfo.SignOff.DateUtc.Should().Be(new DateTime(2017, 07, 10));
                resultRecord.Gemini.MetadataDate.Should().NotBe(publicationInfo.SignOff.DateUtc);
            }
        }
        public new void SetUp()
        {
            var store = GetDocumentStore();

            store.Initialize();
            IndexCreation.CreateIndexes(typeof(Record).Assembly, store);
            WaitForIndexing(store);
            ReusableDocumentStore = store;

            Db = ReusableDocumentStore.OpenSession();

            var record1 = QueryTestHelper.SimpleRecord().With(m =>
            {
                m.Gemini.Title        = "spreadsheet record";
                m.Gemini.DataFormat   = "Microsoft Excel for Windows";
                m.Gemini.ResourceType = "publication";
                m.Manager             = new UserInfo {
                    DisplayName = "cathy test [email protected]"
                };
            });
            var record2 = QueryTestHelper.SimpleRecord().With(m =>
            {
                m.Gemini.Title        = "database record";
                m.Gemini.DataFormat   = "Database";
                m.Gemini.ResourceType = "nonGeographicDataset";
                m.Manager             = new UserInfo {
                    DisplayName = "pete test [email protected]"
                };
            });
            var record3 = QueryTestHelper.SimpleRecord().With(m =>
            {
                m.Gemini.Title        = "geospatial record 1";
                m.Gemini.DataFormat   = "ESRI Arc/View ShapeFile";
                m.Gemini.ResourceType = "dataset";
                m.Manager             = new UserInfo {
                    DisplayName = "pete test"
                };
            });
            var record4 = QueryTestHelper.SimpleRecord().With(m =>
            {
                m.Gemini.Title        = "geospatial record 2";
                m.Gemini.DataFormat   = "Geospatial (vector polygon)";
                m.Gemini.ResourceType = "service";
                m.Manager             = new UserInfo {
                    DisplayName = "*****@*****.**"
                };
            });
            var record5 = QueryTestHelper.SimpleRecord().With(m =>
            {
                m.Gemini.Title        = "record with no data format";
                m.Gemini.DataFormat   = null;
                m.Gemini.ResourceType = "dataset";
            });

            Db.Store(record1);
            Db.Store(record2);
            Db.Store(record3);
            Db.Store(record4);
            Db.Store(record5);
            Db.SaveChanges();
            WaitForIndexing(ReusableDocumentStore);
        }
Example #19
0
        public void previously_published_to_gov_and_now_to_hub()
        {
            var recordId = Guid.NewGuid().ToString();
            var record   = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection(recordId);
                r.Path       = @"X:\path\to\working\folder";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example();
                r.Resources  = new List <Resource> {
                    new Resource {
                        Name = "File resource", Path = "x:\\test\\path.txt"
                    }
                };
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo {
                        Completed = true
                    },
                    SignOff = new SignOffInfo
                    {
                        DateUtc = new DateTime(2017, 08, 02),
                        User    = TestUserInfo.TestUser
                    },
                    Target = new TargetInfo
                    {
                        Hub = new HubPublicationInfo
                        {
                            Publishable = true // now going to publish here
                        },
                        Gov = new GovPublicationInfo
                        {
                            Publishable = false, // previously published here
                            LastSuccess = new PublicationAttempt
                            {
                                DateUtc = new DateTime(2017, 08, 17, 12, 0, 0)
                            }
                        }
                    }
                };
                r.Footer = new Footer();
            });

            using (var db = ReusableDocumentStore.OpenSession())
            {
                db.Store(record);
                db.SaveChanges();

                var currentTime = Clock.CurrentUtcDateTimeGetter;
                var testTime    = new DateTime(2017, 08, 18, 12, 0, 0);
                Clock.CurrentUtcDateTimeGetter = () => testTime;

                var vocabQueryerMock     = new Mock <IVocabQueryer>();
                var uploadService        = new PublishingUploadRecordService(db, new RecordValidator(vocabQueryerMock.Object));
                var dataServiceMock      = new Mock <IDataService>();
                var metadataUploaderMock = new Mock <IGovService>();
                var hubServiceMock       = new Mock <IHubService>();
                var redactorMock         = new Mock <IRecordRedactor>();
                var uploader             = new RobotPublisher(env, db, redactorMock.Object, uploadService, dataServiceMock.Object, metadataUploaderMock.Object, hubServiceMock.Object);
                vocabQueryerMock.Setup(x => x.GetVocab(It.IsAny <string>())).Returns(new Vocabulary());
                redactorMock.Setup(x => x.RedactRecord(It.IsAny <Record>())).Returns(record);

                uploader.PublishRecord(record);
                var updatedRecord = db.Load <Record>(record.Id);

                DataPublishedSuccessfully(updatedRecord, testTime);
                updatedRecord.Resources.Should().Contain(r => r.Name.Equals("File resource"));
                HubPublishedSuccessfully(updatedRecord, testTime);
                updatedRecord.Publication.Target.Gov.LastSuccess.DateUtc.Should().Be(new DateTime(2017, 08, 17, 12, 0, 0));
                ResourcesUpdatedCorrectly(recordId, record.Resources, updatedRecord.Resources);

                updatedRecord.Gemini.MetadataDate.Should().Be(testTime);

                var fileCount = CountFileResources(record.Resources);
                dataServiceMock.Verify(x => x.UploadDataFile(Helpers.RemoveCollection(record.Id), It.IsAny <string>()), Times.Exactly(fileCount));
                hubServiceMock.Verify(x => x.Publish(record), Times.Once);
                metadataUploaderMock.Verify(x => x.UploadGeminiXml(Helpers.RemoveCollectionFromId(record)), Times.Never);
                metadataUploaderMock.Verify(x => x.UpdateDguIndex(Helpers.RemoveCollectionFromId(record)), Times.Never);
                redactorMock.Verify(x => x.RedactRecord(It.IsAny <Record>()), Times.Once);

                Clock.CurrentUtcDateTimeGetter = currentTime;
            }
        }
Example #20
0
        public void publish_fails_at_dgu_upload(
            [Values("publication", "dataset", "nonGeographicDataset", "service")] string resourceType)
        {
            var recordId = Guid.NewGuid().ToString();
            var record   = new Record().With(r =>
            {
                r.Id         = Helpers.AddCollection(recordId);
                r.Path       = @"X:\path\to\upload\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m => m.ResourceType = resourceType);
                r.Resources  = new List <Resource> {
                    new Resource {
                        Name = "Some resource", Path = "x:\\test\\path"
                    }
                };
                r.Publication = new PublicationInfo
                {
                    Assessment = new AssessmentInfo
                    {
                        Completed = true
                    },
                    SignOff = new SignOffInfo
                    {
                        DateUtc = new DateTime(2017, 08, 02),
                        User    = TestUserInfo.TestUser
                    },
                    Target = new TargetInfo
                    {
                        Hub = new HubPublicationInfo
                        {
                            Publishable = true
                        },
                        Gov = new GovPublicationInfo
                        {
                            Publishable = true
                        }
                    }
                };
                r.Footer = new Footer();
            });

            using (var db = ReusableDocumentStore.OpenSession())
            {
                db.Store(record);
                db.SaveChanges();

                var currentTime = Clock.CurrentUtcDateTimeGetter;
                var testTime    = new DateTime(2017, 08, 18, 12, 0, 0);
                Clock.CurrentUtcDateTimeGetter = () => testTime;

                var vocabQueryerMock     = new Mock <IVocabQueryer>();
                var uploadService        = new PublishingUploadRecordService(db, new RecordValidator(vocabQueryerMock.Object));
                var dataServiceMock      = new Mock <IDataService>();
                var metadataUploaderMock = new Mock <IGovService>();
                var hubServiceMock       = new Mock <IHubService>();
                var redactorMock         = new Mock <IRecordRedactor>();
                var uploader             = new RobotPublisher(env, db, redactorMock.Object, uploadService, dataServiceMock.Object, metadataUploaderMock.Object, hubServiceMock.Object);

                var recordWithoutCollection = Helpers.RemoveCollectionFromId(record);
                vocabQueryerMock.Setup(x => x.GetVocab(It.IsAny <string>())).Returns(new Vocabulary());
                metadataUploaderMock.Setup(x => x.UploadGeminiXml(recordWithoutCollection)).Throws(new Exception("test message"));
                hubServiceMock.Setup(x => x.Publish(It.IsAny <Record>()));
                redactorMock.Setup(x => x.RedactRecord(It.IsAny <Record>())).Returns(record);

                uploader.PublishRecord(record);

                var updatedRecord = db.Load <Record>(record.Id);
                updatedRecord.Publication.Data.LastAttempt.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.Data.LastSuccess.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.Target.Hub.LastAttempt.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.Target.Hub.LastSuccess.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.Target.Gov.LastAttempt.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.Target.Gov.LastAttempt.Message.Should().Be("test message");
                updatedRecord.Publication.Target.Gov.LastSuccess.Should().BeNull();
                updatedRecord.Gemini.MetadataDate.Should().Be(testTime);
                redactorMock.Verify(x => x.RedactRecord(It.IsAny <Record>()), Times.Exactly(2));

                Clock.CurrentUtcDateTimeGetter = currentTime;
            }
        }
Example #21
0
 public void OneTimeSetUp()
 {
     ReusableDocumentStore = DbHelper.Create(Seeder.Seed);
     Db = ReusableDocumentStore.OpenSession();
 }