Exemplo n.º 1
0
        public void CreateTest()
        {
            this._context = this.InitContext().Result;
            Workflow newWorkflow = new Workflow()
            {
                id           = "test123456",
                inputFolder  = "path\\to\\test123456",
                outputFolder = "path\\to\\test123456\\output\\",
                active       = true,
                name         = "workflow_test123456",
                processor    = "processor_test123456",
                interval     = 1,
                message      = ""
            };

            this._context.Workflows.Add(newWorkflow);
            this._context.SaveChanges();

            LimsServer.Entities.Task tsk = new LimsServer.Entities.Task()
            {
                id         = "001",
                workflowID = "test123456",
                start      = DateTime.Now.AddMinutes(5)
            };
            TaskService ts     = new TaskService(this._context);
            var         result = ts.Create(tsk).Result;

            Assert.NotNull(result.message);
        }
Exemplo n.º 2
0
        private async Task <DataContext> InitContext()
        {
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var context = new DataContext(options);

            for (int i = 0; i < 10; i++)
            {
                var task = new LimsServer.Entities.Task
                {
                    id         = i.ToString(),
                    workflowID = i.ToString(),
                    taskID     = i.ToString(),
                    inputFile  = "",
                    outputFile = "",
                    start      = DateTime.Now.AddMinutes(1),
                    status     = "SCHEDULED",
                    message    = ""
                };
                await context.Tasks.AddAsync(task);
            }
            await context.SaveChangesAsync();

            return(context);
        }
Exemplo n.º 3
0
        public void DeleteTest(bool expected)
        {
            this._context = this.InitContext().Result;

            LimsServer.Entities.Task tsk = new LimsServer.Entities.Task()
            {
                id         = "1",
                workflowID = "0",
                start      = DateTime.Now.AddMinutes(15),
                taskID     = null,
                status     = "SCHEDULED"
            };
            this._context.Tasks.Add(tsk);
            this._context.SaveChanges();

            WorkflowService wkService = new WorkflowService(this._context);
            var             firstWk   = this._context.Workflows.FirstAsync().Result;

            var result = wkService.Delete(firstWk.id).Result;

            Assert.True(result);                                // Returned results check

            var dbWorkflow = this._context.Workflows.SingleAsync(wk => wk.id == firstWk.id).Result;

            Assert.Equal(dbWorkflow.active, expected);          // Database update check
        }
Exemplo n.º 4
0
        public void DataCheckTest()
        {
            this._context = this.InitContext().Result;
            TaskServiceTest tst = new TaskServiceTest();

            tst.FileSetup();

            Workflow newWorkflow = new Workflow()
            {
                id           = "test12345678",
                inputFolder  = "app_files\\TestFiles\\Input",
                outputFolder = "app_files\\TestFiles\\Output",
                active       = true,
                name         = "workflow_test123456",
                processor    = "masslynx",
                interval     = 10,
                message      = ""
            };

            this._context.Workflows.Add(newWorkflow);

            LimsServer.Entities.Task tsk = new LimsServer.Entities.Task()
            {
                id         = "001",
                workflowID = "test12345678",
                start      = DateTime.Now.AddMinutes(5),
                taskID     = "1234567890",
                status     = "SCHEDULED"
            };
            LimsServer.Entities.Task tsk2 = new LimsServer.Entities.Task()
            {
                id         = "002",
                workflowID = "test12345678",
                start      = DateTime.Now.AddMinutes(5),
                taskID     = "1234567890",
                status     = "SCHEDULED"
            };
            this._context.Tasks.Add(tsk);
            this._context.Tasks.Add(tsk2);
            this._context.SaveChanges();

            TaskService ts = new TaskService(this._context);

            var tsResult = ts.RunTask(tsk.id);

            DataBackup db      = new DataBackup();
            var        results = db.DataCheck("000", this._context);

            Assert.Contains("No task ID found", results);

            var results2 = db.DataCheck(tsk.id, this._context);

            Assert.Equal("", "");

            var results3 = db.DataCheck(tsk2.id, this._context);

            Assert.Contains("Backup expired.", results3);
        }
Exemplo n.º 5
0
        public void UpdateTest(string expected)
        {
            this._context = this.InitContext().Result;

            LimsServer.Entities.Task tsk = new LimsServer.Entities.Task()
            {
                id         = "1",
                workflowID = "5",
                start      = DateTime.Now.AddMinutes(15),
                taskID     = null,
                status     = "SCHEDULED"
            };
            this._context.Tasks.Add(tsk);
            LimsServer.Entities.Task tsk2 = new LimsServer.Entities.Task()
            {
                id         = "2",
                workflowID = "5",
                start      = DateTime.Now.AddMinutes(15),
                taskID     = null,
                status     = "PENDING"
            };
            this._context.Tasks.Add(tsk2);
            this._context.SaveChanges();

            WorkflowService wkService   = new WorkflowService(this._context);
            Workflow        newWorkflow = new Workflow()
            {
                id           = "5",
                inputFolder  = "path\\to\\test123456",
                outputFolder = "path\\to\\test123456\\output\\",
                active       = true,
                name         = "workflow_test123456",
                processor    = "processor_test123456",
                interval     = 1,
                message      = ""
            };
            var result = wkService.Update(newWorkflow, true).Result;

            Assert.True(result);                                // Returned results check

            var dbWorkflow = this._context.Workflows.SingleAsync(wk => wk.id == newWorkflow.id).Result;

            Assert.Equal(dbWorkflow.name, expected);           // Database update check
        }
