public async Task GetDuties()
        {
            var locationId = await CreateLocation();

            var startDate = DateTimeOffset.UtcNow;
            var addDuty   = new Duty
            {
                Id         = 1,
                StartDate  = startDate,
                EndDate    = startDate.AddDays(5),
                LocationId = locationId
            };

            var addDutyExpiryDate = new Duty
            {
                Id         = 2,
                StartDate  = startDate,
                EndDate    = startDate.AddDays(5),
                ExpiryDate = startDate,
                LocationId = locationId
            };

            await Db.Duty.AddAsync(addDuty);

            await Db.Duty.AddAsync(addDutyExpiryDate);

            await Db.SaveChangesAsync();

            var controllerResult = await _controller.GetDuties(locationId, startDate, startDate.AddDays(1));

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Single(response);
            Assert.Equal(1, response.First().Id);
        }
        public async Task ExpireDuty()
        {
            var locationId = await CreateLocation();

            var startDate = DateTimeOffset.UtcNow.AddYears(5);
            var addDuty   = new Duty
            {
                Id         = 1,
                StartDate  = startDate,
                EndDate    = startDate.AddDays(5),
                LocationId = locationId
            };
            await Db.Duty.AddAsync(addDuty);

            await Db.SaveChangesAsync();

            HttpResponseTest.CheckForNoContentResponse(await _controller.ExpireDuties(new List <int> {
                1
            }));

            var controllerResult = await _controller.GetDuties(locationId, startDate, startDate.AddDays(1));

            var getDuties = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Empty(getDuties);
        }
        public async Task ImportWeeklyShifts()
        {
            var sheriffId = Guid.NewGuid();
            var shiftDto  = await CreateShift();

            await Db.Sheriff.AddAsync(new Sheriff { Id = sheriffId, IsEnabled = true, HomeLocationId = 1 });

            await Db.SaveChangesAsync();

            shiftDto.LocationId = 1;
            shiftDto.StartDate  = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek - 6).AddYears(5); //Last week monday
            shiftDto.EndDate    = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek - 5).AddYears(5); //Last week tuesday
            shiftDto.SheriffId  = sheriffId;

            var shiftDtos = new List <ShiftDto> {
                shiftDto
            };
            var shift = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.AddShifts(shiftDtos.Adapt <List <AddShiftDto> >()));

            var importedShifts = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(
                await ShiftController.ImportWeeklyShifts(1, shiftDto.StartDate));

            Assert.NotNull(importedShifts);
            var importedShift = importedShifts.Shifts.First();

            Assert.Equal(shiftDto.StartDate.AddDays(7).DateTime, importedShift.StartDate.DateTime, TimeSpan.FromSeconds(10)); //This week monday
            Assert.Equal(shiftDto.EndDate.AddDays(7).DateTime, importedShift.EndDate.DateTime, TimeSpan.FromSeconds(10));     //This week monday
            Assert.Equal(shiftDto.SheriffId, importedShift.SheriffId);
        }
        public async Task ExpireDuty()
        {
            var location = new Location {
                Id = 1, AgencyId = "5555", Name = "dfd"
            };
            await Db.Location.AddAsync(location);

            var startDate = DateTimeOffset.UtcNow.AddYears(5);
            var addDuty   = new Duty
            {
                Id         = 1,
                StartDate  = startDate,
                EndDate    = startDate.AddDays(5),
                LocationId = 1
            };
            await Db.Duty.AddAsync(addDuty);

            await Db.SaveChangesAsync();

            HttpResponseTest.CheckForNoContentResponse(await _controller.ExpireDuty(1));

            var controllerResult = await _controller.GetDuties(1, startDate, startDate.AddDays(1));

            var getDuties = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Empty(getDuties);
        }
Ejemplo n.º 5
0
        public async Task GetRoles()
        {
            var role = await CreateRole();

            var controllerResult = await _controller.Roles();

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.NotNull(response.FirstOrDefault(r => r.Id == role.Id));
        }
Ejemplo n.º 6
0
        public async Task UpdateRoleAndAssignPermission()
        {
            var role = await CreateRole();

            role.Name        = "hello";
            role.Description = "sugar";

            var permission = await CreatePermission();

            Detach();

            var updateRoleDto = new UpdateRoleDto
            {
                Role          = role.Adapt <RoleDto>(),
                PermissionIds = new List <int> {
                    permission.Id
                }
            };

            var controllerResult = await _controller.UpdateRole(updateRoleDto.Adapt <UpdateRoleDto>());

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Equal(role.Name, response.Name);
            Assert.Equal(role.Description, response.Description);
            Assert.Equal(role.Id, response.Id);

            var dbRole = await Db.Role.Include(r => r.RolePermissions).FirstOrDefaultAsync(r => r.Id == role.Id);

            Assert.NotEmpty(dbRole.RolePermissions);

            Detach();

            updateRoleDto = new UpdateRoleDto
            {
                Role          = role.Adapt <RoleDto>(),
                PermissionIds = new List <int> {
                }
            };

            controllerResult = await _controller.UpdateRole(updateRoleDto.Adapt <UpdateRoleDto>());

            response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Equal(role.Name, response.Name);
            Assert.Equal(role.Description, response.Description);
            Assert.Equal(role.Id, response.Id);

            dbRole = await Db.Role.Include(r => r.RolePermissions).FirstOrDefaultAsync(r => r.Id == role.Id);

            Assert.Empty(dbRole.RolePermissions);
        }
