示例#1
0
        public void SetUp()
        {
            var store = new InMemoryDatabaseHelper().Create();

            using (var db = store.OpenSession())
            {
                try
                {
                    var importer = Importer.CreateImporter(db, new SeabedSurveyMapping());
                    importer.SkipBadRecords = true; // see log for skipped bad records
                    importer.Import(@"D:\workspace\test_import.csv");

                    var errors = importer.Results
                                 .Where(r => !r.Success)
                                 .Select(r => r.Record.Gemini.Title + Environment.NewLine + JsonConvert.SerializeObject(r.Validation) + Environment.NewLine);
                    File.WriteAllLines(@"D:\workspace\test_import.csv.errors.txt", errors);

                    db.SaveChanges();

                    imported = db.Query <Record>()
                               .Customize(x => x.WaitForNonStaleResults())
                               .Take(1000).ToList();
                }
                catch (CsvHelperException ex)
                {
                    string s = (string)ex.Data["CsvHelper"];
                    throw;
                }
            }
        }
示例#2
0
        public void SetUp()
        {
            var paths = new { input = @"C:\work\marine-recorder-dump\MR_MNCR_1stTranche_INPUT_Final.csv", errors = @"C:\work\marine-recorder-dump\errors.txt" };

            var store = new InMemoryDatabaseHelper().Create();

            using (var db = store.OpenSession())
            {
                try
                {
                    var importer = Importer.CreateImporter(db, new MarineRecorderMapping());
                    importer.SkipBadRecords = true;
                    importer.Import(paths.input);

                    var errors = importer.Results
                        .Where(r => !r.Success)
                        .Select(r => r.Record.Gemini.Title + Environment.NewLine + JsonConvert.SerializeObject(r.Validation) + Environment.NewLine);
                    File.WriteAllLines(paths.errors, errors);

                    db.SaveChanges();

                    imported = db.Query<Record>()
                                 .Customize(x => x.WaitForNonStaleResults())
                                 .Take(1000).ToList();

                }
                catch (CsvHelperException ex)
                {
                    string s = (string)ex.Data["CsvHelper"];
                    throw;
                }
            }
        }
        private IDocumentSession GetDbForFilterTests()
        {
            var store = new InMemoryDatabaseHelper().Create();

            using (var db = store.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();

                return(db);
            }
        }
示例#4
0
        public static IDocumentSession GetNewDbSessionWithThisRecordAdded(Record record)
        {
            var store = new InMemoryDatabaseHelper().Create();

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

                return(db);
            }
        }
示例#5
0
        public void versioning_should_work()
        {
            // guid keys are problematic for raven versioning
            // so here's a test that show that it now works

            // this test mutates data so we don't use the ResusableDocumentStore...

            IDocumentStore store = new InMemoryDatabaseHelper().Create();
            Guid           id    = Guid.Parse("f7b444f7-76f3-47a4-b8d8-cc204d400728");

            using (IDocumentSession db = store.OpenSession())
            {
                var record = new Record {
                    Id = id, Gemini = Library.Example()
                };

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

            using (IDocumentSession db = store.OpenSession())
            {
                var record = db.Load <Record>(id);

                record.Notes = "i'm updating this record!";
                db.SaveChanges();
            }

            using (IDocumentSession db = store.OpenSession())
            {
                var      record    = db.Load <Record>(id);
                Record[] revisions = db.Advanced.GetRevisionsFor <Record>(db.Advanced.GetDocumentId(record), 0, 10);

                revisions.Count().Should().Be(2);
                revisions.Select(r => r.Revision).Should().ContainInOrder(new[] { 1, 2 });
            }
        }
示例#6
0
        private List <Record> PendingUploadTest(Record record)
        {
            var store = new InMemoryDatabaseHelper().Create();

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

                var uploadServiceMock = new Mock <IOpenDataPublishingUploadRecordService>();
                var uploadHelperMock  = new Mock <IOpenDataUploadHelper>();
                var robotUploader     = new RobotUploader(db, uploadServiceMock.Object, uploadHelperMock.Object);

                return(robotUploader.GetRecordsPendingUpload());
            }
        }
        public void test_exact_search_checks_abstract_too()
        {
            var store = new InMemoryDatabaseHelper().Create();
            var db    = store.OpenSession();

            using (db)
            {
                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();

                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");
            }
        }
        private IDocumentSession GetDbForSortTests()
        {
            var store = new InMemoryDatabaseHelper().Create();
            var db    = store.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();

            return(db);
        }
