public async Task PutShouldReturnNotFound() { string userId = "Jack"; var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("userId", userId) }, "mock")); ReminderSchedule reminder = new ReminderSchedule { NewsId = 102, Schedule = DateTime.Now.AddDays(2) }; var mockService = new Mock <IReminderService>(); mockService.Setup(svc => svc.UpdateReminder(userId, reminder)).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.Put(reminder); var actionResult = Assert.IsType <NotFoundObjectResult>(actual); Assert.Equal("No reminder found for this news", actionResult.Value); }
public async Task PutShouldReturnOk() { string userId = "Jack"; var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("userId", userId) }, "mock")); ReminderSchedule reminder = new ReminderSchedule { NewsId = 101, Schedule = DateTime.Now.AddDays(2) }; var mockService = new Mock <IReminderService>(); mockService.Setup(svc => svc.UpdateReminder(userId, reminder)).Returns(Task.FromResult(true)); var controller = new ReminderController(mockService.Object); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } }; var actual = await controller.Put(reminder); var actionresult = Assert.IsType <OkObjectResult>(actual); Assert.True(Convert.ToBoolean(actionresult.Value)); }
public async Task PutShouldReturnNotFound() { string userId = "Jack"; ReminderSchedule reminder = new ReminderSchedule { NewsId = 102, Schedule = DateTime.Now.AddDays(2) }; var mockService = new Mock<IReminderService>(); mockService.Setup(svc => svc.UpdateReminder(userId, reminder)).Throws(new NoReminderFoundException("No reminder found for this news")); var controller = new ReminderController(mockService.Object); var actual = await controller.Put(userId, reminder); var actionResult = Assert.IsType<NotFoundObjectResult>(actual); Assert.Equal("No reminder found for this news", actionResult.Value); }
public async Task PutShouldReturnOk() { string userId = "Jack"; ReminderSchedule reminder = new ReminderSchedule { NewsId = 101, Schedule = DateTime.Now.AddDays(2) }; var mockService = new Mock<IReminderService>(); mockService.Setup(svc => svc.UpdateReminder(userId, reminder)).Returns(Task.FromResult(true)); var controller = new ReminderController(mockService.Object); var actual = await controller.Put(userId, reminder); var actionresult = Assert.IsType<OkObjectResult>(actual); Assert.True(Convert.ToBoolean(actionresult.Value)); }