public async void MediaServicesEncoderErrorCreateAssetTest()
        {
            // Arrange Mocks
            Mock.Get(AmsV3Services)
            .Setup(x => x.CreateTransformIfNotExistByNameAsync(It.IsAny <string>(), It.IsAny <JObject>()));

            Mock.Get(StorageService)
            .Setup(x => x.GetBlobExistsAsync(It.IsAny <Uri>(), It.IsAny <StorageClientProviderContext>()))
            .ReturnsAsync(true);

            Mock.Get(AmsV3Services)
            .Setup(x => x.CreateJobAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TimeBasedEncodeDTO>(), It.IsAny <Dictionary <string, string> >(), It.IsAny <JObject>()));

            Mock.Get(AmsV3Services)
            .Setup(x => x.CreateOrUpdateAssetForContainerAsync(It.IsAny <IEnumerable <Uri> >()))
            .Throws(new Exception());

            // Act
            var amsEncoder = new MediaServicesV3Encoder(Log, StorageService, AmsV3Services);
            ServiceOperationResultEncodeDispatched encodeDispatched = null;
            var exception = await Record.ExceptionAsync(async() =>
            {
                encodeDispatched = await amsEncoder.EncodeCreateAsync(MediaServicesV3TestData.RequestMediaServicesV3EncodeCreateDTO_Is_Expected).ConfigureAwait(true);
            }).ConfigureAwait(true);

            // Assert
            exception.ShouldNotBeNull();
            exception.ShouldBeOfType <GridwichMediaServicesV3CreateAssetException>();
            exception.InnerException.ShouldNotBeNull();
            exception.InnerException.ShouldBeOfType <Exception>();
        }
        public async void EncoderRethrowsFromCreateTransformIfNotExistByNameAsync()
        {
            // Arrange Mocks
            // Note LogEventIds used do not affect this test.
            Mock.Get(AmsV3Services)
            .Setup(x => x.CreateTransformIfNotExistByNameAsync(It.IsAny <string>(), It.IsAny <JObject>()))
            .ThrowsAsync(new GridwichMediaServicesV3ConnectivityException(
                             LogEventIds.MediaServicesV3ConnectionError.Name,
                             LogEventIds.MediaServicesV3ConnectionError));


            Mock.Get(AmsV3Services)
            .Setup(x => x.CreateJobAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TimeBasedEncodeDTO>(), It.IsAny <Dictionary <string, string> >(), It.IsAny <JObject>()));

            Mock.Get(AmsV3Services)
            .Setup(x => x.CreateOrUpdateAssetForContainerAsync(It.IsAny <IEnumerable <Uri> >()))
            .ReturnsAsync("assetname");

            // Act
            var amsEncoder = new MediaServicesV3Encoder(Log, StorageService, AmsV3Services);
            ServiceOperationResultEncodeDispatched encodeDispatched = null;
            var exception = await Record.ExceptionAsync(async() =>
            {
                encodeDispatched = await amsEncoder.EncodeCreateAsync(MediaServicesV3TestData.RequestMediaServicesV3EncodeCreateDTO_Is_Expected).ConfigureAwait(true);
            }).ConfigureAwait(true);

            // Assert
            exception.ShouldNotBeNull();
            exception.ShouldBeOfType <GridwichMediaServicesV3CreateTransformException>();
            exception.InnerException.ShouldNotBeNull();
            exception.InnerException.ShouldBeOfType <GridwichMediaServicesV3ConnectivityException>();
        }
        public async void EncoderLogsAndThrowsIfInputBlobsDoNotExist()
        {
            // Arrange Mocks
            Mock.Get(AmsV3Services)
            .Setup(x => x.CreateTransformIfNotExistByNameAsync(It.IsAny <string>(), It.IsAny <JObject>()));

            var mockUriToAppearNonexistent = new Uri(MediaServicesV3TestData.RequestMediaServicesV3EncodeCreateDTO_Is_Expected.Inputs.First().BlobUri);

            Mock.Get(StorageService)
            .Setup(x => x.GetBlobExistsAsync(mockUriToAppearNonexistent, It.IsAny <StorageClientProviderContext>()))
            .ReturnsAsync(false);

            // Act
            var amsEncoder = new MediaServicesV3Encoder(Log, StorageService, AmsV3Services);
            ServiceOperationResultEncodeDispatched encodeDispatched = null;
            var exception = await Record.ExceptionAsync(async() =>
            {
                encodeDispatched = await amsEncoder.EncodeCreateAsync(MediaServicesV3TestData.RequestMediaServicesV3EncodeCreateDTO_Is_Expected).ConfigureAwait(true);
            }).ConfigureAwait(true);

            // Assert
            exception.ShouldNotBeNull();
            exception.ShouldBeOfType <GridwichMediaServicesV3Exception>();
            Mock.Get(Log).Verify(x => x.LogEventObject(LogEventIds.MediaServicesV3AttemptToUseNonexistentBlob,
                                                       It.IsAny <object>()), Times.Once, "The exception should be logged.");
        }