示例#9
0
        private static Record TestAssessment(Record record)
        {
            var store = new InMemoryDatabaseHelper().Create();

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

                var publishingController = GetTestOpenDataPublishingController(db);

                var request = new AssessmentRequest
                {
                    Id = record.Id
                };

                return(((RecordServiceResult)publishingController.Assess(request)).Record);
            }
        }
示例#10
0
        public void SetUp()
        {
            var store = new InMemoryDatabaseHelper().Create();

            using (var db = store.OpenSession())
            {
                var importer = Importer.CreateImporter(db, new DaveChambersMapping());
                importer.SkipBadRecords = true;
                importer.Import(@"C:\Work\data\Data Services metadata for top cat entry.csv");

                var errors = importer.Results
                             .Where(r => !r.Success)
                             .Select(r => r.Record.Gemini.Title + Environment.NewLine + JsonConvert.SerializeObject(r.Validation) + Environment.NewLine);
                File.WriteAllLines(@"C:\work\data\dave-chambers-import-errors.txt", errors);

                db.SaveChanges();

                imported = db.Query <Record>()
                           .Customize(x => x.WaitForNonStaleResults())
                           .Take(1000).ToList();
            }
        }
        public void SetUp()
        {
            var store = new InMemoryDatabaseHelper().Create();

            using (var db = store.OpenSession())
            {
                var importer = Importer.CreateImporter(db, new EuropeanReportingMapping());
                importer.SkipBadRecords = true;
                importer.Import(@"C:\Work\data\europeanreporting\Article 17 JNCC publishable metadata_riskassessment.csv");

                var errors = importer.Results
                             .Where(r => !r.Success)
                             .Select(r => r.Record.Gemini.Title + Environment.NewLine + JsonConvert.SerializeObject(r.Validation) + Environment.NewLine);
                File.WriteAllLines(@"C:\work\data\europeanreporting\errors.txt", errors);

                db.SaveChanges();

                imported = db.Query <Record>()
                           .Customize(x => x.WaitForNonStaleResults())
                           .Take(1000).ToList();
            }
        }
示例#12
0
        public void SetUp()
        {
            var store = new InMemoryDatabaseHelper().Create();

            using (var db = store.OpenSession())
            {
                var importer = Importer.CreateImporter(db, new ActivitiesMapping());
                importer.SkipBadRecords = true; // see log for skipped bad records
                importer.Import(@"C:\work\activities\Catalogue2.txt");

                var errors = importer.Results
                             .Where(r => !r.Success)
                             .Select(r => r.Record.Gemini.Title + Environment.NewLine + JsonConvert.SerializeObject(r.Validation) + Environment.NewLine);
                File.WriteAllLines(@"C:\work\activities\activities-errors.txt", errors);

                db.SaveChanges();

                imported = db.Query <Record>()
                           .Customize(x => x.WaitForNonStaleResults())
                           .Take(1000).ToList();
            }
        }
示例#13
0
        public void RunPubcatImport()
        {
            var store = new InMemoryDatabaseHelper().Create();

            using (IDocumentSession db = store.OpenSession())
            {
                var importer = Importer.CreateImporter(db, new PubCatMapping());
                importer.SkipBadRecords = true;

                importer.Import(@"C:\Working\pubcat.csv");

                var errors = importer.Results
                             .Where(r => !r.Success)
                             .Select(r => r.Record.Gemini.Title + Environment.NewLine + JsonConvert.SerializeObject(r.Validation) + Environment.NewLine);
                File.WriteAllLines(@"C:\working\pubcat-errors.txt", errors);

                db.SaveChanges();

                imported = db.Query <Record>()
                           .Customize(x => x.WaitForNonStaleResults())
                           .Take(1050).ToList();
            }
        }
示例#14
0
        public void not_eligible_for_assessment_when_path_is_not_file_path(Record record)
        {
            var store = new InMemoryDatabaseHelper().Create();

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

                var publishingController = GetTestOpenDataPublishingController(db);

                var request = new AssessmentRequest
                {
                    Id = record.Id
                };

                Action a = () => publishingController.Assess(request);
                a.ShouldThrow <InvalidOperationException>().And.Message.Should().Be("Must have a file path for publishing");

                var resultRecord = db.Load <Record>(record.Id);
                resultRecord.Publication.OpenData.Assessment.Should().BeNull();
            }
        }
