public async Task PostShouldReturnConflict()
        {
            Reminder reminder = new Reminder
            {
                UserId        = "Jack",
                Email         = "*****@*****.**",
                NewsReminders = new List <ReminderSchedule>
                {
                    new ReminderSchedule
                    {
                        NewsId = 101, Schedule = DateTime.Now.AddDays(2)
                    }
                }
            };
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.CreateReminder(reminder.UserId, reminder.Email, reminder.NewsReminders[0])).Throws(new ReminderAlreadyExistsException($"This News already have a reminder"));
            var controller = new ReminderController(mockService.Object);

            var actual = await controller.Post(reminder);

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

            Assert.Equal($"This News already have a reminder", actionResult.Value);
        }
        public async Task PostShouldReturnCreated()
        {
            Reminder reminder = new Reminder
            {
                UserId        = "Jack",
                Email         = "*****@*****.**",
                NewsReminders = new List <ReminderSchedule>
                {
                    new ReminderSchedule
                    {
                        NewsId = 102, Schedule = DateTime.Now.AddDays(2)
                    }
                }
            };
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.CreateReminder(reminder.UserId, reminder.Email, reminder.NewsReminders[0])).Returns(Task.FromResult(true));
            var controller = new ReminderController(mockService.Object);

            var actual = await controller.Post(reminder);

            var actionresult = Assert.IsType <CreatedResult>(actual);

            Assert.True(Convert.ToBoolean(actionresult.Value));
        }
        public void PostShouldSaveRecord()
        {
            var reminderToAdd = new Reminder {
                DueDate = DateTime.Today, Id = "1", Title = "Test"
            };

            sut.Post(reminderToAdd);
            using (var db = new LiteDatabase(databaseFixture.DatabasePath))
            {
                var remindersCollection = db.GetCollection <Reminder>("reminders");
                Assert.NotNull(remindersCollection.Find(r => r.Id.Equals(reminderToAdd.Id)));
            }
        }
        public async Task PostShouldReturnConflict()
        {
            var      mockService = new Mock <IReminderService>();
            Reminder reminder    = new Reminder {
                NewsId = 101, Schedule = DateTime.Now.AddDays(1)
            };

            mockService.Setup(svc => svc.AddReminder(reminder)).Throws(new ReminderAlreadyExistsException($"This news: {reminder.NewsId} already have a reminder"));
            var controller = new ReminderController(mockService.Object);

            var actual = await controller.Post(reminder);

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

            Assert.Equal($"This news: {reminder.NewsId} already have a reminder", actionResult.Value);
        }
Esempio n. 5
0
        public void POSTShouldReturnCreated()
        {
            var      mockService = new Mock <IReminderService>();
            Reminder reminder    = new Reminder {
                Id = 201, Name = "Sports", CreatedBy = "Mukesh", Description = "sports reminder", CreationDate = new DateTime(), Type = "email"
            };

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

            var actual = controller.Post(reminder.CreatedBy, reminder);

            var actionReult = Assert.IsType <CreatedResult>(actual);
            var actualValue = actionReult.Value;

            Assert.IsAssignableFrom <Reminder>(actualValue);
        }
        public async Task PostShouldReturnCreated()
        {
            var      mockService = new Mock <IReminderService>();
            Reminder reminder    = new Reminder {
                NewsId = 102, Schedule = DateTime.Now.AddDays(1)
            };
            Reminder addedReminder = new Reminder {
                ReminderId = 2, NewsId = 102, Schedule = DateTime.Now.AddDays(1)
            };

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

            var actual = await controller.Post(reminder);

            var actionResult = Assert.IsType <CreatedResult>(actual);
            var actionValue  = Assert.IsAssignableFrom <Reminder>(actionResult.Value);

            Assert.Equal(2, actionValue.ReminderId);
        }
Esempio n. 7
0
        public async Task PostShouldReturnCreated()
        {
            string userId = "Jack";
            var    user   = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim("userId", userId)
            }, "mock"));
            Reminder reminder = new Reminder
            {
                UserId        = "Jack",
                Email         = "*****@*****.**",
                NewsReminders = new List <ReminderSchedule>
                {
                    new ReminderSchedule
                    {
                        NewsId = 102, Schedule = DateTime.Now.AddDays(2)
                    }
                }
            };
            var mockService = new Mock <IReminderService>();

            mockService.Setup(svc => svc.CreateReminder(reminder.UserId, reminder.Email, reminder.NewsReminders[0])).Returns(Task.FromResult(true));
            var controller = new ReminderController(mockService.Object);

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

            var actual = await controller.Post(reminder);

            var actionresult = Assert.IsType <CreatedResult>(actual);

            Assert.True(Convert.ToBoolean(actionresult.Value));
        }