Ejemplo n.º 7
0
        public async Task DisableUser()
        {
            var userObject = await CreateUser();

            var controllerResult = await _controller.DisableUser(userObject.Id);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            var dbSheriff = await Db.User.FindAsync(response.Id);

            Assert.NotNull(dbSheriff);
            Assert.False(dbSheriff.IsEnabled);
        }
        private async Task <int> AddCourtRole()
        {
            var courtRole = new AddLookupCodeDto
            {
                Description = "test",
                Type        = LookupTypes.CourtRole,
                LocationId  = 5
            };
            var controllerResult = await _controller.Add(courtRole);

            var result = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            return(result.Id);
        }
        public async Task AddLookup()
        {
            await Db.Database.EnsureDeletedAsync();

            var courtRole = new AddLookupCodeDto
            {
                Type = LookupTypes.CourtRole,
            };
            var controllerResult = await _controller.Add(courtRole);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.True(response.Id > 0);
            await Db.Database.EnsureDeletedAsync();
        }
Ejemplo n.º 10
0
        private async Task SheriffEventTimeTestHelper(string awayLocationDate, string trainingDate, string trainingDate2)
        {
            var sheriffObject = await CreateSheriffUsingDbContext();

            var newLocation = new Location {
                Name = "New PLace", AgencyId = "zfddf2342"
            };
            await Db.Location.AddAsync(newLocation);

            var edmontonTimezoneLocation = new Location {
                Name = "CranbrookExample", AgencyId = "zfddf52342", Timezone = "America/Edmonton"
            };
            await Db.Location.AddAsync(edmontonTimezoneLocation);

            await Db.SaveChangesAsync();

            var sheriffAwayLocation = new SheriffAwayLocation
            {
                Timezone   = "America/Vancouver",
                StartDate  = DateTimeOffset.Parse($"{awayLocationDate} 00:00:00 -8"),
                EndDate    = DateTimeOffset.Parse($"{awayLocationDate} 23:59:00 -8"),
                SheriffId  = sheriffObject.Id,
                LocationId = edmontonTimezoneLocation.Id
            };

            var result0 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await _controller.AddSheriffAwayLocation(sheriffAwayLocation.Adapt <SheriffAwayLocationDto>()));

            var sheriffTraining = new SheriffTraining
            {
                Timezone  = "America/Edmonton",
                StartDate = DateTimeOffset.Parse($"{trainingDate} 00:00:00 -7"),
                EndDate   = DateTimeOffset.Parse($"{trainingDate} 23:59:00 -7"),
                SheriffId = sheriffObject.Id
            };

            HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await _controller.AddSheriffTraining(sheriffTraining.Adapt <SheriffTrainingDto>()));

            var sheriffTraining2 = new SheriffTraining
            {
                Timezone  = "America/Edmonton",
                StartDate = DateTimeOffset.Parse($"{trainingDate2} 00:00:00 -7"),
                EndDate   = DateTimeOffset.Parse($"{trainingDate2} 23:59:00 -7"),
                SheriffId = sheriffObject.Id
            };

            HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(
                await _controller.AddSheriffTraining(sheriffTraining2.Adapt <SheriffTrainingDto>()));
        }
Ejemplo n.º 11
0
        public async Task FindSheriff()
        {
            var sheriffObject = await CreateSheriffUsingDbContext();

            var controllerResult = await _controller.GetSheriffForTeam(sheriffObject.Id);

            var response        = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);
            var sheriffResponse = response.Adapt <Sheriff>();

            //Compare Sheriff and Sheriff Object.
            Assert.Equal(sheriffObject.FirstName, sheriffResponse.FirstName);
            Assert.Equal(sheriffObject.LastName, sheriffResponse.LastName);
            Assert.Equal(sheriffObject.BadgeNumber, sheriffResponse.BadgeNumber);
            Assert.Equal(sheriffObject.Email, sheriffResponse.Email);
            Assert.Equal(sheriffObject.Gender, sheriffResponse.Gender);
        }
        public async Task LocationTest()
        {
            await Db.Database.EnsureDeletedAsync();

            var newLocation = new Location {
                Name = "5", Id = 5
            };
            await Db.Location.AddAsync(newLocation);

            await Db.SaveChangesAsync();

            Detach();

            var courtRole = new AddLookupCodeDto
            {
                Type       = LookupTypes.CourtRole,
                LocationId = 66
            };
            var controllerResult = await _controller.Add(courtRole);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.True(response.Id > 0);

            controllerResult = await _controller.Find(response.Id);

            response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Null(response.Location);


            courtRole = new AddLookupCodeDto
            {
                Type       = LookupTypes.CourtRole,
                LocationId = 5
            };
            controllerResult = await _controller.Add(courtRole);

            response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);
            Assert.True(response.Id > 0);

            controllerResult = await _controller.Find(response.Id);

            response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Equal(5, response.LocationId);
        }
        public async Task GetLookupCodes()
        {
            await Db.Database.EnsureDeletedAsync();

            await AddCourtRole();

            var controllerResult = await _controller.GetAll(LookupTypes.CourtRole, 5);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.True(response.Count >= 1);

            var controllerResult2 = await _controller.GetAll(LookupTypes.EscortRun, 5);

            var response2 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult2);

            Assert.True(response2.Count == 0);
        }
        public async Task ExpireAndUnExpireLookup()
        {
            await Db.Database.EnsureDeletedAsync();

            var id = await AddCourtRole();

            var controllerResult = await _controller.Expire(id);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.NotNull(response.ExpiryDate);

            controllerResult = await _controller.UnExpire(id);

            response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Null(response.ExpiryDate);
        }
