public void CheckIfNewSubIsAllowed_ExistingApprover_OverlappingPeriod_SamePerson_ShouldReturnFalse()
        {
            var substitute = new Substitute()
            {
                StartDateTimestamp = 1431993600,
                EndDateTimestamp   = 1432166400,
                PersonId           = 1,
                LeaderId           = 3,
                SubId = 2,
                Id    = 1,
            };

            _repo = new List <Substitute>()
            {
                new Substitute()
                {
                    StartDateTimestamp = 1432080000,
                    EndDateTimestamp   = 1432252800,
                    PersonId           = 1,
                    LeaderId           = 3,
                    SubId = 2,
                    Id    = 2
                },
            };
            _repoMock.AsQueryable().ReturnsForAnyArgs(_repo.AsQueryable());
            _uut = new SubstituteService(_repoMock, _orgService, _driveService, _driveRepo, _logger);

            Assert.IsFalse(_uut.CheckIfNewSubIsAllowed(substitute));
        }
        public void CheckIfNewSubIsAllowed_ExistingApprover_SamePeriod_AddSub_ShouldReturnTrue()
        {
            var substitute = new Substitute()
            {
                StartDateTimestamp = 1432166400,
                EndDateTimestamp   = 1432339200,
                PersonId           = 1,
                LeaderId           = 1,
                SubId = 2,
            };

            _repo = new List <Substitute>()
            {
                new Substitute()
                {
                    StartDateTimestamp = 1432166400,
                    EndDateTimestamp   = 1432339200,
                    PersonId           = 1,
                    LeaderId           = 3,
                    SubId     = 2,
                    OrgUnitId = 12
                },
            };
            _repoMock.AsQueryable().ReturnsForAnyArgs(_repo.AsQueryable());
            _uut = new SubstituteService(_repoMock, _orgService, _driveService, _driveRepo, _logger);

            Assert.IsTrue(_uut.CheckIfNewSubIsAllowed(substitute));
        }
        public void CheckIfNewSubIsAllowed_ExistingSub_OverlappingPeriod2_SameOrg_ShouldReturnFalse()
        {
            var substitute = new Substitute()
            {
                StartDateTimestamp = 1432166400,
                EndDateTimestamp   = 1432339200,
                PersonId           = 1,
                LeaderId           = 1,
                SubId     = 2,
                OrgUnitId = 12,
                Id        = 1,
            };

            _repo = new List <Substitute>()
            {
                new Substitute()
                {
                    StartDateTimestamp = 1432080000,
                    EndDateTimestamp   = 1432252800,
                    PersonId           = 1,
                    LeaderId           = 1,
                    SubId     = 2,
                    OrgUnitId = 12,
                    Id        = 2,
                },
            };
            _repoMock.AsQueryable().ReturnsForAnyArgs(_repo.AsQueryable());
            _uut = new SubstituteService(_repoMock, _orgService, _reportRepo, _reportService);
            Assert.IsFalse(_uut.CheckIfNewSubIsAllowed(substitute));
        }
        public void CheckIfNewSubIsAllowed_ExistingSub_SamePersonId_SameOrg_DifferentPeriod_ShouldReturnTrue()
        {
            var substitute = new Substitute()
            {
                StartDateTimestamp = 1531993600,
                EndDateTimestamp   = 1532080000,
                PersonId           = 1,
                LeaderId           = 1,
                SubId     = 2,
                OrgUnitId = 12,
                Id        = 1,
            };

            _repo = new List <Substitute>()
            {
                new Substitute()
                {
                    StartDateTimestamp = 1431993600,
                    EndDateTimestamp   = 1432080000,
                    PersonId           = 1,
                    LeaderId           = 1,
                    SubId     = 2,
                    OrgUnitId = 12,
                    Id        = 2
                },
            };
            _repoMock.AsQueryable().ReturnsForAnyArgs(_repo.AsQueryable());
            _uut = new SubstituteService(_repoMock, _orgService, _driveService, _driveRepo, _logger);

            Assert.IsTrue(_uut.CheckIfNewSubIsAllowed(substitute));
        }
        public void CheckIfNewSubIsAllowed_ExistingApprover_SamePeriod_DifferentPerson_ShouldReturnTrue()
        {
            var substitute = new Substitute()
            {
                StartDateTimestamp = 1431993600,
                EndDateTimestamp   = 1432080000,
                PersonId           = 5,
                LeaderId           = 3,
                SubId = 2,
            };

            _repo = new List <Substitute>()
            {
                new Substitute()
                {
                    StartDateTimestamp = 1431993600,
                    EndDateTimestamp   = 1432080000,
                    PersonId           = 1,
                    LeaderId           = 1,
                    SubId = 2,
                },
            };
            _repoMock.AsQueryable().ReturnsForAnyArgs(_repo.AsQueryable());
            _uut = new SubstituteService(_repoMock, _orgService, _reportRepo, _reportService);
            Assert.IsTrue(_uut.CheckIfNewSubIsAllowed(substitute));
        }
        public void CheckIfNewSubIsAllowed_ExistingSubAfterNewSub_ShouldReturnTrue()
        {
            var substitute = new Substitute()
            {
                StartDateTimestamp = 1431993600,
                EndDateTimestamp   = 1432080000,
                PersonId           = 1,
                LeaderId           = 1,
                SubId     = 2,
                OrgUnitId = 12
            };

            _repo = new List <Substitute>()
            {
                new Substitute()
                {
                    StartDateTimestamp = 1432166400,
                    EndDateTimestamp   = 1432252800,
                    PersonId           = 1,
                    LeaderId           = 1,
                    SubId     = 2,
                    OrgUnitId = 12
                },
            };
            _repoMock.AsQueryable().ReturnsForAnyArgs(_repo.AsQueryable());
            _uut = new SubstituteService(_repoMock, _orgService, _reportRepo, _reportService);
            Assert.IsTrue(_uut.CheckIfNewSubIsAllowed(substitute));
        }
