Example #1
0
        public async Task <IActionResult> Edit([FromForm] TestSessionDTO testSession)
        {
            if (testSession.StartTime < DateTimeOffset.Now &&
                !HttpContext.User.IsInRole(Roles.Admin))
            {
                return(RedirectToAction(nameof(AccountController.AccessDenied), "Account"));
            }

            await testSessionService.UpdateAsync(testSession);

            return(RedirectToAction(nameof(List)));
        }
Example #2
0
        public async Task Should_Update()
        {
            var sessionToUpdate = new TestSession
            {
                Id    = 1,
                Title = "Session 1",
                Tests =
                {
                    new TestSessionTest
                    {
                        TestId = 2
                    }
                },
                Members =
                {
                    new TestSessionUser
                    {
                        UserId = "3"
                    }
                }
            };
            var updatedSessionDTO = mapper.Map <TestSession, TestSessionDTO>(sessionToUpdate);

            updatedSessionDTO.Title = "Session 2";

            var repositoryMock = new Mock <IRepository <TestSession> >();

            repositoryMock.Setup(u => u.Get(1)).Returns(sessionToUpdate);

            var unitOfWorkMock = new Mock <IUnitOfWork>();

            unitOfWorkMock.Setup(u => u.TestSessions).Returns(() => repositoryMock.Object);

            var service = new TestSessionService(unitOfWorkMock.Object, mapper);

            await service.UpdateAsync(updatedSessionDTO);

            repositoryMock.Verify(m => m.Update(It.Is <TestSession>(t =>
                                                                    t.Id == sessionToUpdate.Id &&
                                                                    t.Title == updatedSessionDTO.Title &&
                                                                    t.Tests.Single().TestId == sessionToUpdate.Tests.Single().TestId &&
                                                                    t.Members.Single().UserId == sessionToUpdate.Members.Single().UserId)));
            unitOfWorkMock.Verify(m => m.SaveAsync());
        }