Ejemplo n.º 15
0
        public async Task RemoveShift()
        {
            var shiftDto = await CreateShift();

            var shiftDtos = new List <ShiftDto> {
                shiftDto
            }.Adapt <List <AddShiftDto> >();
            var shifts = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.AddShifts(shiftDtos));
            var shift  = shifts.First();

            HttpResponseTest.CheckForNoContentResponse(await ShiftController.ExpireShifts(new List <int> {
                shift.Id
            }));

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.GetShifts(1, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddHours(5)));

            Assert.Empty(response);
        }
        public async Task UpdateLookupCode()
        {
            await Db.Database.EnsureDeletedAsync();

            var newLocation = new Location {
                Name = "6", Id = 6
            };
            await Db.Location.AddAsync(newLocation);

            await Db.SaveChangesAsync();

            Detach();

            var id = await AddCourtRole();

            var result = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await _controller.Find(id));

            Detach(); //We get an exception if we don't detach before the update.

            result.Description          = "test";
            result.EffectiveDate        = DateTime.Now;
            result.Code                 = "gg";
            result.SubCode              = "gg2";
            result.Type                 = LookupTypes.JailRole;
            result.LocationId           = 6;
            result.SortOrderForLocation = new LookupSortOrderDto
            {
                LocationId   = 6,
                LookupCodeId = 6
            };

            var controllerResult = await _controller.Update(result);

            HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            result = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await _controller.Find(id));

            Assert.Equal("test", result.Description);
            Assert.Equal(DateTimeOffset.Now.DateTime, result.EffectiveDate.Value.DateTime, TimeSpan.FromSeconds(10));
            Assert.Equal(LookupTypes.JailRole, result.Type);
            Assert.Equal("gg", result.Code);
            Assert.Equal("gg2", result.SubCode);
            Assert.Equal(6, result.LocationId);
        }
Ejemplo n.º 17
0
        public async Task CreateSheriffSameIdir()
        {
            var newSheriff = new Sheriff
            {
                FirstName      = "Ted",
                LastName       = "Tums",
                BadgeNumber    = "556",
                Email          = "*****@*****.**",
                Gender         = Gender.Female,
                IdirId         = new Guid(),
                IdirName       = "ted@fakeidir",
                HomeLocationId = null
            };

            var sheriffDto = newSheriff.Adapt <SheriffWithIdirDto>();
            //Debug.Write(JsonConvert.SerializeObject(sheriffDto));

            var response        = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await _controller.AddSheriff(sheriffDto));
            var sheriffResponse = response.Adapt <Sheriff>();

            Assert.NotNull(await Db.Sheriff.FindAsync(sheriffResponse.Id));

            newSheriff.BadgeNumber = "554";
            sheriffDto             = newSheriff.Adapt <SheriffWithIdirDto>();
            //Debug.Write(JsonConvert.SerializeObject(sheriffDto));

            BusinessLayerException ble = null;

            try
            {
                response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(
                    await _controller.AddSheriff(sheriffDto));
                sheriffResponse = response.Adapt <Sheriff>();
            }
            catch (Exception e)
            {
                Assert.True(e is BusinessLayerException);
                ble = (BusinessLayerException)e;
            }

            Assert.Contains("has IDIR name", ble.Message);
        }
        public async Task AddDuty()
        {
            var locationId = await CreateLocation();

            var startDate = DateTimeOffset.UtcNow;
            var addDuty   = new AddDutyDto
            {
                StartDate  = startDate,
                EndDate    = startDate.AddDays(5),
                LocationId = locationId,
                Timezone   = "America/Vancouver"
            };
            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await _controller.AddDuties(new List <AddDutyDto> {
                addDuty
            }));

            Assert.NotNull(response);
            Assert.Equal(addDuty.StartDate, response.First().StartDate);
            Assert.Equal(addDuty.EndDate, response.First().EndDate);
        }
