Example #1
0
        public async Task Should_Delete()
        {
            var sessionForDelete = new TestSession
            {
                Id    = 1,
                Title = "My session"
            };

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

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

            var unitOfWorkMock = new Mock <IUnitOfWork>();

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

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

            await service.DeleteByIdAsync(1);

            repositoryMock.Verify(m => m.Delete(1));
            repositoryMock.VerifyNoOtherCalls();
            unitOfWorkMock.Verify(m => m.SaveAsync());
        }
Example #2
0
        public async Task <IActionResult> Delete(int id)
        {
            await testSessionService.DeleteByIdAsync(id);

            return(RedirectToAction(nameof(List)));
        }