public APIService(
            IGenericRepository <OrgUnit> orgUnitRepo,
            IGenericRepository <CachedAddress> cachedRepo,
            IAddressLaunderer actualLaunderer,
            IAddressCoordinates coordinates,
            IGenericRepository <Person> personRepo,
            ISubstituteService subService,
            IGenericRepository <Substitute> subRepo,
            IGenericRepository <Report> reportRepo,
            IReportService <Report> reportService,
            ILogger <APIService> logger
            )
        {
            _orgUnitRepo     = orgUnitRepo;
            _cachedRepo      = cachedRepo;
            _actualLaunderer = actualLaunderer;
            _coordinates     = coordinates;
            _personRepo      = personRepo;
            _subService      = subService;
            _subRepo         = subRepo;
            _reportRepo      = reportRepo;
            _reportService   = reportService;
            _logger          = logger;

            _launderer = new CachedAddressLaunderer(_cachedRepo, _actualLaunderer, _coordinates);

            // manually handle changes on these large datasets to improve performance
            _orgUnitRepo.SetChangeTrackingEnabled(false);
            _personRepo.SetChangeTrackingEnabled(false);
            _subRepo.SetChangeTrackingEnabled(false);
            _reportRepo.SetChangeTrackingEnabled(false);
        }
Example #2
0
 public UpdateService(IGenericRepository <Employment> emplRepo,
                      IGenericRepository <OrgUnit> orgRepo,
                      IGenericRepository <Person> personRepo,
                      IGenericRepository <CachedAddress> cachedRepo,
                      IGenericRepository <PersonalAddress> personalAddressRepo,
                      IAddressLaunderer actualLaunderer,
                      IAddressCoordinates coordinates,
                      IDbUpdaterDataProvider dataProvider,
                      IMailService mailService,
                      IAddressHistoryService historyService,
                      IGenericRepository <DriveReport> reportRepo,
                      IDriveReportService driveService,
                      ISubstituteService subService,
                      IGenericRepository <Substitute> subRepo)
 {
     _emplRepo            = emplRepo;
     _orgRepo             = orgRepo;
     _personRepo          = personRepo;
     _cachedRepo          = cachedRepo;
     _personalAddressRepo = personalAddressRepo;
     _actualLaunderer     = actualLaunderer;
     _coordinates         = coordinates;
     _dataProvider        = dataProvider;
     _mailService         = mailService;
     _historyService      = historyService;
     _reportRepo          = reportRepo;
     _driveService        = driveService;
     _subService          = subService;
     _subRepo             = subRepo;
     _driveService        = driveService;
     _logger = NinjectWebKernel.GetKernel().Get <ILogger>();
 }
Example #3
0
 public SubstitutesController(IServiceProvider provider) : base(provider)
 {
     _sub          = provider.GetService <ISubstituteService>();
     _driveRepo    = provider.GetService <IGenericRepository <DriveReport> >();
     _orgService   = provider.GetService <IOrgUnitService>();
     _driveService = provider.GetService <IDriveReportService>();
 }
Example #4
0
 public UpdateService(IGenericRepository <Employment> emplRepo,
                      IGenericRepository <OrgUnit> orgRepo,
                      IGenericRepository <Person> personRepo,
                      IGenericRepository <CachedAddress> cachedRepo,
                      IGenericRepository <PersonalAddress> personalAddressRepo,
                      IAddressLaunderer actualLaunderer,
                      IAddressCoordinates coordinates,
                      IDbUpdaterDataProvider dataProvider,
                      IMailSender mailSender,
                      IAddressHistoryService historyService,
                      IGenericRepository <Report> reportRepo,
                      IReportService <Report> reportService,
                      ISubstituteService subService,
                      IGenericRepository <Substitute> subRepo,
                      IGenericRepository <VacationBalance> vacationBalanceRepo)
 {
     _emplRepo            = emplRepo;
     _orgRepo             = orgRepo;
     _personRepo          = personRepo;
     _cachedRepo          = cachedRepo;
     _personalAddressRepo = personalAddressRepo;
     _actualLaunderer     = actualLaunderer;
     _coordinates         = coordinates;
     _dataProvider        = dataProvider;
     _mailSender          = mailSender;
     _historyService      = historyService;
     _reportRepo          = reportRepo;
     _reportService       = reportService;
     _subService          = subService;
     _subRepo             = subRepo;
     _vacationBalanceRepo = vacationBalanceRepo;
 }
 //GET: odata/Substitutes
 public SubstitutesController(IGenericRepository <Substitute> repository, ISubstituteService sub, IGenericRepository <Person> personRepo, IGenericRepository <DriveReport> driveRepo, IOrgUnitService orgService, IDriveReportService driveService)
     : base(repository, personRepo)
 {
     _sub          = sub;
     _driveRepo    = driveRepo;
     _orgService   = orgService;
     _driveService = driveService;
 }