Ejemplo n.º 19
0
        public async Task ImportWeeklyShifts()
        {
            var sheriffId  = Guid.NewGuid();
            var sheriffId2 = Guid.NewGuid();
            var shiftDto   = await CreateShift();

            await Db.Sheriff.AddAsync(new Sheriff { Id = sheriffId, IsEnabled = true, HomeLocationId = 50000 });

            await Db.Location.AddAsync(new Location { Id = 50002, AgencyId = "3z", Timezone = "America/Vancouver" });

            await Db.Sheriff.AddAsync(new Sheriff { Id = sheriffId2, IsEnabled = true, HomeLocationId = 50002 });

            await Db.SaveChangesAsync();

            shiftDto.LocationId = 50000;
            shiftDto.StartDate  = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek - 6).AddYears(5); //Last week monday
            shiftDto.EndDate    = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek - 5).AddYears(5); //Last week tuesday
            shiftDto.SheriffId  = sheriffId;

            var shiftDtos = new List <ShiftDto> {
                shiftDto
            };
            var shift = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.AddShifts(shiftDtos.Adapt <List <AddShiftDto> >()));

            //Add in shift at a location, with a Sheriff that has no away location or home location.. to simulate a move. This shift shouldn't be picked up.
            shiftDto.LocationId = 50000;
            shiftDto.StartDate  = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek - 6).AddYears(5); //Last week monday
            shiftDto.EndDate    = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek - 5).AddYears(5); //Last week tuesday
            shiftDto.SheriffId  = sheriffId2;

            var importedShiftsResponse = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(
                await ShiftController.ImportWeeklyShifts(50000, shiftDto.StartDate));

            var importedShifts = importedShiftsResponse.Shifts.OrderBy(s => s.StartDate).ToList();

            Assert.NotNull(importedShifts);
            Assert.True(importedShifts.Count == 3);                                                                                    // 3 due to splitting
            Assert.Equal(shiftDto.StartDate.AddDays(7).DateTime, importedShifts.First().StartDate.DateTime, TimeSpan.FromSeconds(10)); //This week monday
            Assert.Equal(shiftDto.EndDate.AddDays(7).DateTime, importedShifts.Last().EndDate.DateTime, TimeSpan.FromSeconds(10));      //This week monday
            Assert.Equal(sheriffId, importedShifts.First().SheriffId);
        }
Ejemplo n.º 20
0
        public async Task CreateSheriff()
        {
            var newSheriff = new Sheriff
            {
                FirstName      = "Ted",
                LastName       = "Tums",
                BadgeNumber    = "555",
                Email          = "*****@*****.**",
                Gender         = Gender.Female,
                IdirId         = new Guid(),
                IdirName       = "ted@fakeidir",
                HomeLocationId = null
            };

            var sheriffDto = newSheriff.Adapt <SheriffWithIdirDto>();
            //Debug.Write(JsonConvert.SerializeObject(sheriffDto));

            var response        = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await _controller.AddSheriff(sheriffDto));
            var sheriffResponse = response.Adapt <Sheriff>();

            Assert.NotNull(await Db.Sheriff.FindAsync(sheriffResponse.Id));
        }
        public async Task AddDuty()
        {
            var location = new Location {
                Id = 1, AgencyId = "5555", Name = "dfd"
            };
            await Db.Location.AddAsync(location);

            await Db.SaveChangesAsync();

            var startDate = DateTimeOffset.UtcNow;
            var addDuty   = new AddDutyDto
            {
                StartDate  = startDate,
                EndDate    = startDate.AddDays(5),
                LocationId = 1,
                Timezone   = "America/Vancouver"
            };
            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await _controller.AddDuty(addDuty));

            Assert.NotNull(response);
            Assert.Equal(addDuty.StartDate, response.StartDate);
            Assert.Equal(addDuty.EndDate, response.EndDate);
        }
Ejemplo n.º 22
0
        public async Task GetShifts()
        {
            var edmontonTz           = DateTimeZoneProviders.Tzdb["America/Edmonton"];
            var startDateNowEdmonton = SystemClock.Instance.GetCurrentInstant().InZone(edmontonTz);
            var endDateNowEdmonton   = SystemClock.Instance.GetCurrentInstant().InZone(edmontonTz).PlusHours(24 * 5);

            var startTimeOffset = startDateNowEdmonton.ToDateTimeOffset();
            var endTimeOffset   = endDateNowEdmonton.ToDateTimeOffset();

            await Db.Shift.AddAsync(new Shift
            {
                Id        = 1,
                StartDate = startTimeOffset,
                EndDate   = endTimeOffset,
                Sheriff   = new Sheriff {
                    Id = Guid.NewGuid(), LastName = "hello"
                },
                AnticipatedAssignment = new Assignment {
                    Id = 1, Name = "Super assignment", Location = new Location {
                        Id = 50000, AgencyId = "zz"
                    }, LookupCode = new LookupCode()
                    {
                        Id = 900000
                    }
                },
                LocationId = 50000
            });

            await Db.SaveChangesAsync();

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.GetShifts(50000, startTimeOffset, endTimeOffset));

            Assert.NotEmpty(response);
            Assert.NotNull(response[0].Sheriff);
            Assert.NotNull(response[0].AnticipatedAssignment);
            Assert.NotNull(response[0].Location);
        }
