Ejemplo n.º 1
0
        public void EncodeScreenshostTaskTest()
        {
            //Arrange
            var taskData = new EncodeTaskData()
            {
                TaskId = TaskId
            };
            var encodeData = new ScreenshotEncodeData()
            {
                FileId          = ConfigurationManager.AppSettings.Get("TestVideo"),
                ContentType     = "image/jpeg",
                ScreenshotParam = new ScreenshotParam()
                {
                    TimeOffset = 1
                }
            };

            var serializer     = new JsonSerializer();
            var jsonEncodeData = serializer.Serialize(encodeData);
            var jsonTaskData   = serializer.Serialize(taskData);
            var getTaskHeaders = ScreenshotGetTaskResponseHeaders(Resource);

            ResponseSetup(jsonTaskData, jsonEncodeData, getTaskHeaders);
            RestClientSetup(Resource);

            //Act
            var task = _manager.Start();

            task.Wait();

            Trace.WriteLine(_deleteRequest.Parameters.FirstOrDefault(p => p.Name == EncoderStatusParameters.Result).Value);

            //Assert
            Assert.IsTrue(_deleteRequest.Parameters.Any(p => p.Name == EncoderStatusParameters.Result && (EncoderState)p.Value == EncoderState.Completed));
        }
Ejemplo n.º 2
0
        public TaskData GetTaskData(IRestResponse response)
        {
            EncodeTaskData encodeTaskData = _deserializer.EncodeTaskDataDeserealize(response);
            string         resource       = GetHeaderValue(response, HeaderParameters.Location);
            string         contentType    = GetHeaderValue(response, HeaderParameters.ContentType);
            TypeOfTask     type           = GetTypeOfTask(contentType);
            var            taskData       = new TaskData
            {
                Id       = encodeTaskData.TaskId,
                Resource = resource,
                Type     = type
            };

            return(taskData);
        }
Ejemplo n.º 3
0
        public void EncodeMp4TaskTest()
        {
            //Arrange
            var taskData = new EncodeTaskData()
            {
                TaskId = TaskId
            };
            var encodeData = new VideoEncodeData()
            {
                FileId      = ConfigurationManager.AppSettings.Get("TestVideo"),
                ContentType = "video/mp4",
                AudioParam  = new AudioParam()
                {
                    AudioCodec   = MetadataConstant.AacCodec,
                    AudioBitrate = 64000
                },
                VideoParam = new VideoParam()
                {
                    VideoWidth  = 480,
                    VideoHeight = 360,

                    VideoCodec     = MetadataConstant.AvcCodec,
                    VideoBitrate   = 500000,
                    VideoProfile   = MetadataConstant.AvcMainProfile,
                    MediaContainer = MetadataConstant.Mp4Container,
                    FrameRate      = 25,
                    KeyFrameRate   = 10
                }
            };

            var serializer     = new JsonSerializer();
            var jsonEncodeData = serializer.Serialize(encodeData);
            var jsonTaskData   = serializer.Serialize(taskData);
            var getTaskHeaders = VideoGetTaskResponseHeaders(Resource);

            ResponseSetup(jsonTaskData, jsonEncodeData, getTaskHeaders);
            RestClientSetup(Resource);

            //Act
            var task = _manager.Start();

            task.Wait();

            Trace.WriteLine(_deleteRequest.Parameters.FirstOrDefault(p => p.Name == EncoderStatusParameters.Result).Value);

            //Assert
            Assert.IsTrue(_deleteRequest.Parameters.Any(p => p.Name == EncoderStatusParameters.Result && (EncoderState)p.Value == EncoderState.Completed));
        }
