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; } }
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; } }
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; } }
public void data_rollback_for_unsuccessful_hub_and_gov_publish() { 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 = "dataset"); 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 }, Gov = new GovPublicationInfo { Publishable = true } } }; r.Footer = new Footer(); }); var db = new Mock <IDocumentSession>(); var vocabQueryerMock = new Mock <IVocabQueryer>(); var uploadService = new Mock <IPublishingUploadRecordService>(); 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.Object, redactorMock.Object, uploadService.Object, dataServiceMock.Object, metadataUploaderMock.Object, hubServiceMock.Object); vocabQueryerMock.Setup(x => x.GetVocab(It.IsAny <string>())).Returns(new Vocabulary()); hubServiceMock.Setup(x => x.Publish(It.IsAny <Record>())).Throws(new Exception("test message")); redactorMock.Setup(x => x.RedactRecord(It.IsAny <Record>())).Returns(record); uploader.PublishRecord(record); dataServiceMock.Verify(x => x.CreateDataRollback(It.IsAny <string>()), Times.Once); dataServiceMock.Verify(x => x.UploadDataFile(It.IsAny <string>(), It.IsAny <string>()), Times.Once); hubServiceMock.Verify(x => x.Publish(It.IsAny <Record>()), Times.Once); metadataUploaderMock.Verify(x => x.UploadGeminiXml(It.IsAny <Record>()), Times.Never); metadataUploaderMock.Verify(x => x.UpdateDguIndex(It.IsAny <Record>()), Times.Never); uploadService.Verify(x => x.UpdateGovPublishSuccess(It.IsAny <Record>(), It.IsAny <PublicationAttempt>()), Times.Never); redactorMock.Verify(x => x.RedactRecord(It.IsAny <Record>()), Times.Exactly(1)); dataServiceMock.Verify(x => x.RemoveRollbackFiles(It.IsAny <string>()), Times.Never); dataServiceMock.Verify(x => x.Rollback(It.IsAny <string>()), Times.Once); }