Ejemplo n.º 23
0
        public async Task AddRole()
        {
            var roleDto = new RoleDto
            {
                Description = "Super Role",
                Name        = "Super Super"
            };

            var addRoleDto = new AddRoleDto()
            {
                Role          = roleDto,
                PermissionIds = new List <int> {
                    1
                }
            };

            var controllerResult = await _controller.AddRole(addRoleDto);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Equal(roleDto.Description, response.Description);
            Assert.Equal(roleDto.Name, response.Name);
            Assert.NotEqual(roleDto.Id, response.Id);
        }
        public async Task TestExpireAssignment()
        {
            var newLocation = new Location {
                Id = 50000, AgencyId = "44"
            };
            var assignment = new Assignment
            {
                LookupCode = new LookupCode {
                    Id = 5000000
                },
                Location       = newLocation,
                Monday         = true,
                Tuesday        = true,
                Wednesday      = true,
                Thursday       = true,
                Friday         = true,
                Saturday       = true,
                Sunday         = true,
                LocationId     = newLocation.Id,
                AdhocStartDate = DateTimeOffset.UtcNow.AddDays(-1),
                AdhocEndDate   = DateTimeOffset.UtcNow.AddDays(7),
                Timezone       = "America/Edmonton"
            };

            await Db.Assignment.AddAsync(assignment);

            await Db.SaveChangesAsync();

            var duty = new Duty
            {
                Id           = 1,
                AssignmentId = assignment.Id,
                ExpiryDate   = null,
                LocationId   = newLocation.Id,
                StartDate    = DateTimeOffset.UtcNow.AddDays(1),
                DutySlots    = new List <DutySlot>
                {
                    new DutySlot
                    {
                        LocationId = newLocation.Id,
                        ExpiryDate = null
                    }
                }
            };

            var duty2 = new Duty
            {
                Id           = 2,
                AssignmentId = assignment.Id,
                ExpiryDate   = null,
                LocationId   = newLocation.Id,
                StartDate    = DateTimeOffset.UtcNow,
                DutySlots    = new List <DutySlot>
                {
                    new DutySlot
                    {
                        LocationId = newLocation.Id,
                        ExpiryDate = null
                    }
                }
            };

            await Db.Duty.AddAsync(duty);

            await Db.Duty.AddAsync(duty2);

            await Db.SaveChangesAsync();

            var controllerResult3 = await _controller.GetAssignments(newLocation.Id, DateTimeOffset.UtcNow, assignment.AdhocEndDate);

            var hasCount1 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult3);

            Assert.NotEmpty(hasCount1);

            HttpResponseTest.CheckForNoContentResponse(await _controller.ExpireAssignment(assignment.Id, "EXPIRED", null));
            var controllerResult = await _controller.GetAssignments(newLocation.Id, DateTimeOffset.UtcNow, assignment.AdhocEndDate);

            var zeroCount = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Empty(zeroCount);

            var controllerResult2 = await _controller.GetAssignments(newLocation.Id, assignment.AdhocStartDate.Value.AddDays(-1), assignment.AdhocEndDate);

            var hasCount2 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult2);

            Assert.NotEmpty(hasCount2);
        }
Ejemplo n.º 25
0
        public async Task ShiftOvertime()
        {
            //Create Location, shift.. get
            var locationId = await CreateLocation();

            var sheriffId = Guid.NewGuid();
            await Db.Sheriff.AddAsync(new Sheriff { Id = sheriffId, IsEnabled = true, HomeLocationId = locationId });

            await Db.SaveChangesAsync();

            var shiftStartDate = DateTimeOffset.UtcNow.AddYears(5).ConvertToTimezone("America/Vancouver").DateOnly();
            var addShifts      = new List <Shift>
            {
                new Shift
                {
                    LocationId = locationId,
                    StartDate  = shiftStartDate.AddHours(24),
                    EndDate    = shiftStartDate.AddHours(25),
                    ExpiryDate = null,
                    SheriffId  = sheriffId,
                    Timezone   = "America/Vancouver"
                },
                new Shift
                {
                    LocationId = locationId,
                    StartDate  = shiftStartDate,
                    EndDate    = shiftStartDate.AddHours(5),
                    ExpiryDate = null,
                    SheriffId  = sheriffId,
                    Timezone   = "America/Vancouver"
                },
                new Shift
                {
                    LocationId = locationId,
                    StartDate  = shiftStartDate.AddHours(5),
                    EndDate    = shiftStartDate.AddHours(6),
                    SheriffId  = sheriffId,
                    Timezone   = "America/Vancouver"
                },
                new Shift
                {
                    LocationId = locationId,
                    StartDate  = shiftStartDate.AddHours(9),
                    EndDate    = shiftStartDate.AddHours(18),
                    SheriffId  = sheriffId,
                    Timezone   = "America/Vancouver"
                }
            };

            var controllerResult = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.AddShifts(addShifts.Adapt <List <AddShiftDto> >()));

            var shiftConflicts = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(
                await ShiftController.GetAvailability(locationId, shiftStartDate, shiftStartDate.AddDays(1)));

            var conflicts = shiftConflicts.SelectMany(s => s.Conflicts);
            var conflict  = conflicts.FirstOrDefault(s => s.End == shiftStartDate.AddHours(18));

            Assert.NotNull(conflict);
            //SHould have 7 hours of overtime.  12 -> 5 -> 6 <--> 9 -> 18 = 15 hours - 8 hours regular shift = 7 hours overtime.
            Assert.Equal(7.0, conflicts.Sum(s => s.OvertimeHours));
        }