Ejemplo n.º 4
0
        public void FfmpegHangingTest()
        {
            //Arrange
            var taskData = new EncodeTaskData()
            {
                TaskId = TaskId
            };
            var encodeData = new VideoEncodeData()
            {
                FileId      = ConfigurationManager.AppSettings.Get("HangingVideo"),
                ContentType = "video/webm",
                AudioParam  = new AudioParam()
                {
                    AudioCodec   = MetadataConstant.VorbisCodec,
                    AudioBitrate = 128000,
                },
                VideoParam = new VideoParam()
                {
                    VideoWidth  = 480,
                    VideoHeight = 360,

                    VideoCodec     = MetadataConstant.Vp8Codec,
                    VideoBitrate   = 500000,
                    MediaContainer = MetadataConstant.WebmContainer,
                    FrameRate      = 25,
                    KeyFrameRate   = 10
                }
            };

            var serializer     = new JsonSerializer();
            var jsonEncodeData = serializer.Serialize(encodeData);
            var jsonTaskData   = serializer.Serialize(taskData);
            var getTaskHeaders = VideoGetTaskResponseHeaders(Resource);

            ResponseSetup(jsonTaskData, jsonEncodeData, getTaskHeaders);
            RestClientSetup(Resource);

            //Act
            var task = _manager.Start();

            task.Wait();

            Trace.WriteLine(_deleteRequest.Parameters.FirstOrDefault(p => p.Name == EncoderStatusParameters.Result).Value);

            //Assert
            //Assert.IsTrue(_setStatusRequest.Parameters.Any(p=>p.Name==ProcessStatusParameters.State && (ProcessState)p.Value==ProcessState.Hanging));
            Assert.IsTrue(_deleteRequest.Parameters.Any(p => p.Name == EncoderStatusParameters.Result && (EncoderState)p.Value == EncoderState.Cancelled));
        }
        public void TaskDataDeserealizeTest()
        {
            //Arrange
            var deserializer       = new Mock <IDeserializer>();
            var response           = new Mock <IRestResponse>();
            var encodeDeserializer = new EncodeDeserializer(deserializer.Object);

            var data = new EncodeTaskData();

            deserializer.Setup(m => m.Deserialize <EncodeTaskData>(response.Object)).Returns(data);

            //Act
            var encodeTaskData = encodeDeserializer.EncodeTaskDataDeserealize(response.Object);

            //Assert
            Assert.AreEqual(data, encodeTaskData);
        }
Ejemplo n.º 6
0
        public void FfmpegErrorTest()
        {
            //Arrange
            var taskData = new EncodeTaskData()
            {
                TaskId = TaskId
            };
            var errorEncodeData = new VideoEncodeData()
            {
                FileId     = ConfigurationManager.AppSettings.Get("TestVideo"),
                VideoParam = new VideoParam()
                {
                    MediaContainer = MetadataConstant.Mp4Container
                },
                AudioParam = new AudioParam()
                {
                    AudioCodec = MetadataConstant.AacCodec
                }
            };

            var serializer     = new JsonSerializer();
            var jsonEncodeData = serializer.Serialize(errorEncodeData);
            var jsonTaskData   = serializer.Serialize(taskData);
            var getTaskHeaders = VideoGetTaskResponseHeaders(Resource);

            ResponseSetup(jsonTaskData, jsonEncodeData, getTaskHeaders);
            RestClientSetup(Resource);

            _restClient.Setup(m => m.Execute(_deleteRequest)).Callback(() => _token.Cancel());

            //Act
            var task = _manager.Start();

            task.Wait();

            Trace.WriteLine(_deleteRequest.Parameters.FirstOrDefault(p => p.Name == EncoderStatusParameters.Result).Value);

            //Assert
            Assert.IsTrue(_deleteRequest.Parameters.Any(p => p.Name == EncoderStatusParameters.Result && (EncoderState)p.Value == EncoderState.Failed));
        }
Ejemplo n.º 7
0
        public void GetTaskTest()
        {
            //Arrange
            const string resource = "resource";
            const string taskId   = "taskId";

            var response = new Mock <IRestResponse>();
            var headers  = new List <Parameter>()
            {
                new Parameter()
                {
                    Name  = HeaderParameters.ContentType,
                    Value = String.Format("{0};bla-bla", ContentType.TaskVideo)
                },
                new Parameter()
                {
                    Name  = HeaderParameters.Location,
                    Value = resource
                }
            };
            var encodeTaskData = new EncodeTaskData()
            {
                TaskId = taskId
            };

            response.Setup(p => p.Headers).Returns(headers);
            _deserializer.Setup(m => m.EncodeTaskDataDeserealize(response.Object)).Returns(encodeTaskData);

            //Act
            var taskData = _helper.GetTaskData(response.Object);

            //Assert
            Assert.AreEqual(TypeOfTask.Video, taskData.Type);
            Assert.AreEqual(resource, taskData.Resource);
            Assert.AreEqual(taskId, taskData.Id);
        }