Beispiel #1
0
 /// <summary>
 /// Processes the unprocessed result with json.
 /// </summary>
 /// <param name="groupName">Name of the group.</param>
 private static void ProcessUnprocessedResultWithJson(string groupName)
 {
     try
     {
         var settings   = SettingsHelper.Get();
         var resultData = TestDataApi.Get <List <ReportData> >(string.Format(EndPoints.GetAllUnprocessedReports, groupName));
         if (!resultData.IsError)
         {
             foreach (var item in resultData.Item)
             {
                 string path = settings.BaseReportPath + "\\" + groupName + "\\JSON\\" + item.TestQueueId + "-" + item.Os.ToLower() + "-" + item.BrowserName.ToLower() + ".json";
                 if (File.Exists(path))
                 {
                     string jsonString = File.ReadAllText(path);
                     JavaScriptSerializer serializer = new JavaScriptSerializer();
                     object output = serializer.Deserialize <object>(jsonString);
                     TestDataApi.Post <object>("api/report", output);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LoggerService.LogException("ProcessUnprocessedResultWithJson: " + ex.Message);
     }
 }
Beispiel #2
0
        public void SoftDelete_WhenCalled_CourseWillBeRemoved()
        {
            // Arrange
            var computerLab = TestDataApi.CloneCourse(TestDataApi.computerLab);

            courseService.Setup(m => m.Get(It.IsAny <int>()))
            .Returns(computerLab);

            courseService.Setup(m => m.Trash(It.IsAny <Course>()))
            .Callback((Course c) => { c.IsDeleted = true; });

            var id = 4;

            var controller = new CoursesController(courseService.Object, courseTypeService.Object);

            TestHelper.SetUpControllerRequest(controller, "courses");

            // Act
            var actionResult = controller.Trash(id);
            var okResult     = actionResult as OkResult;

            // Assert
            courseService.Verify(m => m.Get(It.IsAny <int>()));
            courseService.Verify(m => m.Trash(It.IsAny <Course>()));
            Assert.That(okResult, Is.Not.Null);
            Assert.That(computerLab.IsDeleted, Is.True);
        }
Beispiel #3
0
        public void Put_WhenCalled_CourseWillBeUpdated()
        {
            // Arrange
            var computerLab = TestDataApi.CloneCourse(TestDataApi.computerLab);

            var courseForm = new CourseDto {
                Id           = computerLab.Id,
                Name         = "Cyber Security Workshop",
                CourseTypeId = 2
            };

            courseService.Setup(m => m.Get(It.IsAny <int>()))
            .Returns(computerLab);

            courseService.Setup(m => m.Update(It.IsAny <Course>()))
            .Callback((Course c) => computerLab = c);

            var id = 4;

            var controller = new CoursesController(courseService.Object, courseTypeService.Object);

            TestHelper.SetUpControllerRequest(controller, "courses");

            // Act
            var actionResult = controller.Put(id, courseForm);
            var okResult     = actionResult as OkResult;

            // Assert
            courseService.Verify(m => m.Get(It.IsAny <int>()));
            courseService.Verify(m => m.Update(It.IsAny <Course>()));
            Assert.That(okResult, Is.Not.Null);
            Assert.That(computerLab.Name, Is.EqualTo("Cyber Security Workshop"));
        }
Beispiel #4
0
        /// <summary>
        /// Executes the service.
        /// </summary>
        /// <param name="isPauseEvent">if set to <c>true</c> [is pause event].</param>
        public static void ExecuteService(bool isPauseEvent)
        {
            try
            {
                if (!isPauseEvent)
                {
                    var testQueue = TestDataApi.Get <List <TestQueue> >(EndPoints.GetTestQueue);
                    if (!testQueue.IsError && testQueue.Item != null && testQueue.Item.Any())
                    {
                        var testQueueFirst = testQueue.Item.First();

                        testQueue.SchedulerId     = testQueueFirst.SchedulerId;
                        testQueue.TestQueueId     = testQueueFirst.Id;
                        testQueue.SeleniumAddress = testQueueFirst.Settings.SeleniumAddress;

                        var updateResult = TestDataApi.Get <bool>(string.Format(EndPoints.BulkUpdateTestQueue, testQueueFirst.GroupName, 1));

                        if (!updateResult.IsError)
                        {
                            SendTestToHub(testQueue);
                        }
                        else
                        {
                            var data = updateResult.Messages.Aggregate(string.Empty, (current, message) => current + (message.Name + ":" + message.Value + "\n"));
                            LoggerService.LogException("ExecuteService UpdateResult: " + data);
                        }
                    }
                    else
                    {
                        ProcessPendingQueue();
                    }
                }
                else
                {
                    ProcessPendingQueue();
                }
            }
            catch (Exception ex)
            {
                LoggerService.LogException("ExecuteService: " + ex.Message);
            }
        }
Beispiel #5
0
        public static void ExecuteServiceThread(Object tQ)
        {
            try
            {
                ResultMessage <List <TestQueue> > testQueue = tQ as ResultMessage <List <TestQueue> >;
                FileGenerator fileGenerator = new FileGenerator(testQueue.Item);
                string        directoryName = fileGenerator.GenerateSpecFiles();

                if (!string.IsNullOrWhiteSpace(directoryName))
                {
                    new ProtractorConfigJsBuilder().Create(testQueue.Item[0]);

                    string groupName = testQueue.Item[0].GroupName;

                    TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryStatus, groupName, (int)SchedulerExecutionStatus.InProgress), new SchedulerHistory());

                    ProtractorCommandRunner protractorCommandRunner = new ProtractorCommandRunner();

                    double maxExecutionTime = TimeSpan.FromMinutes(testQueue.Item.Count * testQueue.Item[0].Browsers.Count * 10).TotalMilliseconds;

                    protractorCommandRunner.ExecuteCommand(groupName, maxExecutionTime);

                    TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryStatus, groupName, (int)SchedulerExecutionStatus.Completed), new SchedulerHistory());

                    ProcessUnprocessedResultWithJson(groupName);

                    ProcessEmail(testQueue, groupName);

                    ImageProcessor.ProcessImages(groupName);
                }

                Hub hubInfo = testQueue.Item.FirstOrDefault().hubInfo;
                DeleteHub(hubInfo.ProcessId, hubInfo.SeleniumAddress);
            }
            catch (Exception ex)
            {
                ResultMessage <List <TestQueue> > testQueue = tQ as ResultMessage <List <TestQueue> >;
                Hub hubInfo = testQueue.Item.FirstOrDefault().hubInfo;
                DeleteHub(hubInfo.ProcessId, hubInfo.SeleniumAddress);
                LoggerService.LogException(ex);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Processes the email.
        /// </summary>
        /// <param name="testQueue">The test queue.</param>
        /// <param name="groupName">Name of the group.</param>
        /// <param name="schedulerExecutionStatus">The scheduler execution status.</param>
        private static void ProcessEmail(ResultMessage <List <TestQueue> > testQueue, string groupName, SchedulerExecutionStatus schedulerExecutionStatus)
        {
            var emailStatus = SchedulerHistoryEmailStatus.NotSent;

            if (testQueue != null && testQueue.Item != null && groupName.IsNotBlank())
            {
                var schedulerIds = testQueue.Item.Select(x => x.SchedulerId).Distinct();

                var resultData = TestDataApi.Post <SearchReportObject, SearchReportResult>(EndPoints.ReportSearch, new SearchReportObject {
                    ExecutionGroup = groupName
                });

                if (resultData == null || resultData.IsError)
                {
                    emailStatus = SchedulerHistoryEmailStatus.SendException;
                }
                else if (resultData.Item != null)
                {
                    var emailProcessor = new EmailProcessor();

                    foreach (var schedulerId in schedulerIds)
                    {
                        if (!schedulerId.HasValue)
                        {
                            continue;
                        }

                        var schedularData = TestDataApi.Get <Scheduler>(string.Format(EndPoints.SchedulerById, schedulerId));

                        if (schedularData != null && !schedularData.IsError && schedularData.Item != null)
                        {
                            schedularData.Item.Status = schedulerExecutionStatus;
                            var repostData = new ReportResultData(resultData.Item.Data, schedularData.Item, groupName);
                            emailStatus = emailProcessor.EmailReport(repostData);
                        }
                    }
                }
            }

            TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryEmailStatus, groupName, (int)emailStatus), new List <SchedulerHistory>());
        }