Ejemplo n.º 26
0
        public async Task UpdateShift()
        {
            var shiftDto = await CreateShift();

            var shiftDtos = new List <ShiftDto> {
                shiftDto
            };
            var sheriffId   = Guid.NewGuid();
            var locationId1 = shiftDto.LocationId;

            await Db.Sheriff.AddAsync(new Sheriff { Id = sheriffId, FirstName = "Hello", LastName = "There", IsEnabled = true, HomeLocationId = locationId1 });

            await Db.Assignment.AddAsync(new Assignment { Id = 5, LocationId = locationId1, LookupCode = new LookupCode()
                                                          {
                                                              Id = 9000
                                                          } });

            await Db.SaveChangesAsync();

            var shifts = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.AddShifts(shiftDtos.Adapt <List <AddShiftDto> >()));
            var shift  = shifts.First();

            shift.StartDate               = DateTimeOffset.UtcNow.AddDays(5).Date;
            shift.EndDate                 = DateTimeOffset.UtcNow.AddDays(6).Date;
            shift.LocationId              = locationId1;           // This shouldn't change
            shift.ExpiryDate              = DateTimeOffset.UtcNow; // this shouldn't change
            shift.SheriffId               = sheriffId;
            shift.Sheriff                 = new SheriffDto();      // shouldn't change
            shift.AnticipatedAssignment   = new AssignmentDto();   //this shouldn't create new.
            shift.AnticipatedAssignmentId = 5;
            shift.Location                = new LocationDto();     // shouldn't change

            var updatedShifts = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.UpdateShifts(shifts.Adapt <List <UpdateShiftDto> >()));
            var updatedShift  = updatedShifts.First();

            Assert.Equal(shiftDto.LocationId, updatedShift.LocationId);
            Assert.Null(updatedShift.ExpiryDate);
            Assert.Equal(5, updatedShift.AnticipatedAssignmentId);
            Assert.Equal(sheriffId, updatedShift.SheriffId);

            //Create the same shift, without sheriff, should conflict.
            shiftDto.SheriffId = sheriffId;
            shiftDto.StartDate = DateTimeOffset.UtcNow.AddDays(5).Date;
            shiftDto.EndDate   = DateTimeOffset.UtcNow.AddDays(6).Date;
            shifts             = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.AddShifts(shiftDtos.Adapt <List <AddShiftDto> >()));
            shift = shifts.First();

            shift.SheriffId = sheriffId;
            await Assert.ThrowsAsync <BusinessLayerException>(() => ShiftController.UpdateShifts(shifts.Adapt <List <UpdateShiftDto> >()));

            //Create a shift that sits side by side, without sheriff, shouldn't conflict.
            shiftDto.SheriffId = sheriffId;
            shiftDto.StartDate = DateTimeOffset.UtcNow.AddDays(4).Date;
            shiftDto.EndDate   = DateTimeOffset.UtcNow.AddDays(5).Date;
            shifts             = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.AddShifts(shiftDtos.Adapt <List <AddShiftDto> >()));
            shift = shifts.First();

            shift.SheriffId = sheriffId;
            updatedShifts   = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.UpdateShifts(shifts.Adapt <List <UpdateShiftDto> >()));

            var firstShift = updatedShifts.OrderBy(s => s.StartDate).First();
            var lastShift  = updatedShifts.OrderByDescending(s => s.EndDate).First();

            Assert.Equal(shiftDto.StartDate, firstShift.StartDate);
            Assert.Equal(shiftDto.EndDate, lastShift.EndDate);
        }
