Beispiel #1
0
        public async Task DeleteShouldReturnOk()
        {
            string userId = "Jack";
            var    user   = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim("userId", userId)
            }, "mock"));
            int newsId      = 101;
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.DeleteReminder(userId, newsId)).Returns(Task.FromResult(true));
            var controller = new ReminderController(mockService.Object);

            controller.ControllerContext = new ControllerContext {
                HttpContext = new DefaultHttpContext {
                    User = user
                }
            };

            var actual = await controller.Delete(newsId);

            var actionResult = Assert.IsType <OkObjectResult>(actual);

            Assert.True(Convert.ToBoolean(actionResult.Value));
        }
Beispiel #2
0
        public async Task DeleteShouldReturnNotFound()
        {
            string userId = "Jack";
            var    user   = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim("userId", userId)
            }, "mock"));
            int newsId      = 101;
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.DeleteReminder(userId, newsId)).Throws(new NoReminderFoundException("No reminder found for this news"));

            var controller = new ReminderController(mockService.Object);

            controller.ControllerContext = new ControllerContext {
                HttpContext = new DefaultHttpContext {
                    User = user
                }
            };

            var actual = await controller.Delete(newsId);

            var actionResult = Assert.IsType <NotFoundObjectResult>(actual);

            Assert.Equal("No reminder found for this news", actionResult.Value);
        }
        public void WhenDeletingReminder_ThenRepositoryDeleteCalled()
        {
            const int reminderId = 123;

            var reminder = new Reminder
            {
                ReminderId  = reminderId,
                Title       = "TestReminder",
                DueDate     = DateTime.UtcNow,
                DueDistance = 5
            };

            MockHandlerFor(
                () => new Mock <GetReminder>(null),
                x => x
                .Setup(h => h.Execute(reminderId))
                .Returns(reminder));

            Mock <DeleteReminder> handler = MockHandlerFor(
                () => new Mock <DeleteReminder>(null),
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId, reminderId))
                .Verifiable("delete handler not called"));

            ReminderController controller = GetTestableReminderController();

            controller.Delete(reminder.ReminderId);

            handler.Verify();
        }
        public void WhenDeletingReminder_ThenReturnsToDashboardPage()
        {
            const int reminderId = 123;

            var reminder = new Reminder
            {
                ReminderId  = reminderId,
                Title       = "TestReminder",
                DueDate     = DateTime.UtcNow,
                DueDistance = 5
            };

            MockHandlerFor(
                () => new Mock <GetReminder>(null),
                x => x
                .Setup(h => h.Execute(reminderId))
                .Returns(reminder));

            MockHandlerFor(
                () => new Mock <DeleteReminder>(null),
                x => x
                .Setup(h => h.Execute(_defaultUser.UserId, reminderId)));

            ReminderController controller = GetTestableReminderController();

            var result = (RedirectToRouteResult)controller.Delete(reminder.ReminderId);

            Assert.NotNull(result);
            Assert.Equal("List", result.RouteValues["action"]);
            Assert.Equal("Reminder", result.RouteValues["controller"]);
        }
        public async Task DeleteShouldReturnNotFound()
        {
            int reminderId  = 3;
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.RemoveReminder(reminderId)).Throws(new ReminderNotFoundException($"No reminder found with id: {reminderId}"));
            var controller = new ReminderController(mockService.Object);

            var actual = await Assert.ThrowsAsync <ReminderNotFoundException>(() => controller.Delete(reminderId));

            Assert.Equal($"No reminder found with id: {reminderId}", actual.Message);
        }
        public async Task DeleteShouldReturnOk()
        {
            string userId = "Jack";
            int newsId = 101;
            var mockService = new Mock<IReminderService>();
            mockService.Setup(svc => svc.DeleteReminder(userId, newsId)).Returns(Task.FromResult(true));
            var controller = new ReminderController(mockService.Object);

            var actual = await controller.Delete(userId, newsId);
            var actionResult = Assert.IsType<OkObjectResult>(actual);
            Assert.True(Convert.ToBoolean(actionResult.Value));
        }
        public async Task DeleteShouldReturnNotFound()
        {
            string userId = "Jack";
            int newsId = 101;
            var mockService = new Mock<IReminderService>();
            mockService.Setup(svc => svc.DeleteReminder(userId, newsId)).Throws(new NoReminderFoundException("No reminder found for this news"));

            var controller = new ReminderController(mockService.Object);

            var actual = await controller.Delete(userId, newsId);
            var actionResult = Assert.IsType<NotFoundObjectResult>(actual);
            Assert.Equal("No reminder found for this news", actionResult.Value);
        }
        public async Task DeleteShouldReturnNotFound()
        {
            int reminderId  = 3;
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.RemoveReminder(reminderId)).Throws(new ReminderNotFoundException($"No reminder found with id: {reminderId}"));
            var controller = new ReminderController(mockService.Object);

            var actual = await controller.Delete(reminderId);

            var actionResult = Assert.IsType <NotFoundObjectResult>(actual);

            Assert.Equal($"No reminder found with id: {reminderId}", actionResult.Value);
        }
Beispiel #9
0
        public void DeleteShouldReturnOK()
        {
            var mockService = new Mock <IReminderService>();

            //Note note = new Note { Title = "Sample", NoteId = 1 };
            mockService.Setup(service => service.DeleteReminder(201)).Returns(true);
            var controller = new ReminderController(mockService.Object);

            var actual = controller.Delete(201);

            var actionReult = Assert.IsType <OkObjectResult>(actual);
            var actualValue = actionReult.Value;
            var expected    = true;

            Assert.Equal(expected, actualValue);
        }