Beispiel #7
0
        public void Get_WhenCalled_ReturnsListOfCourses()
        {
            // Arrange
            courseService.Setup(m => m.GetAll())
            .Returns(TestDataApi.GetCourses());

            var controller = new CoursesController(courseService.Object, courseTypeService.Object);

            TestHelper.SetUpControllerRequest(controller, "Course");

            // Act
            var actionResult  = controller.Get();
            var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <CourseDto> >;
            var courseNames   = contentResult.Content.Select(c => c.Name);

            // Assert
            courseService.Verify(m => m.GetAll());
            Assert.That(contentResult, Is.Not.Null);
            Assert.That(contentResult.Content, Is.Not.Null);
            Assert.That(courseNames, Has.Exactly(1).EqualTo(TestDataApi.CloneCourse(TestDataApi.computerLab).Name));
        }
Beispiel #8
0
        public void GetCurrentTerm_WhenCalled_ReturnsCurrentTerm()
        {
            var spring2018 = TestDataApi.CloneTerm(TestDataApi.spring2018);

            // Arrange
            termService.Setup(m => m.GetCurrentTerm())
            .Returns(spring2018);

            var controller = new TermsController(termService.Object);

            TestHelper.SetUpControllerRequest(controller, "terms");

            // Act
            var actionResult  = controller.GetCurrentTerm();
            var contentResult = actionResult as OkNegotiatedContentResult <TermDto>;

            // Assert
            termService.Verify(m => m.GetCurrentTerm());

            Assert.That(contentResult, Is.Not.Null);
            Assert.That(contentResult.Content, Is.Not.Null);
        }
