public ReportGenerator(IGenericRepository <DriveReport> reportRepo, IReportFileWriter fileWriter, ILogger logger, ICustomSettings customSettings)
 {
     _reportRepo     = reportRepo;
     _fileWriter     = fileWriter;
     _logger         = logger;
     _customSettings = customSettings;
 }
        public void SetUp()
        {
            var idCounter = 0;

            repoList = new List<DriveReport>();
            _emplMock = Substitute.For<IGenericRepository<Employment>>();
            _calculatorMock = Substitute.For<IReimbursementCalculator>();
            _orgUnitMock = Substitute.For<IGenericRepository<OrgUnit>>();
            _routeMock = Substitute.For<IRoute<RouteInformation>>();
            _coordinatesMock = Substitute.For<IAddressCoordinates>();
            _subMock = Substitute.For<IGenericRepository<Core.DomainModel.Substitute>>();
            _mailServiceMock = Substitute.For<IMailService>();
            _reportRepoMock = NSubstitute.Substitute.For<IGenericRepository<DriveReport>>();
            _personMock = Substitute.For<IGenericRepository<Person>>();
            _logger = new Core.ApplicationServices.Logger.Logger();
            _customSettings = new CustomSettings();

            _reportRepoMock.Insert(new DriveReport()).ReturnsForAnyArgs(x => x.Arg<DriveReport>()).AndDoes(x => repoList.Add(x.Arg<DriveReport>())).AndDoes(x => x.Arg<DriveReport>().Id = idCounter).AndDoes(x => idCounter++);
            _reportRepoMock.AsQueryable().ReturnsForAnyArgs(repoList.AsQueryable());

            _calculatorMock.Calculate(new RouteInformation(), new DriveReport()).ReturnsForAnyArgs(x => x.Arg<DriveReport>());

            _coordinatesMock.GetAddressCoordinates(new Address()).ReturnsForAnyArgs(new DriveReportPoint()
            {
                Latitude = "1",
                Longitude = "2",
            });

            _routeMock.GetRoute(DriveReportTransportType.Car, new List<Address>()).ReturnsForAnyArgs(new RouteInformation()
            {
                Length = 2000
            });

            _uut = new DriveReportService(_mailServiceMock, _reportRepoMock, _calculatorMock, _orgUnitMock, _emplMock, _subMock, _coordinatesMock, _routeMock, _rateTypeMock, _personMock, _logger, _customSettings);
        }
Exemplo n.º 3
0
        public FileRecord(DriveReport report, string ownerCpr, ICustomSettings customSettings)
        {
            _customSettings = customSettings;
            // Unix timestamp is seconds past epoch
            DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            var      reportDate = dtDateTime.AddSeconds(report.DriveDateTimestamp).ToLocalTime();

            CprNr                  = ownerCpr;
            Date                   = reportDate;
            EmploymentType         = report.Employment.EmploymentType;
            ExtraNumber            = report.Employment.ExtraNumber;
            ReimbursementDistance  = report.Distance;
            TFCode                 = report.TFCode;
            IsAdministrativeWorker =
                report.Employment.CostCenter.ToString()
                .StartsWith(_customSettings.AdministrativeCostCenterPrefix);
            if (!string.IsNullOrWhiteSpace(report.AccountNumber) && report.AccountNumber.Length == 10)
            {
                Account = report.AccountNumber;
            }
            else if (IsAdministrativeWorker)
            {
                Account = _customSettings.AdministrativeAccount;
            }
        }
Exemplo n.º 4
0
        public MailSender(ILogger logger, ICustomSettings customSettings)
        {
            _logger         = logger;
            _customSettings = customSettings;

            try
            {
                int  port;
                bool hasPortValue = int.TryParse(_customSettings.SMTPHostPort, out port);

                _smtpClient = new SmtpClient()
                {
                    Host = _customSettings.SMTPHost,

                    EnableSsl   = false,
                    Credentials = new NetworkCredential()
                    {
                        UserName = _customSettings.SMTPUser,
                        Password = _customSettings.SMTPPassword
                    }
                };

                if (hasPortValue)
                {
                    _logger.Debug($"{this.GetType().Name}, tryParse on PROTECTED_SMTP_HOST_PORT. port = {port}");
                    _smtpClient.Port = port;
                }
            }
            catch (Exception e)
            {
                _logger.Error($"{this.GetType().Name}, Smtp client initialization falied, check values in CustomSettings.config", e);
                throw e;
            }
        }
