public void GivenAValidGrid_AndTheGridRunINotInTheDatabase_AndTheFileIsNotInTheDatabse_ThenAUnityLogWarningIsThrown()
        {
            GridRun gridRun = null;
            XmlFile xmlFile = null;

            _gridRunService.Setup(f => f.GetGridRun(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>())).Returns(gridRun);
            _applicationService.Setup(a => a.GetApplication(It.IsAny <string>())).Returns(new Application());
            _xmlFileService.Setup(x => x.GetFile(It.IsAny <string>())).Returns(xmlFile);

            _gridRunEngine.ProcessGridRun(
                It.IsAny <string>(),
                It.IsAny <string>(),
                It.IsAny <string>(),
                It.IsAny <string>(),
                It.IsAny <DateTime?>(),
                It.IsAny <DateTime?>(),
                It.IsAny <GridRunStatus>(),
                It.IsAny <bool>());

            _logger.Verify(l => l.Warn(It.IsAny <string>()), Times.Once());

            _gridRunService.Verify(g => g.Create(
                                       It.IsAny <int>(),
                                       null,
                                       It.IsAny <int>(),
                                       It.IsAny <string>(),
                                       It.IsAny <bool>(),
                                       It.IsAny <DateTime?>(),
                                       It.IsAny <DateTime?>()));
        }
        public void GivenAValidGridRun_AndTheGridRunINotInTheDatabase_AndTheApplicationIsNew_TheApplicaitonIsAddedToTheDatabase()
        {
            GridRun     gridRun     = null;
            Application application = null;

            _gridRunService.Setup(f => f.GetGridRun(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>())).Returns(gridRun);
            _applicationService.Setup(a => a.GetApplication(It.IsAny <string>())).Returns(application);
            _xmlFileService.Setup(x => x.GetFile(It.IsAny <string>())).Returns(new XmlFile());
            _applicationService.Setup(a => a.CreateApplication(It.IsAny <string>(), It.IsAny <string>())).Returns(new Application());

            _gridRunEngine.ProcessGridRun(
                It.IsAny <string>(),
                It.IsAny <string>(),
                It.IsAny <string>(),
                It.IsAny <string>(),
                It.IsAny <DateTime?>(),
                It.IsAny <DateTime?>(),
                It.IsAny <GridRunStatus>(),
                It.IsAny <bool>());

            _applicationService.Verify(x => x.CreateApplication(It.IsAny <string>(), It.IsAny <string>()), Times.Once());
            _applicationService.Verify(x => x.GetApplication(It.IsAny <string>()));

            _gridRunService.Verify(g => g.Create(
                                       It.IsAny <int>(),
                                       It.IsAny <int>(),
                                       It.IsAny <int>(),
                                       It.IsAny <string>(),
                                       It.IsAny <bool>(),
                                       It.IsAny <DateTime?>(),
                                       It.IsAny <DateTime?>()),
                                   Times.Once());
        }
Пример #3
0
 public HouseHoldingRunBuilder WithGridRun(GridRun gridRun)
 {
     if (gridRun != null)
     {
         Instance.GridRuns.Add(gridRun);
     }
     return(this);
 }
Пример #4
0
 public XmlFileBuilder WithGridRun(GridRun gridRun)
 {
     if (gridRun != null)
     {
         Instance.GridRuns.Add(gridRun);
     }
     return(this);
 }
Пример #5
0
        public void GivenValidData_WhenITryToUpdateTheGridRunAndTheGridRunIsNotFound_IGetAUnityException()
        {
            GridRun gridRun = null;

            _gridRunRepository.Setup(g => g.GetGridRun(It.IsAny <int>())).Returns(gridRun);

            Action act = () => _gridRunService.Update(It.IsAny <int>(), It.IsAny <DateTime?>(), It.IsAny <DateTime?>(), It.IsAny <int>(), It.IsAny <int>());

            act.ShouldThrow <UnityException>();
        }