Example #6
0
        public void SetUp()
        {
            var emplList = new List <Employment>();

            var emplIdCount = 0;

            _emplRepoMock            = NSubstitute.Substitute.For <IGenericRepository <Employment> >();
            _orgUnitRepoMock         = NSubstitute.Substitute.For <IGenericRepository <OrgUnit> >();
            _personRepoMock          = NSubstitute.Substitute.For <IGenericRepository <Person> >();
            _cachedAddressRepoMock   = NSubstitute.Substitute.For <IGenericRepository <CachedAddress> >();
            _personalAddressRepoMock = NSubstitute.Substitute.For <IGenericRepository <PersonalAddress> >();
            _actualLaunderer         = NSubstitute.Substitute.For <IAddressLaunderer>();
            _coordinates             = NSubstitute.Substitute.For <IAddressCoordinates>();
            _dataProvider            = NSubstitute.Substitute.For <IDbUpdaterDataProvider>();
            _workAddressRepoMock     = NSubstitute.Substitute.For <IGenericRepository <WorkAddress> >();
            _mailSenderMock          = NSubstitute.Substitute.For <IMailSender>();
            _vacationBalanceRepo     = NSubstitute.Substitute.For <IGenericRepository <Core.DomainModel.VacationBalance> >();

            _emplRepoMock.AsQueryable().Returns(emplList.AsQueryable());

            _emplRepoMock.Insert(new Employment()).ReturnsForAnyArgs(x => x.Arg <Employment>()).AndDoes(x => emplList.Add(x.Arg <Employment>())).AndDoes(x => x.Arg <Employment>().Id = emplIdCount).AndDoes(x => emplIdCount++);

            _subRepo      = NSubstitute.Substitute.For <IGenericRepository <Core.DomainModel.Substitute> >();
            _reportRepo   = NSubstitute.Substitute.For <IGenericRepository <Report> >();
            _repotService = NSubstitute.Substitute.For <IReportService <Report> >();
            _subservice   = NSubstitute.Substitute.For <ISubstituteService>();


            _orgUnitRepoMock.AsQueryable().Returns(new List <OrgUnit>()
            {
                new OrgUnit()
                {
                    Level                 = 0,
                    OrgId                 = 1,
                    LongDescription       = "IT Minds, Aarhus",
                    ShortDescription      = "ITM",
                    HasAccessToFourKmRule = false,
                    Id = 1,
                }
            }.AsQueryable());

            _personRepoMock.AsQueryable().Returns(new List <Person>()
            {
                new Person()
                {
                    Id = 1,
                }
            }.AsQueryable());

            _uut = new UpdateService(_emplRepoMock, _orgUnitRepoMock, _personRepoMock, _cachedAddressRepoMock,
                                     _personalAddressRepoMock, _actualLaunderer, _coordinates, _dataProvider, _mailSenderMock, NSubstitute.Substitute.For <IAddressHistoryService>(), _reportRepo, _repotService, _subservice, _subRepo, _vacationBalanceRepo);
        }
        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);
        }
        public APIService(IServiceProvider provider)
        {
            _orgUnitRepo           = provider.GetService <IGenericRepository <OrgUnit> >();
            _cachedRepo            = provider.GetService <IGenericRepository <CachedAddress> >();
            _actualLaunderer       = provider.GetService <IAddressLaunderer>();
            _coordinates           = provider.GetService <IAddressCoordinates>();;
            _personRepo            = provider.GetService <IGenericRepository <Person> >();;
            _subService            = provider.GetService <ISubstituteService>();;
            _subRepo               = provider.GetService <IGenericRepository <Substitute> >();;
            _reportRepo            = provider.GetService <IGenericRepository <DriveReport> >();;
            _driveService          = provider.GetService <IDriveReportService>();;
            _logger                = provider.GetService <ILogger <APIService> >();;
            _launderer             = new CachedAddressLaunderer(_cachedRepo, _actualLaunderer, _coordinates);
            _addressHistoryService = provider.GetService <AddressHistoryService>();
            _configuration         = provider.GetService <IConfiguration>();

            // manually handle changes on these large datasets to improve performance
            _orgUnitRepo.SetChangeTrackingEnabled(false);
            _personRepo.SetChangeTrackingEnabled(false);
            _subRepo.SetChangeTrackingEnabled(false);
            _reportRepo.SetChangeTrackingEnabled(false);
        }
        public void SetUp()
        {
            var orgList = new List <OrgUnit>();

            var orgIdCount = 0;

            var cachedAddressList = new List <CachedAddress>();
            var cachedIdCount     = 0;

            _emplRepoMock            = NSubstitute.Substitute.For <IGenericRepository <Employment> >();
            _orgUnitRepoMock         = NSubstitute.Substitute.For <IGenericRepository <OrgUnit> >();
            _personRepoMock          = NSubstitute.Substitute.For <IGenericRepository <Person> >();
            _cachedAddressRepoMock   = NSubstitute.Substitute.For <IGenericRepository <CachedAddress> >();
            _personalAddressRepoMock = NSubstitute.Substitute.For <IGenericRepository <PersonalAddress> >();
            _actualLaunderer         = NSubstitute.Substitute.For <IAddressLaunderer>();
            _coordinates             = NSubstitute.Substitute.For <IAddressCoordinates>();
            _dataProvider            = NSubstitute.Substitute.For <IDbUpdaterDataProvider>();
            _mailSender          = NSubstitute.Substitute.For <IMailSender>();
            _vacationBalanceRepo = NSubstitute.Substitute.For <IGenericRepository <Core.DomainModel.VacationBalance> >();

            _orgUnitRepoMock.AsQueryable().Returns(orgList.AsQueryable());

            _orgUnitRepoMock.Insert(new OrgUnit()).ReturnsForAnyArgs(x => x.Arg <OrgUnit>()).AndDoes(x => orgList.Add(x.Arg <OrgUnit>())).AndDoes(x => x.Arg <OrgUnit>().Id = orgIdCount).AndDoes(x => orgIdCount++);

            _cachedAddressRepoMock.Insert(new CachedAddress()).ReturnsForAnyArgs(x => x.Arg <CachedAddress>()).AndDoes(x => cachedAddressList.Add(x.Arg <CachedAddress>())).AndDoes(x => x.Arg <CachedAddress>().Id = cachedIdCount).AndDoes(x => cachedIdCount++);

            _cachedAddressRepoMock.AsQueryable().Returns(cachedAddressList.AsQueryable());

            _subRepo      = NSubstitute.Substitute.For <IGenericRepository <Core.DomainModel.Substitute> >();
            _reportRepo   = NSubstitute.Substitute.For <IGenericRepository <Report> >();
            _repotService = NSubstitute.Substitute.For <IReportService <Report> >();
            _subservice   = NSubstitute.Substitute.For <ISubstituteService>();

            _actualLaunderer.Launder(new Address()).ReturnsForAnyArgs(x => x.Arg <CachedAddress>());

            _uut = new UpdateService(_emplRepoMock, _orgUnitRepoMock, _personRepoMock, _cachedAddressRepoMock,
                                     _personalAddressRepoMock, _actualLaunderer, _coordinates, _dataProvider, _mailSender, NSubstitute.Substitute.For <IAddressHistoryService>(), _reportRepo, _repotService, _subservice, _subRepo, _vacationBalanceRepo);
        }
        public void SetUp()
        {
            var personList = new List <Person>();
            var emplList   = new List <Employment>();

            var emplIdCount   = 0;
            var personIdCount = 0;

            var cachedAddressList   = new List <CachedAddress>();
            var cachedIdCount       = 0;
            var personalAddressList = new List <PersonalAddress>();
            var personalIdCount     = 0;

            _emplRepoMock            = NSubstitute.Substitute.For <IGenericRepository <Employment> >();
            _orgUnitRepoMock         = NSubstitute.Substitute.For <IGenericRepository <OrgUnit> >();
            _personRepoMock          = NSubstitute.Substitute.For <IGenericRepository <Person> >();
            _cachedAddressRepoMock   = NSubstitute.Substitute.For <IGenericRepository <CachedAddress> >();
            _personalAddressRepoMock = NSubstitute.Substitute.For <IGenericRepository <PersonalAddress> >();
            _actualLaundererMock     = NSubstitute.Substitute.For <IAddressLaunderer>();
            _coordinatesMock         = NSubstitute.Substitute.For <IAddressCoordinates>();
            _dataProviderMock        = NSubstitute.Substitute.For <IDbUpdaterDataProvider>();
            _workAddressRepoMock     = NSubstitute.Substitute.For <IGenericRepository <WorkAddress> >();
            _mailServiceMock         = NSubstitute.Substitute.For <IMailService>();
            _actualLaunderer         = NSubstitute.Substitute.For <IAddressLaunderer>();
            _coordinates             = NSubstitute.Substitute.For <IAddressCoordinates>();
            _dataProvider            = NSubstitute.Substitute.For <IDbUpdaterDataProvider>();


            _subRepo      = NSubstitute.Substitute.For <IGenericRepository <Core.DomainModel.Substitute> >();
            _reportRepo   = NSubstitute.Substitute.For <IGenericRepository <DriveReport> >();
            _driveService = NSubstitute.Substitute.For <IDriveReportService>();
            _subservice   = NSubstitute.Substitute.For <ISubstituteService>();

            _personRepoMock.AsQueryable().Returns(personList.AsQueryable());

            _personRepoMock.Insert(new Person()).ReturnsForAnyArgs(x => x.Arg <Person>()).AndDoes(x => personList.Add(x.Arg <Person>())).AndDoes(x => x.Arg <Person>().Id = personIdCount).AndDoes(x => personIdCount++);

            _emplRepoMock.AsQueryable().Returns(emplList.AsQueryable());

            _emplRepoMock.Insert(new Employment()).ReturnsForAnyArgs(x => x.Arg <Employment>()).AndDoes(x => emplList.Add(x.Arg <Employment>())).AndDoes(x => x.Arg <Employment>().Id = emplIdCount).AndDoes(x => emplIdCount++);

            _cachedAddressRepoMock.Insert(new CachedAddress()).ReturnsForAnyArgs(x => x.Arg <CachedAddress>()).AndDoes(x => cachedAddressList.Add(x.Arg <CachedAddress>())).AndDoes(x => x.Arg <CachedAddress>().Id = cachedIdCount).AndDoes(x => cachedIdCount++);

            cachedAddressList.Add(new CachedAddress()
            {
                Id           = 999,
                StreetName   = "Katrinebjergvej",
                StreetNumber = "93B",
                ZipCode      = 8200,
                Town         = "Aarhus N",
                DirtyString  = "Katrinebjergvej 93B, 8200 Aarhus N",
            });

            _cachedAddressRepoMock.AsQueryable().Returns(cachedAddressList.AsQueryable());

            _personalAddressRepoMock.Insert(new PersonalAddress()).ReturnsForAnyArgs(x => x.Arg <PersonalAddress>()).AndDoes(x => personalAddressList.Add(x.Arg <PersonalAddress>())).AndDoes(x => x.Arg <PersonalAddress>().Id = personalIdCount).AndDoes(x => personalIdCount++);

            _personalAddressRepoMock.AsQueryable().Returns(personalAddressList.AsQueryable());

            _actualLaundererMock.Launder(new Address()).ReturnsForAnyArgs(x => x.Arg <CachedAddress>());

            _uut = new UpdateService(_emplRepoMock, _orgUnitRepoMock, _personRepoMock, _cachedAddressRepoMock,
                                     _personalAddressRepoMock, _actualLaunderer, _coordinates, _dataProvider, _mailServiceMock, NSubstitute.Substitute.For <IAddressHistoryService>(), _reportRepo, _driveService, _subservice, _subRepo);

            _orgUnitRepoMock.AsQueryable().ReturnsForAnyArgs(new List <OrgUnit>()
            {
                new OrgUnit()
                {
                    Id                    = 1,
                    OrgId                 = 1,
                    ShortDescription      = "ITM",
                    LongDescription       = "IT Minds, Aarhus",
                    Level                 = 0,
                    HasAccessToFourKmRule = false,
                },
                new OrgUnit()
                {
                    Id                    = 2,
                    OrgId                 = 2,
                    ShortDescription      = "ITMB",
                    LongDescription       = "IT Minds, Aarhus child",
                    Level                 = 1,
                    ParentId              = 1,
                    HasAccessToFourKmRule = false,
                }
            }.AsQueryable());

            personList.Add(new Person()
            {
                Id = 1,
            });
        }
 //GET: odata/Substitutes
 public SubstitutesController(IGenericRepository <Substitute> repository, ISubstituteService sub, IGenericRepository <Person> personRepo, ILogger <Substitute> logger, UserManager <IdentityPerson> userManager) : base(repository, personRepo, logger, userManager)
 {
     _sub = sub;
 }
 public DependencyRetriever(ISubstituteService substituteFactory, IEnumerable <Type> supportedDependencies)
 {
     this.substituteFactory     = substituteFactory;
     this.supportedDependencies = supportedDependencies;
 }
Example #13
0
 //GET: odata/Substitutes
 public SubstitutesController(IGenericRepository <Substitute> repository, ISubstituteService sub, IGenericRepository <Person> personRepo)
     : base(repository, personRepo)
 {
     _sub = sub;
 }