public async Task ViewShifts_Shifts_ViewModel()
        {
            // Arrange
            IRepository <Library.Models.Shift> shiftRepository = Substitute.For <IRepository <Library.Models.Shift> >();

            shiftRepository.Get(Arg.Any <string>(), Arg.Any <IDictionary <string, object> >()).Returns(new[]
            {
                new Library.Models.Shift {
                    StartDateTime = DateTime.Now, LocationId = "1", Allocated = false
                },
                new Library.Models.Shift {
                    StartDateTime = DateTime.Now.Add(new TimeSpan(1, 0, 0, 0)), LocationId = "1", Allocated = false
                }
            });
            ILocationService locationService = Substitute.For <ILocationService>();

            locationService.Get().Returns(new[] { new Library.Models.Location {
                                                      id = "1", Name = "Contoso"
                                                  }, new Library.Models.Location {
                                                      id = "2", Name = "Fabrikam"
                                                  } });
            ShiftsController controller = this.GetController(shiftRepository: shiftRepository, locationService: locationService);

            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("http://schemas.microsoft.com/identity/claims/objectidentifier", "123") }));

            // Act
            IActionResult result = await controller.ViewShifts();

            // Assert
            ViewResult viewResult = Assert.IsType <ViewResult>(result);
            IEnumerable <ShiftViewModel> viewModelResult = Assert.IsAssignableFrom <IEnumerable <ShiftViewModel> >(viewResult.ViewData.Model);

            Assert.Equal(2, viewModelResult.Count());
        }
        public async Task ViewShifts_Shifts_AfterOrEqualToNow()
        {
            // Arrange
            IRepository <Library.Models.Shift> shiftRepository = Substitute.For <IRepository <Library.Models.Shift> >();
            ShiftsController controller = this.GetController(shiftRepository: shiftRepository);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("http://schemas.microsoft.com/identity/claims/objectidentifier", "123") }));

            // Act
            await controller.ViewShifts();

            // Assert
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            shiftRepository.Received(1).Get(
                "SELECT * FROM c WHERE c.EmployeeId = @employeeId AND c.StartDateTime >= @start",
                Arg.Is <Dictionary <string, object> >(x => x.ContainsKey("@employeeId") && x.ContainsKey("@start")));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
        public async Task ViewShifts_NoShifts_ViewDataWarning()
        {
            // Arrange
            IStringLocalizer <ShiftsController> stringLocalizer = Substitute.For <IStringLocalizer <ShiftsController> >();

            stringLocalizer.GetString("NoShifts").Returns(new LocalizedString("NoShifts", "You have no shifts booked."));
            ShiftsController controller = this.GetController(stringLocalizer: stringLocalizer);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("http://schemas.microsoft.com/identity/claims/objectidentifier", "123") }));

            // Act
            IActionResult result = await controller.ViewShifts();

            // Assert
            ViewResult viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal(stringLocalizer["NoShifts"], viewResult.ViewData["NoShifts"]);
        }
        public async Task ViewShifts_NoIdClaim_Exception()
        {
            // Arrange
            ShiftsController controller = this.GetController();

            // Assert
            ArgumentException exception = await Assert.ThrowsAsync <ArgumentException>(() => controller.ViewShifts());

            Assert.Equal("http://schemas.microsoft.com/identity/claims/objectidentifier claim is required", exception.Message);
        }