Пример #6
0
        public void Create(int applicationId, int?xmlFileId, int status, string grid, bool isDebug, DateTime?startDate, DateTime?endDate)
        {
            var gridRun = new GridRun();

            gridRun.AddGridRun(applicationId, xmlFileId, endDate, grid, isDebug, startDate, status);

            try
            {
                _gridRunRepository.Create(gridRun);
            }
            catch (Exception e)
            {
                throw new UnityException("Unable to create grid run", e);
            }
        }
        public void GivenADashBoardViewModel_WhenThereArRecenteXmlFiles_AndEndDateIsNull_ThenAUnityExceptionIsThrown()
        {
            var gridRunA = new GridRun {
                EndDate = null, XmlFile = new XmlFile {
                    ManCo = new ManCo(), DocType = new DocType()
                }
            };

            var dashboardViewModel = new DashboardViewModel();

            Action act = () => dashboardViewModel.AddRecent(new List <GridRun> {
                gridRunA
            });

            act.ShouldThrow <InvalidOperationException>();
        }
Пример #8
0
        private void UpdateGridRun(int gridRunId, DateTime?startdate, DateTime?endDate, int status, int?xmlFileId, int?houseHoldingRunId)
        {
            try
            {
                GridRun gridRun = _gridRunRepository.GetGridRun(gridRunId);
                if (gridRun == null)
                {
                    throw new UnityException("grid run not valid");
                }

                gridRun.UpdateGridRun(startdate, endDate, status, xmlFileId, houseHoldingRunId);

                _gridRunRepository.Update(gridRun);
            }
            catch (Exception e)
            {
                throw new UnityException("Unable to update grid run", e);
            }
        }
        public void GivenADashBoardViewModel_WhenThereAreXmlFiles_ThenRecentExceptionViewModelHasData()
        {
            var gridRunA = new GridRun {
                EndDate = DateTime.Now, XmlFile = new XmlFile {
                    ManCo = new ManCo(), DocType = new DocType()
                }
            };
            var gridRunB = new GridRun {
                EndDate = DateTime.Now, XmlFile = new XmlFile {
                    ManCo = new ManCo(), DocType = new DocType()
                }
            };

            var dashboardViewModel = new DashboardViewModel();

            dashboardViewModel.AddExceptions(new List <GridRun> {
                gridRunA, gridRunB
            });
            dashboardViewModel.DashboardExceptionViewModels.Should().HaveCount(2);
        }
Пример #10
0
        public void GivenADashBoardViewModel_WhenThereAreXmlFiles_ThenProcessingViewModelHasData()
        {
            var gridRunA = new GridRun {
                XmlFile = new XmlFile {
                    ManCo = new ManCo(), DocType = new DocType()
                }
            };
            var gridRunB = new GridRun {
                XmlFile = new XmlFile {
                    ManCo = new ManCo(), DocType = new DocType()
                }
            };

            var dashboardViewModel = new DashboardViewModel();

            dashboardViewModel.AddProcessing(new List <GridRun> {
                gridRunA, gridRunB
            });
            dashboardViewModel.DashboardProcessingViewModels.Should().HaveCount(2);
        }