Exemplo n.º 5
0
 public TransferToPayrollService(IReportGenerator reportGenerator, IGenericRepository <DriveReport> driveReportRepo, ISdClient sdClient, ILogger logger, ICustomSettings customSettings)
 {
     _reportGenerator = reportGenerator;
     _driveReportRepo = driveReportRepo;
     _sdClient        = sdClient;
     _logger          = logger;
     _customSettings  = customSettings;
 }
 public MailService(IGenericRepository <DriveReport> driveRepo, IGenericRepository <Substitute> subRepo, IGenericRepository <Person> personRepo, IMailSender mailSender, ILogger logger, ICustomSettings customSettings)
 {
     _driveRepo      = driveRepo;
     _subRepo        = subRepo;
     _personRepo     = personRepo;
     _mailSender     = mailSender;
     _logger         = logger;
     _customSettings = customSettings;
 }
Exemplo n.º 7
0
 public void Setup()
 {
     _customSettings = NSubstitute.Substitute.For <ICustomSettings>();
     _customSettings.KMDBackupFilePath.Returns("/sti/til/kmd/mappe");
     _customSettings.KMDFileName.Returns("kmdFilNavn");
     _customSettings.KMDHeader.Returns("første linje i kmd fil");
     _customSettings.KMDStaticNumber.Returns("DA6");
     _customSettings.KMDMunicipalityNumber.Returns("2222");
     _customSettings.KMDReservedNumber.Returns("000000");
 }
 public void Setup()
 {
     _addressHistoryMocker = new RepoMocker <AddressHistory>();
     _driveReportMocker    = new RepoMocker <DriveReport>();
     _personMocker         = new RepoMocker <Person>();
     _employmentMocker     = new RepoMocker <Employment>();
     _rateTypeMocker       = new RepoMocker <RateType>();
     _addressMocker        = new RepoMocker <Address>();
     _logger         = Substitute.For <ILogger>();
     _customSettings = new CustomSettings();
 }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            var ninjectKernel = NinjectWebKernel.GetKernel();

            ILogger         logger         = ninjectKernel.Get <ILogger>();
            ICustomSettings customSettings = ninjectKernel.Get <ICustomSettings>();

            logger.Debug($"-------- DBUPDATER STARTED --------");

            IAddressHistoryService historyService = new AddressHistoryService(ninjectKernel.Get <IGenericRepository <Employment> >(), ninjectKernel.Get <IGenericRepository <AddressHistory> >(), ninjectKernel.Get <IGenericRepository <PersonalAddress> >());

            var service = new UpdateService(ninjectKernel.Get <IGenericRepository <Employment> >(),
                                            ninjectKernel.Get <IGenericRepository <OrgUnit> >(),
                                            ninjectKernel.Get <IGenericRepository <Person> >(),
                                            ninjectKernel.Get <IGenericRepository <CachedAddress> >(),
                                            ninjectKernel.Get <IGenericRepository <PersonalAddress> >(),
                                            ninjectKernel.Get <IAddressLaunderer>(),
                                            ninjectKernel.Get <IAddressCoordinates>(),
                                            new DataProvider(ninjectKernel.Get <ILogger>(), ninjectKernel.Get <ICustomSettings>()),
                                            ninjectKernel.Get <IMailService>(),
                                            historyService,
                                            ninjectKernel.Get <IGenericRepository <DriveReport> >(),
                                            ninjectKernel.Get <IDriveReportService>(),
                                            ninjectKernel.Get <ISubstituteService>(),
                                            ninjectKernel.Get <IGenericRepository <Substitute> >());

            var dbSync = customSettings.DbIntegration ?? "SOFD";

            logger.Debug($"Database integration = {dbSync}");

            switch (dbSync)
            {
            case "IDM":
                service.MigrateOrganisationsIDM();
                service.MigrateEmployeesIDM();
                break;

            case "SOFD":
                service.MigrateOrganisations();
                service.MigrateEmployees();
                break;

            default:
                logger.Error("Could not read database integration type, check CustomSettings.config. DBUpdater will NOT run.");
                return;
            }

            historyService.UpdateAddressHistories();
            historyService.CreateNonExistingHistories();
            service.UpdateLeadersOnExpiredOrActivatedSubstitutes();
            service.AddLeadersToReportsThatHaveNone();
            logger.Debug($"-------- DBUPDATER FINISHED --------");
        }
