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, _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, _driveService, _driveRepo, _logger);

            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_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, _reportRepo, _reportService);
            Assert.IsTrue(_uut.CheckIfNewSubIsAllowed(substitute));
        }
        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, _reportRepo, _reportService);
            Assert.IsFalse(_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, _driveService, _driveRepo, _logger);

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

            _repo = new List <Substitute>()
            {
                new Substitute()
                {
                    StartDateTimestamp = 1432166400,
                    EndDateTimestamp   = 1432339200,
                    PersonId           = 1,
                    LeaderId           = 3,
                    SubId     = 2,
                    OrgUnitId = 12
                },

                new Substitute()
                {
                    StartDateTimestamp = 1432166400,
                    EndDateTimestamp   = 1432339200,
                    PersonId           = 1,
                    OrgUnitId          = 12,
                    LeaderId           = 1,
                    SubId = 2
                }
            };

            _repoMock.AsQueryable().ReturnsForAnyArgs(_repo.AsQueryable());
            _uut = new SubstituteService(_repoMock, _orgService, _driveService, _driveRepo, _logger);

            Assert.IsTrue(_uut.CheckIfNewSubIsAllowed(substitute));
        }