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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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 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));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public void Initializer()
        {
            _getTaskResponse = new Mock<IRestResponse>();
            _getEntityResponse = new Mock<IRestResponse>();
            _setStatusResponse = new Mock<IRestResponse>();
            _deleteResponse = new Mock<IRestResponse>();
            _restClient = new Mock<IRestClient>();

           _action = null;

            var container = new Container(new ContainerOptions()
            {
                AllowOverridingRegistrations = true
            });
            var initiolizer = new IoCInitializer(_restClient.Object);
            initiolizer.Initialize(container);
            
            container.Register<IFileSystem>(() => new FakeFileSystem());

            _manager = container.GetInstance<EncodeManager>();
            _token = container.GetInstance<CancellationTokenSource>();
        }
        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);
        }
Esempio n. 8
0
        public void Initializer()
        {
            _getTaskResponse   = new Mock <IRestResponse>();
            _getEntityResponse = new Mock <IRestResponse>();
            _setStatusResponse = new Mock <IRestResponse>();
            _deleteResponse    = new Mock <IRestResponse>();
            _restClient        = new Mock <IRestClient>();

            _action = null;

            var container = new Container(new ContainerOptions()
            {
                AllowOverridingRegistrations = true
            });
            var initiolizer = new IoCInitializer(_restClient.Object);

            initiolizer.Initialize(container);

            container.Register <IFileSystem>(() => new FakeFileSystem());

            _manager = container.GetInstance <EncodeManager>();
            _token   = container.GetInstance <CancellationTokenSource>();
        }
Esempio n. 9
0
        private static void Start()
        {
            daemon = Task.Run(() =>
            {
                while (true)
                {
                    Thread.Sleep(1000);

                    FileItem fileItem;

                    if (!queueFileItems.TryDequeue(out fileItem))
                    {
                        continue;
                    }

                    CurrentPositionInQueue++;

                    // encode video
                    bool success = EncodeManager.Encode(fileItem);

                    if (success)
                    {
                        if (fileItem.ModeSprite)
                        {
                            string[] files    = SpriteManager.GetListImageFrom(fileItem.FilePath); // récupération des images
                            string outputPath = TempFileManager.GetNewTempFilePath();              // nom du fichier sprite
                            SpriteManager.CombineBitmap(files, outputPath);                        // création du sprite
                            TempFileManager.SafeDeleteTempFiles(fileItem.FilePath);                // suppression des images
                            fileItem.FilePath = outputPath;                                        // réaffectation chemin sprite
                        }

                        IpfsDaemon.Queue(fileItem);
                    }
                }
            });
        }