Exemplo n.º 10
0
        private static TreeNode CreateNode(ICustomSettings settings)
        {
            TreeNode node = new TreeNode(settings.Text)
            {
                Tag = settings
            };

            foreach (ICustomSettings children in settings.Settings)
            {
                node.Nodes.Add(CreateNode(children));
            }
            return(node);
        }
 public ReimbursementCalculator(IRoute <RouteInformation> route, IPersonService personService, IGenericRepository <Person> personRepo, IGenericRepository <Employment> emplrepo, IGenericRepository <AddressHistory> addressHistoryRepo, ILogger logger, ICustomSettings customeSettings, IGenericRepository <RateType> rateTypeRepo, IGenericRepository <DriveReport> driveReportRepo, IGenericRepository <Address> addressRepo)
 {
     _route                 = route;
     _personService         = personService;
     _personRepo            = personRepo;
     _emplrepo              = emplrepo;
     _addressHistoryRepo    = addressHistoryRepo;
     _logger                = logger;
     _customSettings        = customeSettings;
     _rateTypeRepo          = rateTypeRepo;
     _driveReportRepository = driveReportRepo;
     _addressRepo           = addressRepo;
 }
        public void SetUp()
        {
            var idCounter = 0;

            repoList         = new List <DriveReport>();
            _emplMock        = Substitute.For <IGenericRepository <Employment> >();
            _calculatorMock  = Substitute.For <IReimbursementCalculator>();
            _orgUnitMock     = Substitute.For <IGenericRepository <OrgUnit> >();
            _rateTypeMock    = Substitute.For <IGenericRepository <RateType> >();
            _routeMock       = Substitute.For <IRoute <RouteInformation> >();
            _coordinatesMock = Substitute.For <IAddressCoordinates>();
            _subMock         = Substitute.For <IGenericRepository <Core.DomainModel.Substitute> >();
            _mailServiceMock = Substitute.For <IMailService>();
            _subServiceMock  = Substitute.For <ISubstituteService>();
            _reportRepoMock  = NSubstitute.Substitute.For <IGenericRepository <DriveReport> >();
            _personMock      = Substitute.For <IGenericRepository <Person> >();
            _logger          = new Core.ApplicationServices.Logger.Logger();
            _customSettings  = new CustomSettings();

            _reportRepoMock.Insert(new DriveReport()).ReturnsForAnyArgs(x => x.Arg <DriveReport>()).AndDoes(x => repoList.Add(x.Arg <DriveReport>())).AndDoes(x => x.Arg <DriveReport>().Id = idCounter).AndDoes(x => idCounter++);
            _reportRepoMock.AsQueryable().ReturnsForAnyArgs(repoList.AsQueryable());

            _calculatorMock.Calculate(new RouteInformation(), new DriveReport()).ReturnsForAnyArgs(x => x.Arg <DriveReport>());
            // The mocked reports share the exact same timestamp if they are driven on same day, so for test purposes we simplify the method and check if they are identical, so we are able to mock the method.
            _calculatorMock.AreReportsDrivenOnSameDay(1, 1).ReturnsForAnyArgs(x => (long)x[0] == (long)x[1]);

            _rateTypeMock.AsQueryable().ReturnsForAnyArgs(new List <RateType>
            {
                new RateType()
                {
                    TFCode = "1234",
                    IsBike = false,
                    RequiresLicensePlate = true,
                    Id          = 1,
                    Description = "TestRate"
                }
            }.AsQueryable());

            _coordinatesMock.GetAddressCoordinates(new Address()).ReturnsForAnyArgs(new DriveReportPoint()
            {
                Latitude  = "1",
                Longitude = "2",
            });

            _routeMock.GetRoute(DriveReportTransportType.Car, new List <Address>()).ReturnsForAnyArgs(new RouteInformation()
            {
                Length = 2000
            });

            _uut = new DriveReportService(_mailServiceMock, _reportRepoMock, _calculatorMock, _orgUnitMock, _emplMock, _subMock, _coordinatesMock, _routeMock, _rateTypeMock, _personMock, _logger, _customSettings);
        }
