public async void MediaServicesLocatorCreateHandler_Exceptions_Passthrough_Test() { // Arrange var expectedExceptionType = typeof(GridwichPublicationLocatorCreationException); // Arrange Mocks Mock.Get(eventGridPublisher) .Setup(x => x.PublishEventToTopic(It.IsAny <EventGridEvent>())) .ReturnsAsync(true); Mock.Get(mediaServicesV3PublicationService) .Setup(x => x.LocatorCreateAsync( It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TimeBasedFilterDTO>(), It.IsAny <JObject>(), It.IsAny <bool>())) .ThrowsAsync(new GridwichPublicationLocatorCreationException( MediaServicesV3PublicationTestData.GoodAssetName, "Something went wrong.", innerException: new Exception())); // Act ResponseBaseDTO eventReturned = null; var exception = await Record.ExceptionAsync(async() => { eventReturned = await this.handler.TestDoWorkAsync(MediaServicesV3PublicationTestData.RequestMediaServicesLocatorCreateDTO_Is_Expected, CustomEventTypes.RequestMediaservicesLocatorCreate).ConfigureAwait(true); }).ConfigureAwait(true); // Assert exception.ShouldBeOfType(expectedExceptionType); eventReturned.ShouldBeNull(); }
public async void MediaServicesLocatorCreateHandler_DoWorkAsync_Tests(RequestMediaServicesLocatorCreateDTO baseDTO, string expectedCustomEventTypes, Type expectedExceptionType) { // Arrange Mocks Mock.Get(eventGridPublisher) .Setup(x => x.PublishEventToTopic(It.IsAny <EventGridEvent>())) .ReturnsAsync(true); Mock.Get(mediaServicesV3PublicationService) .Setup(x => x.LocatorCreateAsync( It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TimeBasedFilterDTO>(), It.IsAny <JObject>(), It.IsAny <bool>())) .ReturnsAsync(MediaServicesV3PublicationTestData.ServiceOperationResult_Is_Expected); // Act ResponseBaseDTO eventReturned = null; var exception = await Record.ExceptionAsync(async() => { eventReturned = await this.handler.TestDoWorkAsync(baseDTO, CustomEventTypes.RequestMediaservicesLocatorCreate).ConfigureAwait(true); }).ConfigureAwait(true); // Assert if (expectedExceptionType == null) { // Success cases exception.ShouldBeNull(); } else { // Failure cases exception.ShouldBeOfType(expectedExceptionType); eventReturned.ShouldBeNull(); } if (!string.IsNullOrWhiteSpace(expectedCustomEventTypes)) { // Success cases eventReturned.ShouldNotBeNull(); eventReturned.ReturnEventType.ShouldBe(expectedCustomEventTypes); } else { // Failure cases eventReturned.ShouldBeNull(); } }
/// <summary> /// Get an event grid event based on the input parameters. This method accepts any <see cref="ResponseBaseDTO" />. /// Event type will be extracted from the DTO. /// </summary> /// <param name="anyDto">Any dto.</param> /// <param name="subject">The subject.</param> /// <param name="appendEventIdToSubject">if set to <c>true</c> [append event identifier to subject].</param> /// <param name="dataVersion">The data version.</param> /// <param name="locator">The locator.</param> /// <returns> /// An <see cref="EventGridEvent" /> /// </returns> public EventGridEvent GetEventGridEventFromResponseDTO(ResponseBaseDTO anyDto, string subject, bool appendEventIdToSubject = true, string dataVersion = "1.0", EventLocator locator = null) { if (anyDto == null) { throw new ArgumentNullException(nameof(anyDto)); } var eventGridEventId = Guid.NewGuid().ToString(); var eventToPublish = new EventGridEvent { Id = eventGridEventId, Data = anyDto, EventTime = DateTime.UtcNow, EventType = anyDto.ReturnEventType, Subject = appendEventIdToSubject ? $"{subject}/{eventGridEventId}" : subject, DataVersion = dataVersion, }; return(locator == null ? eventToPublish : eventToPublish.DecorateWith(locator)); }