Esempio n. 7
0
        public void CheckIfNewSubIsAllowed_ExistingApproverBeforeNewApprover_ShouldReturnTrue()
        {
            var substitute = new Substitute()
            {
                StartDateTimestamp = 1432166400,
                EndDateTimestamp   = 1432252800,
                PersonId           = 1,
                LeaderId           = 3,
                SubId = 2,
            };

            _repo = new List <Substitute>()
            {
                new Substitute()
                {
                    StartDateTimestamp = 1431993600,
                    EndDateTimestamp   = 1432080000,
                    PersonId           = 1,
                    LeaderId           = 3,
                    SubId = 2,
                },
            };
            _repoMock.AsQueryable().ReturnsForAnyArgs(_repo.AsQueryable());
            _uut = new SubstituteService(_repoMock, _orgService, _driveService, _driveRepo);

            Assert.IsTrue(_uut.CheckIfNewSubIsAllowed(substitute));
        }
        public void CheckIfNewSubIsAllowed_NoExistingApprovers_ShouldReturnTrue()
        {
            var substitute = new Substitute()
            {
                StartDateTimestamp = 12,
                EndDateTimestamp   = 2000,
                PersonId           = 1,
                LeaderId           = 1,
                SubId     = 2,
                OrgUnitId = 12
            };

            _repo = new List <Substitute>();
            _repoMock.AsQueryable().ReturnsForAnyArgs(_repo.AsQueryable());
            _uut = new SubstituteService(_repoMock, _orgService, _reportRepo, _reportService);
            Assert.IsTrue(_uut.CheckIfNewSubIsAllowed(substitute));
        }
        public void SetUp()
        {
            _orgService   = NSubstitute.Substitute.For <IOrgUnitService>();
            _repoMock     = NSubstitute.Substitute.For <IGenericRepository <Substitute> >();
            _driveRepo    = NSubstitute.Substitute.For <IGenericRepository <DriveReport> >();
            _emplMock     = NSubstitute.Substitute.For <IGenericRepository <Employment> >();
            _orgUnitMock  = NSubstitute.Substitute.For <IGenericRepository <OrgUnit> >();
            _driveService = NSubstitute.Substitute.For <IDriveReportService>();

            _repo = new List <Substitute>
            {
                new Substitute()
                {
                    Sub = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Jacob",
                        LastName  = "Jensen",
                        Initials  = "JOJ"
                    },
                    Leader = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Morten",
                        LastName  = "Rasmussen",
                        Initials  = "MR"
                    },
                    Person = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Morten",
                        LastName  = "Rasmussen",
                        Initials  = "MR"
                    },
                },
                new Substitute()
                {
                    Sub = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Jacob",
                        LastName  = "Jensen",
                        Initials  = "JOJ"
                    },
                    Leader = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Morten",
                        LastName  = "Rasmussen",
                        Initials  = "MR"
                    },
                    Person = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Jacob",
                        LastName  = "Jensen",
                        Initials  = "JOJ"
                    },
                }
            };

            var leader1 = new Person()
            {
                Id        = 1,
                FirstName = "Test",
                LastName  = "Testesen",
                Initials  = "TT",
                FullName  = "Test Testesen [TT]"
            };

            var leader2 = new Person()
            {
                Id        = 3,
                FirstName = "Test2",
                LastName  = "Testesen2",
                Initials  = "2",
                FullName  = "Test Testesen [2]"
            };

            var user1 = new Person()
            {
                Id        = 2,
                FirstName = "User",
                LastName  = "Usersen",
                Initials  = "UU",
                FullName  = "User Usersen [UU]"
            };

            var user2 = new Person()
            {
                Id        = 4,
                FirstName = "User",
                LastName  = "Usersen",
                Initials  = "UU",
                FullName  = "User Usersen [UU]"
            };

            var orgUnit = new OrgUnit()
            {
                Id = 1,
            };

            var orgUnit2 = new OrgUnit()
            {
                Id = 12,
            };

            var leaderEmpl1 = new Employment()
            {
                Id        = 1,
                OrgUnitId = 1,
                OrgUnit   = orgUnit,
                Person    = leader1,
                PersonId  = leader1.Id,
                IsLeader  = true
            };

            var leaderEmpl2 = new Employment()
            {
                Id        = 2,
                OrgUnitId = 2,
                OrgUnit   = orgUnit2,
                Person    = leader1,
                PersonId  = leader1.Id,
                IsLeader  = true
            };

            var userEmpl1 = new Employment()
            {
                Id        = 3,
                OrgUnitId = 1,
                OrgUnit   = orgUnit,
                Person    = user1,
                PersonId  = user1.Id,
                IsLeader  = false
            };

            var userEmpl2 = new Employment()
            {
                Id        = 4,
                OrgUnitId = 2,
                OrgUnit   = orgUnit2,
                Person    = user2,
                PersonId  = user2.Id,
                IsLeader  = false
            };

            _emplMock.AsQueryable().ReturnsForAnyArgs(new List <Employment>()
            {
                leaderEmpl1,
                userEmpl1,
                leaderEmpl2,
                userEmpl2
            }.AsQueryable());

            _orgUnitMock.AsQueryable().ReturnsForAnyArgs(new List <OrgUnit>()
            {
                orgUnit,
                orgUnit2
            }.AsQueryable());

            var reports = new List <DriveReport>()
            {
                new DriveReport()
                {
                    Id           = 1,
                    Employment   = userEmpl1,
                    EmploymentId = userEmpl1.Id,
                    PersonId     = user1.Id,
                    Person       = user1,
                },
                new DriveReport()
                {
                    Id           = 2,
                    Employment   = userEmpl1,
                    EmploymentId = userEmpl1.Id,
                    PersonId     = user1.Id,
                    Person       = user1,
                },
                new DriveReport()
                {
                    Id           = 3,
                    Employment   = userEmpl2,
                    EmploymentId = userEmpl2.Id,
                    PersonId     = user2.Id,
                    Person       = user2,
                },
                new DriveReport()
                {
                    Id           = 4,
                    Employment   = userEmpl2,
                    EmploymentId = userEmpl2.Id,
                    PersonId     = user2.Id,
                    Person       = user2,
                },
                new DriveReport()
                {
                    Id           = 5,
                    Employment   = leaderEmpl1,
                    EmploymentId = leaderEmpl1.Id,
                    PersonId     = 1
                },
                new DriveReport()
                {
                    Id           = 6,
                    Employment   = leaderEmpl2,
                    EmploymentId = leaderEmpl2.Id,
                    PersonId     = 3
                }
            };

            _driveRepo.AsQueryable().ReturnsForAnyArgs(reports.AsQueryable());

            _uut = new SubstituteService(_repoMock, _orgService, _driveService, _driveRepo, _logger);
        }
        public void SetUp()
        {
            _orgService = NSubstitute.Substitute.For <IOrgUnitService>();
            _repoMock   = NSubstitute.Substitute.For <IGenericRepository <Substitute> >();

            _reportRepo    = NSubstitute.Substitute.For <IGenericRepository <Report> >();
            _reportService = NSubstitute.Substitute.For <IReportService <Report> >();


            _repo = new List <Substitute>
            {
                new Substitute()
                {
                    Sub = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Jacob",
                        LastName  = "Jensen",
                        Initials  = "JOJ"
                    },
                    Leader = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Morten",
                        LastName  = "Rasmussen",
                        Initials  = "MR"
                    },
                    Person =
                        new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Morten",
                        LastName  = "Rasmussen",
                        Initials  = "MR"
                    },
                },
                new Substitute()
                {
                    Sub = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Jacob",
                        LastName  = "Jensen",
                        Initials  = "JOJ"
                    },
                    Leader = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Morten",
                        LastName  = "Rasmussen",
                        Initials  = "MR"
                    },
                    Person = new Person()
                    {
                        CprNumber = "123123",
                        FirstName = "Jacob",
                        LastName  = "Jensen",
                        Initials  = "JOJ"
                    },
                }
            };

            _uut = new SubstituteService(_repoMock, _orgService, _reportRepo, _reportService);
        }
 public void Setup()
 {
     this.SubstituteFactory = Substitute.For <ISubstituteFactory>();
     this.Target            = new SubstituteService(new[] { this.SubstituteFactory });
 }