Exemplo n.º 13
0
 public DriveReportService(IMailService mailService, IGenericRepository <DriveReport> driveReportRepository, IReimbursementCalculator calculator, IGenericRepository <OrgUnit> orgUnitRepository, IGenericRepository <Employment> employmentRepository, IGenericRepository <Substitute> substituteRepository, IAddressCoordinates coordinates, IRoute <RouteInformation> route, IGenericRepository <RateType> rateTypeRepo, IGenericRepository <Person> personRepo, ILogger logger, ICustomSettings customSettings)
 {
     _route                 = route;
     _rateTypeRepo          = rateTypeRepo;
     _coordinates           = coordinates;
     _calculator            = calculator;
     _orgUnitRepository     = orgUnitRepository;
     _employmentRepository  = employmentRepository;
     _substituteRepository  = substituteRepository;
     _mailService           = mailService;
     _driveReportRepository = driveReportRepository;
     _personRepository      = personRepo;
     _logger                = logger;
     _customSettings        = customSettings;
 }
Exemplo n.º 14
0
        public void Setup()
        {
            var idCounter = 0;

            _reportRepoMock    = NSubstitute.Substitute.For <IGenericRepository <DriveReport> >();
            _substitueRepoMock = NSubstitute.Substitute.For <IGenericRepository <Core.DomainModel.Substitute> >();

            _personRepoMock = NSubstitute.Substitute.For <IGenericRepository <Person> >();
            _personList     = new List <Person>();
            _personRepoMock.Insert(new Person()).ReturnsForAnyArgs(x => x.Arg <Person>()).AndDoes(x => _personList.Add(x.Arg <Person>())).AndDoes(x => x.Arg <Person>().Id = idCounter).AndDoes(x => idCounter++);
            _personRepoMock.AsQueryable().ReturnsForAnyArgs(_personList.AsQueryable());

            _mailSenderMock = NSubstitute.Substitute.For <IMailSender>();
            _loggerMock     = NSubstitute.Substitute.For <ILogger>();
            _customSettings = new CustomSettings();

            _mailService = new MailService(_reportRepoMock, _substitueRepoMock, _personRepoMock, _mailSenderMock, _loggerMock, _customSettings);
        }
        public void SetUp()
        {
            var fileIdCounter = 0;
            var mailIdCounter = 0;

            fileRepoList = new List <FileGenerationSchedule>();
            mailRepoList = new List <MailNotificationSchedule>();

            _logger      = NSubstitute.Substitute.For <ILogger>();
            fileRepoMock = NSubstitute.Substitute.For <IGenericRepository <FileGenerationSchedule> >();
            fileRepoMock.Insert(new FileGenerationSchedule()).ReturnsForAnyArgs(x => x.Arg <FileGenerationSchedule>()).AndDoes(x => fileRepoList.Add(x.Arg <FileGenerationSchedule>())).AndDoes(x => x.Arg <FileGenerationSchedule>().Id = fileIdCounter).AndDoes(x => fileIdCounter++);
            fileRepoMock.AsQueryable().ReturnsForAnyArgs(fileRepoList.AsQueryable());

            mailRepoMock = NSubstitute.Substitute.For <IGenericRepository <MailNotificationSchedule> >();
            mailRepoMock.Insert(new MailNotificationSchedule()).ReturnsForAnyArgs(x => x.Arg <MailNotificationSchedule>()).AndDoes(x => mailRepoList.Add(x.Arg <MailNotificationSchedule>())).AndDoes(x => x.Arg <MailNotificationSchedule>().Id = mailIdCounter).AndDoes(x => mailIdCounter++);
            mailRepoMock.AsQueryable().ReturnsForAnyArgs(mailRepoList.AsQueryable());

            _customSettings = new CustomSettings();
        }
