Esempio n. 1
0
        /// <summary>
        /// Preps and calls the Flip API to encode a video.
        /// </summary>
        /// <param name="sasUri">Generated asset Uri with SAS token.</param>
        /// <param name="requestorFlipEncodeCreateDTO">Encode specific data object.</param>
        ///
        /// <returns>A "Video" object.</returns>
        private async Task <Video> CreateVideoAsync(string sasUri, RequestFlipEncodeCreateDTO requestorFlipEncodeCreateDTO)
        {
            // Get or create the TelestreamCloud storage reference to our output container.
            var store = await _telestreamCloudStorageProvider.GetStoreByNameAsync(new Uri(requestorFlipEncodeCreateDTO.OutputContainer)).ConfigureAwait(false);

            var newVideo = new CreateVideoBody
            {
                Profiles  = requestorFlipEncodeCreateDTO.Profiles,
                SourceUrl = sasUri,
                StoreId   = store.Id
            };

            var factory = await GetFactoryByNameAsync(requestorFlipEncodeCreateDTO.FactoryName).ConfigureAwait(false);

            // configure the encode payload for Correlation Vector
            var payload = new FlipPayload()
            {
                OperationContext = requestorFlipEncodeCreateDTO.OperationContext,
                FactoryId        = factory.Id,
                OutputContainer  = requestorFlipEncodeCreateDTO.OutputContainer
            };

            newVideo.Payload = JsonConvert.SerializeObject(payload);

            try
            {
                var video = await _telestreamCloudClientProvider.FlipApi.CreateVideoAsync(factory.Id, newVideo).ConfigureAwait(false);

                return(video);
            }
            catch (ApiException ae)
            {
                throw new GridwichFlipApiException("Error calling CreateVideoAsync.", requestorFlipEncodeCreateDTO.OperationContext, ae);
            }
        }
        public async Task HandleAsync_ShouldReturnTrueAndNotLog_WhenNoErrorsFailedEncode()
        {
            // Arrange
            var payload = new FlipPayload()
            {
                OperationContext = testOpCtx,
                FactoryId        = "424242",
                OutputContainer  = "https://someaccount.blob.core.windows.net/somecontainer"
            };
            var flipEncodeCompleteData = new FlipEncodingCompleteData()
            {
                EncodingId       = "444",
                EncodingStatus   = "777",
                OriginalFilename = "bbb.mp4",
                EventName        = "flip",
                ServiceName      = "flip",
                VideoId          = "999",
                VideoPayload     = payload,
            };
            var appInsightsUri = new Uri("https://www.appinsights.com");

            var eventToPublish = new EventGridEvent()
            {
                Id          = Guid.NewGuid().ToString(),
                Data        = JObject.FromObject(flipEncodeCompleteData),
                EventTime   = DateTime.Now,
                EventType   = ExternalEventTypes.FlipEncodingComplete,
                Subject     = $"/EncodeCompleted/sagaid",
                DataVersion = "1.0",
            };

            var expectedEventToPublishCaptureMatch = new CaptureMatch <EventGridEvent>(x =>
            {
                // Assert values in the object passed to the publisher:
                x.EventType.ShouldBe(CustomEventTypes.ResponseFailure);
            });

            // Arrange Mocks
            Mock.Get(_eventGridPublisher).Setup(x => x.PublishEventToTopic(Capture.With(expectedEventToPublishCaptureMatch)))
            .ReturnsAsync(true);
            Mock.Get(_logger)
            .Setup(x => x.LogEventObject(
                       out appInsightsUri,
                       LogEventIds.EncodeCompleteFailure,
                       It.IsAny <object>()));
            Mock.Get(_flipService)
            .Setup(x => x.GetEncodeInfo(It.IsAny <FlipEncodingCompleteData>()))
            .Returns(new Telestream.Cloud.Flip.Model.Encoding {
                ErrorClass = "ErrorClass", ErrorMessage = "ErrorMessage"
            });

            // Act
            var handleAsyncResult = await _handler.HandleAsync(eventToPublish).ConfigureAwait(false);

            // Assert
            handleAsyncResult.ShouldBe(true, "handleAsync should always return false");
        }