Example #4
0
        /// <inheritdoc/>
        protected override async Task <ResponseBaseDTO> DoWorkAsync(RequestMediaServicesV3EncodeCreateDTO eventData, string eventType)
        {
            // Call the service that will do work:
            ServiceOperationResultEncodeDispatched encodeDispatched = await _mediaServicesV3Encoder.EncodeCreateAsync(eventData).ConfigureAwait(false);

            // Convert the service operation result into a success DTO:
            return(new ResponseEncodeDispatchedDTO(CustomEventTypes.ResponseEncodeMediaServicesV3Dispatched)
            {
                WorkflowJobName = encodeDispatched.WorkflowJobName,
                EncoderContext = encodeDispatched.EncoderContext,
                OperationContext = encodeDispatched.OperationContext,
            });
        }
        public async void EncodeCreateAsync_Is_As_ExpectedAsync(
            RequestMediaServicesV3EncodeCreateDTO encodeCreateDTO,
            ServiceOperationResultEncodeDispatched expectedEncodeDispatched,
            Type expectedExceptionType)
        {
            // Arrange
            string expectedOutputAssetName = GetExpectedOutputAssetName(encodeCreateDTO);

            output.WriteLine($"Using expectedOutputAssetName: {expectedOutputAssetName}");

            // Arrange Mocks
            Mock.Get(AmsV3Services)
            .Setup(x => x.CreateTransformIfNotExistByNameAsync(It.IsAny <string>(), It.IsAny <JObject>()));

            Mock.Get(StorageService)
            .Setup(x => x.GetBlobExistsAsync(It.IsAny <Uri>(), It.IsAny <StorageClientProviderContext>()))
            .ReturnsAsync(true);

            Mock.Get(AmsV3Services)
            .Setup(x => x.CreateJobAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TimeBasedEncodeDTO>(), It.IsAny <Dictionary <string, string> >(), It.IsAny <JObject>()));

            Mock.Get(AmsV3Services)
            .Setup(x => x.CreateOrUpdateAssetForContainerAsync(It.IsAny <IEnumerable <Uri> >()))
            .ReturnsAsync(expectedOutputAssetName);

            // Act
            var amsEncoder = new MediaServicesV3Encoder(Log, StorageService, AmsV3Services);
            ServiceOperationResultEncodeDispatched encodeDispatched = null;
            var exception = await Record.ExceptionAsync(async() =>
            {
                encodeDispatched = await amsEncoder.EncodeCreateAsync(encodeCreateDTO).ConfigureAwait(true);
            }).ConfigureAwait(true);

            // Assert
            if (expectedExceptionType == null)
            {
                // Success cases
                exception.ShouldBeNull();
            }
            else
            {
                // Failure cases
                exception.ShouldBeOfType(expectedExceptionType);
            }

            if (expectedEncodeDispatched != null)
            {
                // Success cases
                if (MediaServicesV3TestData.ServiceOperationResultEncodeDispatched_Is_Expected.WorkflowJobName == null)
                {
                    encodeDispatched.WorkflowJobName.ShouldBeNull();
                }
                else
                {
                    encodeDispatched.WorkflowJobName.StartsWith(expectedOutputAssetName);
                }

                if (MediaServicesV3TestData.ServiceOperationResultEncodeDispatched_Is_Expected.EncoderContext == null)
                {
                    encodeDispatched.EncoderContext.ShouldBeNull();
                }
                else
                {
                    encodeDispatched.EncoderContext.ShouldBe(MediaServicesV3TestData.ServiceOperationResultEncodeDispatched_Is_Expected.EncoderContext);
                }

                if (MediaServicesV3TestData.ServiceOperationResultEncodeDispatched_Is_Expected.OperationContext == null)
                {
                    encodeDispatched.OperationContext.ShouldBeNull();
                }
                else
                {
                    encodeDispatched.OperationContext.ShouldBe(MediaServicesV3TestData.ServiceOperationResultEncodeDispatched_Is_Expected.OperationContext);
                }
            }
            else
            {
                // Failure cases
                encodeDispatched.ShouldBeNull();
            }
        }