Пример #11
0
        public void ProcessGridRun(string fileName, string applicationCode, string applicationDesc, string grid, DateTime?startDate, DateTime?endDate, GridRunStatus gridRunStatus, bool?isDebug)
        {
            XmlFile xmlFile = _xmlFileService.GetFile(fileName);

            if (xmlFile == null)
            {
                _logger.Warn(string.Format("Unable to update file information as the file is not in the database. File name is {0}.", fileName));
            }

            GridRun gridRun = SearchForGridRunThatCameFromOneStep(fileName, applicationCode, grid, startDate)
                              ?? SearchForGridThatCameFromNTGEN95Import(applicationCode, grid);

            if (gridRun != null && xmlFile == null)
            {
                _gridRunService.Update(gridRun.Id, startDate, endDate, (int)gridRunStatus);
            }
            else if (gridRun != null)
            {
                _gridRunService.Update(gridRun.Id, startDate, endDate, (int)gridRunStatus, xmlFile.Id);
            }
            else
            {
                Application application = _applicationService.GetApplication(applicationCode);

                if (application == null)
                {
                    application = _applicationService.CreateApplication(applicationCode, applicationDesc);
                }

                _gridRunService.Create(
                    application.Id,
                    xmlFile != null ? xmlFile.Id : (int?)null,
                    (int)gridRunStatus,
                    grid,
                    isDebug.GetValueOrDefault(),
                    startDate == null ? (DateTime?)null : startDate.Value,
                    endDate == null ? (DateTime?)null : endDate.Value);
            }
        }
        public void SetUp()
        {
            this._gridRunService = new Mock <IGridRunService>();
            _syncService         = new Mock <ISyncService>();
            _logger                 = new Mock <ILogger>();
            _manCoService           = new Mock <IManCoService>();
            _userService            = new Mock <IUserService>();
            _houseHoldingRunService = new Mock <IHouseHoldingRunService>();

            var gridRunA = new GridRun {
                XmlFile = new XmlFile {
                    ManCo = new ManCo(), DocType = new DocType()
                }
            };
            var gridRunB = new GridRun {
                XmlFile = new XmlFile {
                    ManCo = new ManCo(), DocType = new DocType()
                }
            };
            var gridRunC = new GridRun {
                XmlFile = new XmlFile {
                    ManCo = new ManCo(), DocType = new DocType()
                }
            };
            var gridRunD = new GridRun {
                XmlFile = new XmlFile {
                    ManCo = new ManCo(), DocType = new DocType()
                }
            };
            var gridRunE = new GridRun {
                XmlFile = new XmlFile {
                    ManCo = new ManCo(), DocType = new DocType()
                }
            };


            this._gridRunService.Setup(x => x.GetProcessing()).Returns(new List <GridRun>()
            {
                gridRunA, gridRunB, gridRunC, gridRunD, gridRunE
            });
            this._gridRunService.Setup(x => x.GetTopFifteenRecentExceptions()).Returns(new List <GridRun>()
            {
                gridRunA, gridRunB, gridRunC, gridRunD, gridRunE
            });

            this._gridRunService.Setup(x => x.GetTopFifteenRecentExceptions(It.IsAny <List <int> >())).Returns(new List <GridRun>()
            {
                gridRunA, gridRunB, gridRunC, gridRunD, gridRunE
            });

            this._gridRunService.Setup(x => x.GetProcessing(It.IsAny <List <int> >())).Returns(new List <GridRun>()
            {
                gridRunA, gridRunB, gridRunC, gridRunD, gridRunE
            });

            var gridRun = new GridRun
            {
                EndDate   = DateTime.Now,
                Grid      = "grid",
                IsDebug   = false,
                StartDate = DateTime.Now.AddHours(-1),
                Status    = 2,
                XmlFile   = new XmlFile {
                    DocType = new DocType(), ManCo = new ManCo()
                },
            };

            this._gridRunService.Setup(j => j.GetTopFifteenSuccessfullyCompleted()).Returns(new List <GridRun> {
                gridRun, gridRun, gridRun, gridRun, gridRun
            });

            this._gridRunService.Setup(j => j.GetTopFifteenSuccessfullyCompleted(It.IsAny <List <int> >())).Returns(new List <GridRun> {
                gridRun, gridRun, gridRun, gridRun, gridRun
            });

            _gridRunService.Setup(x => x.GetTopFifteenRecentUnapprovedGrids()).Returns(new List <GridRun> {
                gridRun, gridRun, gridRun, gridRun, gridRun
            });

            _gridRunService.Setup(x => x.GetTopFifteenRecentUnapprovedGrids(It.IsAny <List <int> >())).Returns(new List <GridRun> {
                gridRun, gridRun, gridRun, gridRun, gridRun
            });

            _gridRunService.Setup(x => x.GetTopFifteenGridsWithRejectedDocuments()).Returns(new List <GridRun> {
                gridRun, gridRun, gridRun, gridRun, gridRun
            });

            _gridRunService.Setup(x => x.GetTopFifteenGridsWithRejectedDocuments(It.IsAny <List <int> >())).Returns(new List <GridRun> {
                gridRun, gridRun, gridRun, gridRun, gridRun
            });

            _gridRunService.Setup(x => x.GetTopFifteenGridsAwaitingHouseHolding()).Returns(new List <GridRun> {
                gridRun, gridRun, gridRun, gridRun, gridRun
            });

            _gridRunService.Setup(x => x.GetTopFifteenGridsAwaitingHouseHolding(It.IsAny <List <int> >())).Returns(new List <GridRun> {
                gridRun, gridRun, gridRun, gridRun, gridRun
            });

            _houseHoldingRunService.Setup(x => x.GetTopFifteenRecentHouseHeldGrids()).Returns(new List <HouseHoldingRun>
            {
                new HouseHoldingRun
                {
                    StartDate = DateTime.Now.AddMinutes(-10),
                    EndDate   = DateTime.Now.AddMinutes(-9),
                    GridRuns  = new Collection <GridRun>()
                    {
                        new GridRun
                        {
                            Grid = "grid1",
                        },
                        new GridRun
                        {
                            Grid = "grid2"
                        }
                    }
                }
            });

            _houseHoldingRunService.Setup(x => x.GetTopFifteenRecentHouseHeldGrids(It.IsAny <List <int> >())).Returns(new List <HouseHoldingRun>
            {
                new HouseHoldingRun
                {
                    StartDate = DateTime.Now.AddMinutes(-10),
                    EndDate   = DateTime.Now.AddMinutes(-9),
                    GridRuns  = new Collection <GridRun>()
                    {
                        new GridRun
                        {
                            Grid = "grid1",
                        },
                        new GridRun
                        {
                            Grid = "grid2"
                        }
                    }
                }
            });

            var documents = new List <Document>
            {
                new Document
                {
                    DocumentId = "5731e1fd-ebd2-46bf-9823-6cfc56223257",
                    ManCo      = new ManCo {
                        Code = "199447", Id = 199447
                    },
                    DocType = new DocType {
                        Code = "doctype code"
                    },
                    SubDocType = new SubDocType {
                        Code = "subdoctype code"
                    },
                },
                new Document
                {
                    DocumentId = "5731e1jk-ebd2-46bf-9823-6cfc56223257",
                    ManCo      = new ManCo {
                        Code = "199447", Id = 199447
                    },
                    DocType = new DocType {
                        Code = "doctype code"
                    },
                    SubDocType = new SubDocType {
                        Code = "subdoctype code"
                    }
                },
                new Document
                {
                    DocumentId = "5731e1fd-ebd2-46bf-9823-6cfc78223257",
                    ManCo      = new ManCo {
                        Code = "199778", Id = 199778
                    },
                    DocType = new DocType {
                        Code = "doctype code"
                    },
                    SubDocType = new SubDocType {
                        Code = "subdoctype code2"
                    }
                }
            };

            var manCos = new List <ManCo>
            {
                new ManCo {
                    Code = "1", Description = "Test ManCo 1", Id = 1, Users = new List <ApplicationUserManCo>()
                },
                new ManCo {
                    Code = "2", Description = "Test ManCo 2", Id = 2, Users = new List <ApplicationUserManCo>()
                },
                new ManCo {
                    Code = "3", Description = "Test ManCo 3", Id = 3, Users = new List <ApplicationUserManCo>()
                },
                new ManCo {
                    Code = "4", Description = "Test ManCo 4", Id = 4, Users = new List <ApplicationUserManCo>()
                },
                new ManCo {
                }
            };

            _manCoService.Setup(m => m.GetManCosByUserId(It.IsAny <string>())).Returns(manCos);

            _controller = new DashboardController(_gridRunService.Object, _syncService.Object, _logger.Object, _manCoService.Object, _userService.Object, _houseHoldingRunService.Object);

            _userService.Setup(x => x.GetApplicationUser()).Returns(new ApplicationUser());
        }