Beispiel #9
0
        /// <summary>
        /// Executes the service.
        /// </summary>
        public static void ExecuteService()
        {
            var testQueue = TestDataApi.Get <List <TestQueue> >(EndPoints.GetTestQueue);

            if (!testQueue.IsError && testQueue.Item != null)
            {
                testQueue.Item.ForEach(x => x.Status = 1);
                var updateResult = TestDataApi.Post(EndPoints.BulkUpdateTestQueue, testQueue.Item);
                if (!updateResult.IsError)
                {
                    Hub hub = GetHubBySeleniumAddress(testQueue.Item[0].Settings.SeleniumAddress);
                    if (hub == null)
                    {
                        Hub hubCreated = AddHub(Guid.NewGuid(), testQueue.Item[0].Settings.SeleniumAddress);
                        testQueue.Item.ForEach(x => x.hubInfo = hubCreated);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(ExecuteServiceThread), testQueue);
                    }
                    else
                    {
                        _QueuedTest[Guid.NewGuid()] = testQueue;
                    }
                }
            }
            else
            {
                foreach (var item in _QueuedTest)
                {
                    Hub hubPast = GetHubBySeleniumAddress(item.Value.Item[0].Settings.SeleniumAddress);
                    if (hubPast == null)
                    {
                        Hub hubCreated = AddHub(Guid.NewGuid(), item.Value.Item[0].Settings.SeleniumAddress);
                        item.Value.Item.ForEach(x => x.hubInfo = hubCreated);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(ExecuteServiceThread), item.Value);
                        ResultMessage <List <TestQueue> > h;
                        _QueuedTest.TryRemove(item.Key, out h);
                    }
                }
            }
        }
