Exemplo n.º 1
0
        public async Task GetShouldReturnOk()
        {
            string userId = "Jack";
            var    user   = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim("userId", userId)
            }, "mock"));
            List <ReminderSchedule> reminder = new List <ReminderSchedule>
            {
                new ReminderSchedule
                {
                    NewsId = 101, Schedule = DateTime.Now.AddDays(2)
                }
            };
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.GetReminders(userId)).Returns(Task.FromResult(reminder));
            var controller = new ReminderController(mockService.Object);

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

            var actual = await controller.Get();

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

            Assert.IsAssignableFrom <List <ReminderSchedule> >(actionResult.Value);
        }
        public async Task GetShouldReturnNotFound()
        {
            string userId = "Jack";
            var mockService = new Mock<IReminderService>();
            mockService.Setup(svc => svc.GetReminders(userId)).Throws(new NoReminderFoundException("No reminders found for this user"));
            var controller = new ReminderController(mockService.Object);

            var actual = await controller.Get(userId);
            var actionResult = Assert.IsType<NotFoundObjectResult>(actual);
            Assert.Equal("No reminders found for this user", actionResult.Value);
        }
        public async Task GetShouldReturnNotFound()
        {
            int newsId      = 102;
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.GetReminderByNewsId(newsId)).Throws(new ReminderNotFoundException($"No reminder found for news: {newsId}"));
            var controller = new ReminderController(mockService.Object);

            var actual = await Assert.ThrowsAsync <ReminderNotFoundException>(() => controller.Get(newsId));

            Assert.Equal($"No reminder found for news: {newsId}", actual.Message);
        }
Exemplo n.º 4
0
        public void GetShouldReturnAList()
        {
            var mockService = new Mock <IReminderService>();

            mockService.Setup(service => service.GetAllReminders()).Returns(this.GetReminders());
            var controller = new ReminderController(mockService.Object);

            var actual = controller.Get();

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

            Assert.IsAssignableFrom <List <Reminder> >(actionReult.Value);
        }
        public void GetShouldRetrieveAllRecords()
        {
            using (var db = new LiteDatabase(databaseFixture.DatabasePath))
            {
                var remindersCollection = db.GetCollection <Reminder>("reminders");
                var reminderToAdd       = new Reminder {
                    DueDate = DateTime.Today, Id = "2", Title = "Test"
                };
                remindersCollection.Insert(reminderToAdd);
            }

            Assert.Contains(sut.Get().Value, r => r.Id.Equals("2"));
        }
        public async Task GetShouldReturnNotFound()
        {
            int newsId      = 102;
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.GetReminderByNewsId(newsId)).Throws(new ReminderNotFoundException($"No reminder found for news: {newsId}"));
            var controller = new ReminderController(mockService.Object);

            var actual = await controller.Get(newsId);

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

            Assert.Equal($"No reminder found for news: {newsId}", actionResult.Value);
        }
        public async Task GetShouldReturnOk()
        {
            string userId = "Jack";
            List<ReminderSchedule> reminder = new List<ReminderSchedule>
                {
                    new ReminderSchedule
                    { NewsId = 101, Schedule = DateTime.Now.AddDays(2) }
                };
            var mockService = new Mock<IReminderService>();
            mockService.Setup(svc => svc.GetReminders(userId)).Returns(Task.FromResult(reminder));
            var controller = new ReminderController(mockService.Object);

            var actual = await controller.Get(userId);
            var actionResult = Assert.IsType<OkObjectResult>(actual);
            Assert.IsAssignableFrom<List<ReminderSchedule>>(actionResult.Value);
        }
        public async Task GetShouldReturnOk()
        {
            int      newsId   = 101;
            Reminder reminder = new Reminder {
                ReminderId = 1, NewsId = 101, Schedule = DateTime.Now.AddDays(5)
            };
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.GetReminderByNewsId(newsId)).Returns(Task.FromResult(reminder));
            var controller = new ReminderController(mockService.Object);

            var actual = await controller.Get(newsId);

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

            Assert.IsAssignableFrom <Reminder>(actionResult.Value);
        }
Exemplo n.º 9
0
        public void GetByCategoryIdShouldReturnOk()
        {
            int      reminderId = 101;
            Reminder reminder   = new Reminder {
                Id = 201, Name = "Sports", CreatedBy = "Mukesh", Description = "sports reminder", CreationDate = new DateTime(), Type = "email"
            };
            var mockService = new Mock <IReminderService>();

            mockService.Setup(service => service.GetReminderById(reminderId)).Returns(reminder);
            var controller = new ReminderController(mockService.Object);

            var actual = controller.Get(reminderId);

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

            Assert.IsAssignableFrom <Reminder>(actionReult.Value);
        }
Exemplo n.º 10
0
        public async Task GetShouldReturnNotFound()
        {
            string userId = "Jack";
            var    user   = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim("userId", userId)
            }, "mock"));
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.GetReminders(userId)).Throws(new NoReminderFoundException("No reminders found for this user"));
            var controller = new ReminderController(mockService.Object);

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

            var actual = await controller.Get();

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

            Assert.Equal("No reminders found for this user", actionResult.Value);
        }