Ejemplo n.º 27
0
        public async Task AddShiftConflicts()
        {
            var sheriffId = Guid.NewGuid();
            var location  = new Location {
                Id = 50000, AgencyId = "zz"
            };
            await Db.Location.AddAsync(location);

            await Db.Sheriff.AddAsync(new Sheriff { Id = sheriffId, IsEnabled = true, HomeLocationId = location.Id });

            await Db.SaveChangesAsync();

            Detach();

            //Case where shifts conflict with themselves.
            var shiftOne = new Shift
            {
                StartDate  = DateTimeOffset.UtcNow.Date,
                EndDate    = DateTimeOffset.UtcNow.Date.AddHours(1),
                LocationId = location.Id,
                Timezone   = "America/Vancouver",
                SheriffId  = sheriffId
            }.Adapt <AddShiftDto>();

            var shiftTwo = new Shift
            {
                StartDate  = DateTimeOffset.UtcNow.Date.AddHours(1),
                EndDate    = DateTimeOffset.UtcNow.Date.AddHours(2),
                LocationId = location.Id,
                Timezone   = "America/Vancouver",
                SheriffId  = sheriffId
            }.Adapt <AddShiftDto>();

            var shiftThree = new Shift
            {
                Id         = 3,
                StartDate  = DateTimeOffset.UtcNow.Date,
                EndDate    = DateTimeOffset.UtcNow.Date.AddHours(1),
                LocationId = location.Id,
                Timezone   = "America/Vancouver",
                SheriffId  = sheriffId
            }.Adapt <AddShiftDto>();

            var shiftFour = new Shift
            {
                Id         = 4,
                StartDate  = DateTimeOffset.UtcNow.Date.AddHours(1),
                EndDate    = DateTimeOffset.UtcNow.Date.AddHours(2),
                LocationId = location.Id,
                Timezone   = "America/Vancouver",
                SheriffId  = sheriffId
            }.Adapt <AddShiftDto>();

            var shiftFive = new Shift
            {
                StartDate  = DateTimeOffset.UtcNow.Date,
                EndDate    = DateTimeOffset.UtcNow.Date.AddHours(2),
                LocationId = location.Id,
                Timezone   = "America/Vancouver",
                SheriffId  = sheriffId
            }.Adapt <AddShiftDto>();

            var shiftSix = new Shift
            {
                Id         = 6,
                StartDate  = DateTimeOffset.UtcNow.Date.AddHours(2),
                EndDate    = DateTimeOffset.UtcNow.Date.AddHours(3),
                LocationId = location.Id,
                Timezone   = "America/Vancouver",
                SheriffId  = sheriffId
            }.Adapt <AddShiftDto>();

            var shiftSeven = new Shift
            {
                Id         = 7,
                StartDate  = DateTimeOffset.UtcNow.Date.AddHours(-1),
                EndDate    = DateTimeOffset.UtcNow.Date,
                LocationId = location.Id,
                Timezone   = "America/Vancouver",
                SheriffId  = sheriffId
            }.Adapt <AddShiftDto>();


            await Assert.ThrowsAsync <BusinessLayerException>(async() => await ShiftController.AddShifts(new List <AddShiftDto> {
                shiftOne, shiftFive
            }));

            var sheriffShifts = Db.Shift.AsNoTracking().Where(s => s.SheriffId == sheriffId);

            Assert.Empty(sheriffShifts);

            //Two shifts no conflicts.
            var shifts = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.AddShifts(new List <AddShiftDto> {
                shiftOne, shiftTwo
            }));

            sheriffShifts = Db.Shift.AsNoTracking().Where(s => s.SheriffId == sheriffId);
            Assert.All(sheriffShifts, s => new List <int> {
                1, 2
            }.Contains(s.Id));

            //Already assigned to two shifts: Two new shifts, should conflict now.
            await Assert.ThrowsAsync <BusinessLayerException>(async() => await ShiftController.AddShifts(new List <AddShiftDto> {
                shiftThree, shiftFour
            }));

            sheriffShifts = Db.Shift.AsNoTracking().Where(s => s.SheriffId == sheriffId);
            Assert.All(sheriffShifts, s => new List <int> {
                1, 2
            }.Contains(s.Id));

            //Schedule two more shifts, on the outside of 3 and 4.
            HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await ShiftController.AddShifts(new List <AddShiftDto> {
                shiftSix, shiftSeven
            }));
            sheriffShifts = Db.Shift.AsNoTracking().Where(s => s.SheriffId == sheriffId);
            Assert.All(sheriffShifts, s => new List <int> {
                3, 4, 6, 7
            }.Contains(s.Id));
        }
Ejemplo n.º 28
0
        public async Task AddUpdateRemoveSheriffTraining()
        {
            var sheriffObject = await CreateSheriffUsingDbContext();

            var newLocation = new Location {
                Name = "New PLace", AgencyId = "zfddf2342"
            };
            await Db.Location.AddAsync(newLocation);

            await Db.SaveChangesAsync();

            var lookupCode = new LookupCode
            {
                Code        = "zz4",
                Description = "gg",
                LocationId  = newLocation.Id
            };
            await Db.LookupCode.AddAsync(lookupCode);

            var lookupCode2 = new LookupCode
            {
                Code        = "zz",
                Description = "gg",
                LocationId  = newLocation.Id
            };

            await Db.LookupCode.AddAsync(lookupCode2);

            await Db.SaveChangesAsync();


            var entity = new SheriffTrainingDto
            {
                TrainingTypeId = lookupCode.Id,
                SheriffId      = sheriffObject.Id,
                StartDate      = DateTime.UtcNow,
                EndDate        = DateTime.UtcNow.AddHours(3)
            };

            //Add
            var controllerResult = await _controller.AddSheriffTraining(entity);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Detach();

            var updateSheriffTraining = entity.Adapt <SheriffTrainingDto>();

            updateSheriffTraining.StartDate      = DateTime.UtcNow.AddDays(5);
            updateSheriffTraining.EndDate        = DateTime.UtcNow.AddDays(5);
            updateSheriffTraining.TrainingTypeId = lookupCode2.Id;
            updateSheriffTraining.TrainingType   = lookupCode2.Adapt <LookupCodeDto>();
            updateSheriffTraining.Id             = response.Id;

            //Update
            var controllerResult3 = await _controller.UpdateSheriffTraining(updateSheriffTraining);

            var response3 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult3);

            Assert.Equal(response3.StartDate, updateSheriffTraining.StartDate);
            Assert.Equal(response3.EndDate, updateSheriffTraining.EndDate);
            Assert.Equal(response3.SheriffId, updateSheriffTraining.SheriffId);
            Assert.Equal(response3.TrainingTypeId, updateSheriffTraining.TrainingTypeId);

            //Remove
            var controllerResult4 = await _controller.RemoveSheriffTraining(updateSheriffTraining.Id, "expired");

            HttpResponseTest.CheckForNoContentResponse(controllerResult4);

            var controllerResult5 = await _controller.GetSheriffForTeam(sheriffObject.Id);

            var response5 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult5);

            Assert.Empty(response5.Training);
        }