示例#15
0
        private IDocumentSession GetDbForSortTests()
        {
            var store = new InMemoryDatabaseHelper().Create();

            using (var db = store.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();

                return(db);
            }
        }
示例#16
0
        public void recently_modified_records()
        {
            var dateTest7 = new RecentlyModifiedRecord
            {
                Id    = new Guid("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    = new Guid("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    = new Guid("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    = new Guid("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    = new Guid("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    = new Guid("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")
            };

            var store = new InMemoryDatabaseHelper().Create();

            using (var db = store.OpenSession())
            {
                IRecordService recordService = new RecordService(db, new RecordValidator());
                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);
            }
        }
示例#17
0
        public void awaiting_sign_off_test()
        {
            var retrieveSignOffTest1Record = new Record().With(r =>
            {
                r.Id         = new Guid("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
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed      = true,
                            CompletedOnUtc = new DateTime(2017, 09, 25)
                        },
                        SignOff = null
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest2Record = new Record().With(r =>
            {
                r.Id         = new Guid("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         = new Guid("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
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed      = true,
                            CompletedOnUtc = new DateTime(2017, 09, 25)
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 09, 26),
                            User    = TestUserInfo.TestUser
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest4Record = new Record().With(r =>
            {
                r.Id         = new Guid("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
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed = false
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 09, 25),
                            User    = TestUserInfo.TestUser
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest5Record = new Record().With(r =>
            {
                r.Id         = new Guid("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
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed      = true,
                            CompletedOnUtc = new DateTime(2017, 09, 25)
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 09, 20),
                            User    = TestUserInfo.TestUser
                        },
                        LastAttempt = new PublicationAttempt
                        {
                            DateUtc = new DateTime(2017, 09, 21)
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest6Record = new Record().With(r =>
            {
                r.Id         = new Guid("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
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed      = true,
                            CompletedOnUtc = new DateTime(2017, 09, 25)
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 09, 28),
                            User    = TestUserInfo.TestUser
                        },
                        LastAttempt = new PublicationAttempt
                        {
                            DateUtc = new DateTime(2017, 09, 28)
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest7Record = new Record().With(r =>
            {
                r.Id         = new Guid("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
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed      = false,
                            CompletedOnUtc = new DateTime(2017, 09, 25)
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 09, 20),
                            User    = TestUserInfo.TestUser
                        },
                        LastAttempt = new PublicationAttempt
                        {
                            DateUtc = new DateTime(2017, 09, 21)
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var retrieveSignOffTest8Record = new Record().With(r =>
            {
                r.Id         = new Guid("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
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed      = true,
                            CompletedOnUtc = new DateTime(2017, 09, 25)
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 09, 26),
                            User    = TestUserInfo.TestUser
                        },
                        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 });

            var store = new InMemoryDatabaseHelper().Create();

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

                Thread.Sleep(100); // Allow time for indexing

                var publishingController = PublishingTestHelper.GetTestOpenDataPublishingController(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);
            }
        }
        public void failed_upload()
        {
            var record = new Record().With(r =>
            {
                r.Id         = new Guid("8ad134fa-9045-40af-a0cb-02bc3e868f5a");
                r.Path       = @"X:\path\to\upload\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.ResourceLocator = null;
                });
                r.Publication = new PublicationInfo
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed = true
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 08, 02),
                            User    = TestUserInfo.TestUser
                        },
                        Resources = new List <Resource> {
                            new Resource {
                                Path = "x:\\test\\path"
                            }
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var store = new InMemoryDatabaseHelper().Create();

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

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

                var uploadService    = new OpenDataPublishingUploadRecordService(db, new RecordValidator());
                var uploadHelperMock = new Mock <IOpenDataUploadHelper>();
                var uploader         = new RobotUploader(db, uploadService, uploadHelperMock.Object);

                uploadHelperMock.Setup(x => x.UploadAlternativeResources(record))
                .Throws(new WebException("test message"));

                uploader.Upload(new List <Record> {
                    record
                });

                var updatedRecord = db.Load <Record>(record.Id);
                updatedRecord.Publication.OpenData.LastAttempt.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.OpenData.LastAttempt.Message.Should().Be("test message");
                updatedRecord.Publication.OpenData.LastSuccess.Should().BeNull();
                updatedRecord.Gemini.MetadataDate.Should().Be(testTime);

                Clock.CurrentUtcDateTimeGetter = currentTime;
            }
        }
        public void corpulent_upload_with_populated_jncc_resource_location()
        {
            var record = new Record().With(r =>
            {
                r.Id         = new Guid("5bc8cd79-7d7f-4c71-9653-cbe82226e174");;
                r.Path       = @"X:\path\to\upload\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.Keywords.Add(new MetadataKeyword
                    {
                        Vocab = "http://vocab.jncc.gov.uk/metadata-admin",
                        Value = "Corpulent"
                    });
                    m.ResourceLocator = "http://data.jncc.gov.uk/data/filename";
                });
                r.Publication = new PublicationInfo
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed = true
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 08, 02),
                            User    = TestUserInfo.TestUser
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var store = new InMemoryDatabaseHelper().Create();

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

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

                var uploadService    = new OpenDataPublishingUploadRecordService(db, new RecordValidator());
                var uploadHelperMock = new Mock <IOpenDataUploadHelper>();
                var uploader         = new RobotUploader(db, uploadService, uploadHelperMock.Object);
                uploader.Upload(new List <Record> {
                    record
                });

                var updatedRecord = db.Load <Record>(record.Id);
                updatedRecord.Publication.OpenData.LastAttempt.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.OpenData.LastAttempt.Message.Should().BeNull();
                updatedRecord.Publication.OpenData.LastSuccess.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.OpenData.LastSuccess.Message.Should().BeNull();
                updatedRecord.Gemini.MetadataDate.Should().Be(testTime);
                updatedRecord.Gemini.ResourceLocator.Should().Be("http://data.jncc.gov.uk/data/filename");
                uploadHelperMock.Verify(x => x.UploadAlternativeResources(record), Times.Never);
                uploadHelperMock.Verify(x => x.UploadDataFile(record.Id, record.Path), Times.Never);
                uploadHelperMock.Verify(x => x.UploadMetadataDocument(record), Times.Once);
                uploadHelperMock.Verify(x => x.UploadWafIndexDocument(record), Times.Once);

                Clock.CurrentUtcDateTimeGetter = currentTime;
            }
        }
        public void record_not_corpulent_with_populated_resource_locator()
        {
            var recordId = new Guid("88399fba-b6f5-4e0a-b1d1-fc0668ac7515");
            var record   = new Record().With(r =>
            {
                r.Id         = recordId;
                r.Path       = @"X:\path\to\upload\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.ResourceLocator = "http://www.someexternallinkhere.com";
                });
                r.Publication = new PublicationInfo
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed = true
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 08, 02),
                            User    = TestUserInfo.TestUser
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var store = new InMemoryDatabaseHelper().Create();

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

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

                var uploadService    = new OpenDataPublishingUploadRecordService(db, new RecordValidator());
                var uploadHelperMock = new Mock <IOpenDataUploadHelper>();
                var uploader         = new RobotUploader(db, uploadService, uploadHelperMock.Object);

                uploadHelperMock.Setup(x => x.GetHttpRootUrl()).Returns("http://data.jncc.gov.uk");

                uploader.Upload(new List <Record> {
                    record
                });

                var updatedRecord = db.Load <Record>(record.Id);
                updatedRecord.Publication.OpenData.LastAttempt.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.OpenData.LastAttempt.Message.Should().BeNull();
                updatedRecord.Publication.OpenData.LastSuccess.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.OpenData.LastSuccess.Message.Should().BeNull();
                updatedRecord.Gemini.MetadataDate.Should().Be(testTime);
                updatedRecord.Gemini.ResourceLocator.Should().Be("http://www.someexternallinkhere.com");
                uploadHelperMock.Verify(x => x.UploadAlternativeResources(record), Times.Never);
                uploadHelperMock.Verify(x => x.UploadDataFile(record.Id, record.Path), Times.Never);
                uploadHelperMock.Verify(x => x.UploadMetadataDocument(record), Times.Once);
                uploadHelperMock.Verify(x => x.UploadWafIndexDocument(record), Times.Once);

                Clock.CurrentUtcDateTimeGetter = currentTime;
            }
        }
        public void successful_upload_with_additional_resources()
        {
            var record = new Record().With(r =>
            {
                r.Id         = new Guid("eb189a2f-ebce-4232-8dc6-1ad486cacf21");
                r.Path       = @"X:\path\to\upload\test";
                r.Validation = Validation.Gemini;
                r.Gemini     = Library.Example().With(m =>
                {
                    m.ResourceLocator = null;
                });
                r.Publication = new PublicationInfo
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Assessment = new OpenDataAssessmentInfo
                        {
                            Completed = true
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 08, 02),
                            User    = TestUserInfo.TestUser
                        },
                        Resources = new List <Resource> {
                            new Resource {
                                Path = "x:\\test\\path"
                            }
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var store = new InMemoryDatabaseHelper().Create();

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

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

                var uploadService    = new OpenDataPublishingUploadRecordService(db, new RecordValidator());
                var uploadHelperMock = new Mock <IOpenDataUploadHelper>();
                var uploader         = new RobotUploader(db, uploadService, uploadHelperMock.Object);

                uploadHelperMock.Setup(x => x.GetHttpRootUrl()).Returns("http://data.jncc.gov.uk");

                uploader.Upload(new List <Record> {
                    record
                });

                var updatedRecord = db.Load <Record>(record.Id);
                updatedRecord.Publication.OpenData.LastAttempt.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.OpenData.LastAttempt.Message.Should().BeNull();
                updatedRecord.Publication.OpenData.LastSuccess.DateUtc.Should().Be(testTime);
                updatedRecord.Publication.OpenData.LastSuccess.Message.Should().BeNull();
                updatedRecord.Gemini.MetadataDate.Should().Be(testTime);
                updatedRecord.Gemini.ResourceLocator.Should().BeNull();
                uploadHelperMock.Verify(x => x.UploadAlternativeResources(record), Times.Once);
                uploadHelperMock.Verify(x => x.UploadDataFile(record.Id, record.Path), Times.Never);
                uploadHelperMock.Verify(x => x.UploadMetadataDocument(record), Times.Once);
                uploadHelperMock.Verify(x => x.UploadWafIndexDocument(record), Times.Once);

                Clock.CurrentUtcDateTimeGetter = currentTime;
            }
        }
示例#22
0
        public void fail_when_reassessing_up_to_date_record_at_upload_stage()
        {
            var recordId = new Guid("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
                {
                    OpenData = new OpenDataPublicationInfo
                    {
                        Publishable = true,
                        Assessment  = new OpenDataAssessmentInfo
                        {
                            Completed       = true,
                            CompletedOnUtc  = new DateTime(2017, 07, 21),
                            CompletedByUser = new UserInfo
                            {
                                DisplayName = "Pete",
                                Email       = "*****@*****.**"
                            },
                            InitialAssessmentWasDoneOnSpreadsheet = false
                        },
                        SignOff = new OpenDataSignOffInfo
                        {
                            DateUtc = new DateTime(2017, 07, 29)
                        },
                        LastAttempt = new PublicationAttempt
                        {
                            DateUtc = new DateTime(2017, 07, 30)
                        }
                    }
                };
                r.Footer = new Footer();
            });

            var store = new InMemoryDatabaseHelper().Create();

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

                var publishingController = GetTestOpenDataPublishingController(db);

                var request = new AssessmentRequest
                {
                    Id = record.Id
                };

                Action a = () => publishingController.Assess(request);
                a.ShouldThrow <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 openDataInfo = resultRecord.Publication.OpenData;
                openDataInfo.Should().NotBeNull();
                openDataInfo.Assessment.Completed.Should().BeTrue();
                openDataInfo.Assessment.CompletedByUser.DisplayName.Should().Be("Pete");
                openDataInfo.Assessment.CompletedByUser.Email.Should().Be("*****@*****.**");
                openDataInfo.Assessment.CompletedOnUtc.Should().Be(new DateTime(2017, 07, 21));
                resultRecord.Gemini.MetadataDate.Should().NotBe(openDataInfo.Assessment.CompletedOnUtc);
            }
        }