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)); }
public void StartMethodTest() { //Arrange const int quantityMethodCall = 1; var count = 0; var taskStatic = new Mock<TaskStaticWrapper>(); var pipeline = new Mock<IEncodePipeline>(); var tokenSource = new CancellationTokenSource(); var manager = new EncodeManager(pipeline.Object, tokenSource, taskStatic.Object); pipeline.Setup(m => m.Run()).Callback(() => { count++; if (quantityMethodCall == count) { tokenSource.Cancel(); } }); //Act var task = manager.Start(); task.Wait(); //Assert pipeline.Verify(m => m.Run(), Times.Exactly(quantityMethodCall)); }
public void StartMethodSleeppWhenThrowNotContentExceptionTest() { //Arrange var taskStatic = new Mock <TaskStaticWrapper>(); var pipeline = new Mock <IEncodePipeline>(); var tokenSource = new CancellationTokenSource(); var manager = new EncodeManager(pipeline.Object, tokenSource, taskStatic.Object); taskStatic.Setup(m => m.Delay(5000)).Returns(() => { var tcs = new TaskCompletionSource <object>(); tcs.SetResult(null); return(tcs.Task); }); pipeline.Setup(m => m.Run()).Callback(() => { tokenSource.Cancel(); throw new NoContentException(); }); //Act var task = manager.Start(); task.Wait(); //Assert taskStatic.Verify(m => m.Delay(5000)); }
public void StartMethodTest() { //Arrange const int quantityMethodCall = 1; var count = 0; var taskStatic = new Mock <TaskStaticWrapper>(); var pipeline = new Mock <IEncodePipeline>(); var tokenSource = new CancellationTokenSource(); var manager = new EncodeManager(pipeline.Object, tokenSource, taskStatic.Object); pipeline.Setup(m => m.Run()).Callback(() => { count++; if (quantityMethodCall == count) { tokenSource.Cancel(); } }); //Act var task = manager.Start(); task.Wait(); //Assert pipeline.Verify(m => m.Run(), Times.Exactly(quantityMethodCall)); }
public void StartMethodExceptionHandleTest() { //Arrange var taskStatic = new Mock<TaskStaticWrapper>(); var pipeline = new Mock<IEncodePipeline>(); var tokenSource = new CancellationTokenSource(); var manager = new EncodeManager(pipeline.Object, tokenSource, taskStatic.Object); pipeline.Setup(m => m.Run()).Callback(()=> { tokenSource.Cancel(); throw new Exception(); }); //Act var task = manager.Start(); task.Wait(); //Assert Assert.IsFalse(task.IsFaulted); }
public void StartMethodExceptionHandleTest() { //Arrange var taskStatic = new Mock <TaskStaticWrapper>(); var pipeline = new Mock <IEncodePipeline>(); var tokenSource = new CancellationTokenSource(); var manager = new EncodeManager(pipeline.Object, tokenSource, taskStatic.Object); pipeline.Setup(m => m.Run()).Callback(() => { tokenSource.Cancel(); throw new Exception(); }); //Act var task = manager.Start(); task.Wait(); //Assert Assert.IsFalse(task.IsFaulted); }
public void StartMethodSleeppWhenThrowNotContentExceptionTest() { //Arrange var taskStatic = new Mock<TaskStaticWrapper>(); var pipeline = new Mock<IEncodePipeline>(); var tokenSource = new CancellationTokenSource(); var manager = new EncodeManager(pipeline.Object, tokenSource, taskStatic.Object); taskStatic.Setup(m => m.Delay(5000)).Returns(() => { var tcs = new TaskCompletionSource<object>(); tcs.SetResult(null); return tcs.Task; }); pipeline.Setup(m => m.Run()).Callback(() => { tokenSource.Cancel(); throw new NoContentException(); }); //Act var task = manager.Start(); task.Wait(); //Assert taskStatic.Verify(m=>m.Delay(5000)); }