Ejemplo n.º 29
0
        public async Task AddUpdateRemoveSheriffAwayLocation()
        {
            //Test permissions?
            var sheriffObject = await CreateSheriffUsingDbContext();

            var newLocation = new Location {
                Name = "New PLace", AgencyId = "545325345353"
            };
            await Db.Location.AddAsync(newLocation);

            var newLocation2 = new Location {
                Name = "New PLace", AgencyId = "g435346346363"
            };
            await Db.Location.AddAsync(newLocation2);

            await Db.SaveChangesAsync();

            var sheriffAwayLocation = new SheriffAwayLocationDto
            {
                SheriffId  = sheriffObject.Id,
                LocationId = newLocation.Id,
                StartDate  = DateTime.UtcNow,
                EndDate    = DateTime.UtcNow.AddHours(3)
            };

            //Add
            var controllerResult = await _controller.AddSheriffAwayLocation(sheriffAwayLocation);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Equal(sheriffAwayLocation.LocationId, response.Location.Id);
            Assert.Equal(sheriffAwayLocation.SheriffId, response.SheriffId);
            Assert.Equal(sheriffAwayLocation.StartDate, response.StartDate);
            Assert.Equal(sheriffAwayLocation.EndDate, response.EndDate);

            Detach();

            var controllerResult2 = await _controller.GetSheriffForTeam(sheriffObject.Id);

            var response2 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult2);

            Assert.True(response2.AwayLocation.Count == 1);

            var updateSheriffAwayLocation = sheriffAwayLocation.Adapt <SheriffAwayLocationDto>();

            updateSheriffAwayLocation.StartDate  = DateTime.UtcNow.AddDays(5);
            updateSheriffAwayLocation.EndDate    = DateTime.UtcNow.AddDays(5);
            updateSheriffAwayLocation.LocationId = newLocation2.Id;
            updateSheriffAwayLocation.Id         = response.Id;

            Detach();

            //Update
            var controllerResult3 = await _controller.UpdateSheriffAwayLocation(updateSheriffAwayLocation);

            var response3 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult3);

            Assert.Equal(response3.StartDate, updateSheriffAwayLocation.StartDate);
            Assert.Equal(response3.EndDate, updateSheriffAwayLocation.EndDate);
            Assert.Equal(response3.SheriffId, updateSheriffAwayLocation.SheriffId);

            Detach();

            //Remove
            var controllerResult4 = await _controller.RemoveSheriffAwayLocation(response.Id, "hello");

            HttpResponseTest.CheckForNoContentResponse(controllerResult4);

            var controllerResult6 = await _controller.GetSheriffForTeam(sheriffObject.Id);

            var response6 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult6);

            Assert.Empty(response6.AwayLocation);
        }
Ejemplo n.º 30
0
        public async Task UpdateSheriff()
        {
            var sheriffObject = await CreateSheriffUsingDbContext();

            var newLocation = new Location {
                Name = "5", Id = 50005, AgencyId = "645646464646464"
            };
            await Db.Location.AddAsync(newLocation);

            var newLocation2 = new Location {
                Name = "6", Id = 50006, AgencyId = "6456456464"
            };
            await Db.Location.AddAsync(newLocation2);

            await Db.SaveChangesAsync();

            Detach();

            var updateSheriff = sheriffObject.Adapt <SheriffWithIdirDto>();

            updateSheriff.FirstName   = "Al";
            updateSheriff.LastName    = "Hoyne";
            updateSheriff.BadgeNumber = "55";
            updateSheriff.Email       = "*****@*****.**";
            updateSheriff.Gender      = Gender.Other;

            //This object is only used for fetching.
            //updateSheriff.HomeLocation = new LocationDto { Name = "Als place2", Id = 5};
            updateSheriff.HomeLocationId = newLocation.Id;

            Detach();

            var controllerResult = await _controller.UpdateSheriff(updateSheriff);

            var response        = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);
            var sheriffResponse = response.Adapt <Sheriff>();

            Assert.Equal(updateSheriff.FirstName, sheriffResponse.FirstName);
            Assert.Equal(updateSheriff.LastName, sheriffResponse.LastName);
            Assert.Equal(updateSheriff.BadgeNumber, sheriffResponse.BadgeNumber);
            Assert.Equal(updateSheriff.Email, sheriffResponse.Email);
            Assert.Equal(updateSheriff.Gender, sheriffResponse.Gender);

            //Shouldn't be able to update any of the navigation properties here.
            Assert.Empty(sheriffResponse.AwayLocation);
            Assert.Empty(sheriffResponse.Training);
            Assert.Empty(sheriffResponse.Leave);
            //Set to invalid location, should be null.
            //WE didn't set the HomeLocationId here.
            Assert.NotNull(sheriffResponse.HomeLocation);

            Detach();

            updateSheriff.HomeLocationId = newLocation2.Id;
            updateSheriff.HomeLocation   = newLocation2.Adapt <LocationDto>();
            controllerResult             = await _controller.UpdateSheriff(updateSheriff);

            response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Detach();

            var controllerResult2 = await _controller.GetSheriffForTeam(sheriffResponse.Id);

            var response2 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.NotNull(response2.HomeLocation);
            Assert.Equal(newLocation2.Id, response.HomeLocation.Id);
        }