public async Task <IActionResult> Edit(int id) { var testSession = testSessionService.GetById(id); if (testSession.StartTime < DateTimeOffset.Now && !HttpContext.User.IsInRole(Roles.Admin)) { return(RedirectToAction(nameof(AccountController.AccessDenied), "Account")); } ViewData["Templates"] = testTemplateService .GetAll() .Select(template => new SelectListItem { Value = template.Id.ToString(), Text = template.Title }); ViewData["Users"] = (await identityService .GetAllAsync(Roles.Examinee)) .Select(user => new SelectListItem { Value = user.Id, Text = user.Name }); return(View(testSession)); }
public void Should_Get_Item() { var sessionToGet = new TestSession { Id = 1, Title = "My session" }; var repositoryMock = new Mock <IRepository <TestSession> >(); repositoryMock.Setup(u => u.Get(1)).Returns(sessionToGet); var unitOfWorkMock = new Mock <IUnitOfWork>(); unitOfWorkMock.Setup(u => u.TestSessions).Returns(() => repositoryMock.Object); var service = new TestSessionService(unitOfWorkMock.Object, mapper); var actualGet = service.GetById(1); Assert.NotNull(actualGet); Assert.Equal(sessionToGet.Title, actualGet.Title); repositoryMock.Verify(m => m.Get(1)); }