public async Task LmiWebhookReceiverServiceReportAllReturnsSuccessfully() { // Arrange const HttpStatusCode expectedResult = HttpStatusCode.Created; var dummyFullDeltaReportModel = A.Dummy <FullDeltaReportModel>(); var dummyDeltaReports = A.CollectionOfDummy <DeltaReportModel>(publishedJobGroupClientOptions.MaxReportsKept + 1); var dummyDeltaReportSocs = A.CollectionOfDummy <DeltaReportSocModel>(1); dummyFullDeltaReportModel.DeltaReportSocs = A.CollectionOfFake <DeltaReportSocModel>(1).ToList(); A.CallTo(() => fakeJobGroupDataService.GetAllAsync()).Returns(dummyFullDeltaReportModel); A.CallTo(() => fakeDeltaReportDocumentService.UpsertAsync(A <DeltaReportModel> .Ignored)).Returns(HttpStatusCode.Created); A.CallTo(() => fakeDeltaReportSocDocumentService.UpsertAsync(A <DeltaReportSocModel> .Ignored)).Returns(HttpStatusCode.Created); A.CallTo(() => fakeDeltaReportDocumentService.GetAllAsync(A <string> .Ignored)).Returns(dummyDeltaReports); A.CallTo(() => fakeDeltaReportDocumentService.DeleteAsync(A <Guid> .Ignored)).Returns(true); A.CallTo(() => fakeDeltaReportSocDocumentService.GetAsync(A <Expression <Func <DeltaReportSocModel, bool> > > .Ignored)).Returns(dummyDeltaReportSocs); A.CallTo(() => fakeDeltaReportSocDocumentService.DeleteAsync(A <Guid> .Ignored)).Returns(true); // Act var result = await lmiWebhookReceiverService.ReportAll().ConfigureAwait(false); // Assert A.CallTo(() => fakeJobGroupDataService.GetAllAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeSocDeltaService.DetermineDelta(A <FullDeltaReportModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDeltaReportDocumentService.UpsertAsync(A <DeltaReportModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDeltaReportSocDocumentService.UpsertAsync(A <DeltaReportSocModel> .Ignored)).MustHaveHappened(dummyFullDeltaReportModel.DeltaReportSocs !.Count, Times.Exactly); A.CallTo(() => fakeEventGridService.SendEventAsync(A <EventGridEventData> .Ignored, A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDeltaReportDocumentService.GetAllAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDeltaReportDocumentService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappened(dummyDeltaReports.Count - publishedJobGroupClientOptions.MaxReportsKept, Times.Exactly); A.CallTo(() => fakeDeltaReportSocDocumentService.GetAsync(A <Expression <Func <DeltaReportSocModel, bool> > > .Ignored)).MustHaveHappened(dummyDeltaReports.Count - publishedJobGroupClientOptions.MaxReportsKept, Times.Exactly); A.CallTo(() => fakeDeltaReportSocDocumentService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappened((dummyDeltaReports.Count - publishedJobGroupClientOptions.MaxReportsKept) * dummyDeltaReportSocs.Count, Times.Exactly); Assert.Equal(expectedResult, result); }
public async Task EventGridServiceSendEventReturnsSuccess() { // arrange var dummyEventGridEventData = A.Dummy <EventGridEventData>(); // act await eventGridService.SendEventAsync(dummyEventGridEventData, "a subject", "an event type").ConfigureAwait(false); // assert A.CallTo(() => fakeEventGridClientService.SendEventAsync(A <List <EventGridEvent> > .Ignored, A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); }
public async Task PostDraftEventAsync(string displayText, Uri?apiEndpoint, Guid?contentId) { logger.LogInformation($"Posting to event grid for: {displayText}"); var eventGridEventData = new EventGridEventData { ItemId = contentId.ToString(), Api = apiEndpoint?.ToString(), DisplayText = displayText, VersionId = Guid.NewGuid().ToString(), Author = eventGridClientOptions.SubjectPrefix, }; await eventGridService.SendEventAsync(eventGridEventData, eventGridClientOptions.SubjectPrefix, EventTypeDraft).ConfigureAwait(false); }
public Task PostPublishedEventAsync(string displayText, Uri?apiEndpoint, Guid?contentId) { logger.LogInformation($"Posting to event grid for: {displayText}"); var eventGridEventData = new EventGridEventData { ItemId = contentId.ToString(), Api = apiEndpoint?.ToString(), DisplayText = displayText, VersionId = Guid.NewGuid().ToString(), Author = eventGridClientOptions.SubjectPrefix, }; return(eventGridService.SendEventAsync(eventGridEventData, eventGridClientOptions.SubjectPrefix, EventTypePublished)); }
public async Task <HttpStatusCode> DeleteContentAsync(Guid contentId) { var existingContentPageModel = await contentPageService.GetByIdAsync(contentId).ConfigureAwait(false); var result = await eventMessageService.DeleteAsync(contentId).ConfigureAwait(false); if (result == HttpStatusCode.OK && existingContentPageModel != null) { await eventGridService.SendEventAsync(WebhookCacheOperation.Delete, existingContentPageModel).ConfigureAwait(false); contentCacheService.Remove(contentId); } return(result); }
public async Task LmiOrchestrationTriggerPostGraphEventActivityIsSuccessful() { // Arrange var eventGridPostRequest = new EventGridPostRequestModel { ItemId = Guid.NewGuid(), DisplayText = "Display text", EventType = "published", }; // Act await lmiOrchestrationTrigger.PostTransformationEventActivity(eventGridPostRequest).ConfigureAwait(false); // Assert A.CallTo(() => fakeEventGridService.SendEventAsync(A <EventGridEventData> .Ignored, A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); }
public async Task PostTransformationEventActivity([ActivityTrigger] EventGridPostRequestModel?eventGridPostRequest) { _ = eventGridPostRequest ?? throw new ArgumentNullException(nameof(eventGridPostRequest)); logger.LogInformation($"Posting to event grid for: {eventGridPostRequest.DisplayText}: {eventGridPostRequest.EventType}"); var eventGridEventData = new EventGridEventData { ItemId = $"{eventGridPostRequest.ItemId}", Api = eventGridPostRequest.Api, DisplayText = eventGridPostRequest.DisplayText, VersionId = Guid.NewGuid().ToString(), Author = eventGridClientOptions.SubjectPrefix, }; await eventGridService.SendEventAsync(eventGridEventData, eventGridClientOptions.SubjectPrefix, eventGridPostRequest.EventType).ConfigureAwait(false); }
public async Task WebhooksContentServiceProcessContentForSharedContentItemReturnsSuccess() { // Arrange const HttpStatusCode expectedResult = HttpStatusCode.OK; A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <Uri> .Ignored)).Returns(A.Dummy <CmsApiSharedContentModel>()); A.CallTo(() => fakeMapper.Map <ContentItemModel>(A <CmsApiSharedContentModel> .Ignored)).Returns(A.Dummy <ContentItemModel>()); A.CallTo(() => fakeContentItemDocumentService.UpsertAsync(A <ContentItemModel> .Ignored)).Returns(expectedResult); // Act var result = await webhooksContentService.ProcessContentAsync(false, Guid.NewGuid(), null, "https://somewhere.com", MessageContentType.SharedContentItem).ConfigureAwait(false); // Assert A.CallTo(() => fakeJobGroupCacheRefreshService.ReloadAsync(A <Uri> .Ignored)).MustNotHaveHappened(); A.CallTo(() => fakeJobGroupCacheRefreshService.ReloadItemAsync(A <Uri> .Ignored)).MustNotHaveHappened(); A.CallTo(() => fakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeMapper.Map <ContentItemModel>(A <CmsApiSharedContentModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeContentItemDocumentService.UpsertAsync(A <ContentItemModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeJobGroupPublishedRefreshService.ReloadAsync(A <Uri> .Ignored)).MustNotHaveHappened(); A.CallTo(() => fakeJobGroupPublishedRefreshService.ReloadItemAsync(A <Uri> .Ignored)).MustNotHaveHappened(); A.CallTo(() => fakeEventGridService.SendEventAsync(A <EventGridEventData> .Ignored, A <string> .Ignored, A <string> .Ignored)).MustNotHaveHappened(); Assert.Equal(expectedResult, result); }