Exemplo n.º 6
0
        public void RunTaskTest()
        {
            this.FileSetup();
            this._context = this.InitContext().Result;
            Workflow newWorkflow = new Workflow()
            {
                id           = "test123456",
                inputFolder  = "path\\to\\test123456",
                outputFolder = "path\\to\\test123456\\output\\",
                active       = true,
                name         = "workflow_test123456",
                processor    = "processor_test123456",
                interval     = 10,
                message      = ""
            };

            this._context.Workflows.Add(newWorkflow);
            Workflow newWorkflow2 = new Workflow()
            {
                id           = "test1234567",
                inputFolder  = "app_files\\TestFiles\\Input",
                outputFolder = "app_files\\TestFiles\\Output",
                active       = true,
                name         = "workflow_test123456",
                processor    = "masslynx",
                interval     = 10,
                message      = ""
            };

            this._context.Workflows.Add(newWorkflow2);
            Workflow newWorkflow3 = new Workflow()
            {
                id           = "test12345678",
                inputFolder  = "app_files\\TestFiles\\Input",
                outputFolder = "app_files\\TestFiles\\Output",
                active       = true,
                name         = "workflow_test123456",
                processor    = "picogreen",
                interval     = 10,
                message      = ""
            };

            this._context.Workflows.Add(newWorkflow3);

            LimsServer.Entities.Task tsk = new LimsServer.Entities.Task()
            {
                id         = "001",
                workflowID = "test123456",
                start      = DateTime.Now.AddMinutes(5),
                taskID     = "1234567890",
                status     = "SCHEDULED"
            };
            LimsServer.Entities.Task tsk2 = new LimsServer.Entities.Task()
            {
                id         = "002",
                workflowID = "test123456",
                start      = DateTime.Now.AddMinutes(5),
                taskID     = "12345678901",
                status     = "PENDING"
            };
            LimsServer.Entities.Task tsk3 = new LimsServer.Entities.Task()
            {
                id         = "003",
                workflowID = "test",
                start      = DateTime.Now.AddMinutes(5),
                taskID     = "12345678902",
                status     = "SCHEDULED"
            };
            LimsServer.Entities.Task tsk4 = new LimsServer.Entities.Task()
            {
                id         = "004",
                workflowID = "test1234567",
                start      = DateTime.Now.AddMinutes(5),
                taskID     = "12345678903",
                status     = "SCHEDULED"
            };
            LimsServer.Entities.Task tsk5 = new LimsServer.Entities.Task()
            {
                id         = "005",
                workflowID = "test12345678",
                start      = DateTime.Now.AddMinutes(5),
                taskID     = "12345678903",
                status     = "SCHEDULED"
            };
            this._context.Tasks.Add(tsk);
            this._context.Tasks.Add(tsk2);
            this._context.Tasks.Add(tsk3);
            this._context.Tasks.Add(tsk4);
            this._context.Tasks.Add(tsk5);
            this._context.SaveChanges();

            TaskService ts = new TaskService(this._context);

            var result1  = ts.RunTask(tsk.id);
            var dbCheck1 = this._context.Tasks.SingleAsync(tk => tk.id == tsk.id).Result;

            Assert.NotNull(dbCheck1.message);

            var result2  = ts.RunTask(tsk2.id);
            var dbCheck2 = this._context.Tasks.SingleAsync(tk => tk.id == tsk2.id).Result;

            Assert.Equal("CANCELLED", dbCheck2.status);         // Invalid status to continue task

            var result3  = ts.RunTask(tsk3.id);
            var dbCheck3 = this._context.Tasks.SingleAsync(tk => tk.id == tsk3.id).Result;

            Assert.Equal("CANCELLED", dbCheck3.status);         // No workflow found with the workflow ID provided

            var result54 = ts.RunTask(tsk5.id);
            var dbCheck5 = this._context.Tasks.SingleAsync(tk => tk.id == tsk5.id).Result;

            Assert.Equal("CANCELLED", dbCheck5.status);         // Cancelled, wrong processor

            var result4  = ts.RunTask(tsk4.id);
            var dbCheck4 = this._context.Tasks.SingleAsync(tk => tk.id == tsk4.id).Result;

            Assert.Equal("COMPLETED", dbCheck4.status);         // Completed
        }