Exemplo n.º 16
0
        public SdClient(ILogger logger, ICustomSettings customSettings)
        {
            _logger         = logger;
            _customSettings = customSettings;

            try
            {
                _portTypeClient = new AnsaettelseKoerselOpret20170501PortTypeClient();
                _portTypeClient.ClientCredentials.UserName.UserName = _customSettings.SdUsername;
                _portTypeClient.ClientCredentials.UserName.Password = _customSettings.SdPassword;
            }
            catch (Exception e)
            {
                if (_customSettings.SdIsEnabled)
                {
                    _logger.ErrorSd($"{this.GetType().ToString()}, sendDataToSd(), Error when initiating SD client", e);
                    throw e;
                }
            }
        }
        public void Setup()
        {
            var idCounter = 0;

            _reportList     = new List <DriveReport>();
            _reportRepoMock = NSubstitute.Substitute.For <IGenericRepository <DriveReport> >();
            _reportRepoMock.Insert(new DriveReport()).ReturnsForAnyArgs(x => x.Arg <DriveReport>()).AndDoes(x => _reportList.Add(x.Arg <DriveReport>())).AndDoes(x => x.Arg <DriveReport>().Id = idCounter).AndDoes(x => idCounter++);
            _reportRepoMock.AsQueryable().ReturnsForAnyArgs(_reportList.AsQueryable());
            _reportGeneratorMock = NSubstitute.Substitute.For <IReportGenerator>();
            var writerMock = new FileWriterMock();

            _reportGeneratorMock = new ReportGenerator(_reportRepoMock, writerMock, new Logger(), new CustomSettings());
            _sdClientMock        = NSubstitute.Substitute.For <ISdClient>();
            _loggerMock          = NSubstitute.Substitute.For <ILogger>();
            _customSettingsMock  = NSubstitute.Substitute.For <ICustomSettings>();
            _customSettingsMock.SdIsEnabled.ReturnsForAnyArgs(true);
            _customSettingsMock.SdUsername.ReturnsForAnyArgs("usernametest");
            _customSettingsMock.SdPassword.ReturnsForAnyArgs("passwordtest");
            _customSettingsMock.SdInstitutionNumber.ReturnsForAnyArgs("institutionnumbertest");
            _loggerMock = NSubstitute.Substitute.For <ILogger>();

            _transferToPayRollService = new TransferToPayrollService(_reportGeneratorMock, _reportRepoMock, _sdClientMock, _loggerMock, _customSettingsMock);
        }
Exemplo n.º 18
0
 public void SetUp()
 {
     _logger         = NSubstitute.Substitute.For <ILogger>();
     repoMock        = new MailNotificationsRepoMock();
     _customSettings = new CustomSettings();
 }
Exemplo n.º 19
0
 public ReportFileWriter(ICustomSettings customSettings)
 {
     _customSettings = customSettings;
 }
Exemplo n.º 20
0
 public DataProvider(ILogger logger, ICustomSettings customSettings)
 {
     _logger         = logger;
     _customSettings = customSettings;
 }
Exemplo n.º 21
0
 public void Setup()
 {
     // will test with values found in app.config in DomainServices.Test project
     _customSettings = new CustomSettings();
 }
Exemplo n.º 22
0
 public void RegisterSettings(ICustomSettings settings)
 {
     Settings.Add(settings);
 }
 public UrlDefinitions(ICustomSettings customSettings)
 {
     _customSettings = customSettings;
 }