Beispiel #10
0
        public void GetById_WhenCalled_ReturnsTerm()
        {
            var id         = 5;
            var spring2018 = TestDataApi.CloneTerm(TestDataApi.spring2018);

            // Arrange
            termService.Setup(m => m.Get(It.IsAny <int>()))
            .Returns(spring2018);

            var controller = new TermsController(termService.Object);

            TestHelper.SetUpControllerRequest(controller, "terms");

            // Act
            var actionResult  = controller.Get(id);
            var contentResult = actionResult as OkNegotiatedContentResult <TermDto>;

            // Assert
            termService.Verify(m => m.Get(It.IsAny <int>()));

            Assert.That(contentResult, Is.Not.Null);
            Assert.That(contentResult.Content, Is.Not.Null);
            Assert.That(contentResult.Content.Name, Is.EqualTo("Spring 2018"));
        }
Beispiel #11
0
        /// <summary>
        /// Executes the service thread.
        /// </summary>
        /// <param name="testQueueData">The test queue data.</param>
        public static void ExecuteServiceThread(object testQueueData)
        {
            try
            {
                ResultMessage <List <TestQueue> > testQueue = testQueueData as ResultMessage <List <TestQueue> >;
                FileGenerator fileGenerator = new FileGenerator(testQueue.Item);
                string        directoryName = fileGenerator.GenerateSpecFiles();

                if (!string.IsNullOrWhiteSpace(directoryName))
                {
                    new ProtractorConfigJsBuilder().Create(testQueue.Item[0], testQueue.Item.Count);

                    string groupName = testQueue.Item[0].GroupName;

                    var schedulerHistory = testQueue.Item[0].SchedulerId > 0
                                               ? TestDataApi.Get <SchedulerHistory>(string.Format(EndPoints.SchedulerHistory, groupName))
                                               : new ResultMessage <SchedulerHistory>();

                    if (schedulerHistory.Item == null || !schedulerHistory.Item.IsCancelled)
                    {
                        TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryStatus, groupName, (int)SchedulerExecutionStatus.InProgress), new List <SchedulerHistory>());

                        ProtractorCommandRunner protractorCommandRunner = new ProtractorCommandRunner();

                        var status = protractorCommandRunner.ExecuteCommand(groupName);

                        schedulerHistory = testQueue.Item[0].SchedulerId > 0
                           ? TestDataApi.Get <SchedulerHistory>(string.Format(EndPoints.SchedulerHistory, groupName))
                           : new ResultMessage <SchedulerHistory>();

                        status = (schedulerHistory.Item == null || !schedulerHistory.Item.IsCancelled)
                                     ? status
                                     : SchedulerExecutionStatus.Cancelled;

                        TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryStatus, groupName, (int)status), new List <SchedulerHistory>());

                        ProcessUnprocessedResultWithJson(groupName);
                    }
                    else
                    {
                        TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryStatus, groupName, schedulerHistory.Item.Status == SchedulerExecutionStatus.CancelledCallBackIssue ? (int)SchedulerExecutionStatus.CancelledCallBackIssue : (int)SchedulerExecutionStatus.Cancelled), new List <SchedulerHistory>());
                    }

                    if (schedulerHistory.Item != null)
                    {
                        ProcessEmail(testQueue, groupName, schedulerHistory.Item.Status);
                    }

                    ImageProcessor.ProcessImages(groupName);
                }

                Hub hubInfo = testQueue.Item.First().HubInfo;

                DeleteHub(hubInfo.ProcessId, hubInfo.SeleniumAddress);
            }
            catch (Exception ex)
            {
                ResultMessage <List <TestQueue> > testQueue = testQueueData as ResultMessage <List <TestQueue> >;
                Hub hubInfo = testQueue.Item.First().HubInfo;
                DeleteHub(hubInfo.ProcessId, hubInfo.SeleniumAddress);
                LoggerService.LogException("ExecuteServiceThread: " + ex.Message);
            }
        }