public void GetNewsInstances_ShouldReturnNotfound()
        {
            var context    = new MockNewsFeedAPIContext();
            var controller = new NewsInstancesController(context);
            var result     = controller.GetNewsInstances();

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void GetNewsInstance_ShouldReturnResult()
        {
            var context = new MockNewsFeedAPIContext();

            context.NewsInstances.Add(GetNewsInstance());
            var controller = new NewsInstancesController(context);
            var result     = controller.GetNewsInstance(1) as OkNegotiatedContentResult <NewsInstanceViewModel>;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Content.ID);
        }
        public void DeleteNewsInstance_ShouldReturnNotfound()
        {
            var context    = new MockNewsFeedAPIContext();
            var controller = new NewsInstancesController(context);

            context.NewsInstances.Add(GetNewsInstance());
            var result = controller.DeleteNewsInstance(3);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void PostNewsInstance_ShouldSuccess()
        {
            var context    = new MockNewsFeedAPIContext();
            var controller = new NewsInstancesController(context);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();
            var newInstance = GetNewsInstance();
            ResponseMessageResult result = (ResponseMessageResult)controller.PostNewsInstance(newInstance);

            Assert.IsNotNull(result);
            Assert.AreEqual($"NewsInstance/{ newInstance.ID}", result.Response.Headers.GetValues("Location").FirstOrDefault());
        }
        public void PutNewsInstance_ShouldSuccess()
        {
            var context    = new MockNewsFeedAPIContext();
            var controller = new NewsInstancesController(context);

            context.NewsInstances.Add(GetNewsInstance());
            var newInstance = GetNewsInstance();

            newInstance.RateCount = 100;
            var result = controller.PutNewsInstance(1, newInstance) as StatusCodeResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
        }
        public void GetNewsInstances_ShouldReturnResult()
        {
            var context    = new MockNewsFeedAPIContext();
            var controller = new NewsInstancesController(context);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();
            context.NewsInstances.Add(GetNewsInstance());
            context.NewsInstances.Add(GetNewsInstance());
            ResponseMessageResult result = (ResponseMessageResult)controller.GetNewsInstances();

            Assert.IsNotNull(result);
            Assert.AreEqual(2, int.Parse(result.Response.Headers.GetValues("X-Count").FirstOrDefault()));
        }
        public void GetNewsInstancesCategory_ShouldFailNotFound()
        {
            var context    = new MockNewsFeedAPIContext();
            var controller = new NewsInstancesController(context);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();
            context.NewsInstances.Add(GetNewsInstance());
            context.NewsInstances.Add(GetNewsInstance());
            var result = controller.GetNewsInstances("12");

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void PutNewsInstance_ShouldFailDifferentID()
        {
            var context    = new MockNewsFeedAPIContext();
            var controller = new NewsInstancesController(context);

            context.NewsInstances.Add(GetNewsInstance());
            var newInstance = GetNewsInstance();

            newInstance.RateCount = 100;
            var result = controller.PutNewsInstance(3, newInstance);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult));
        }
        public void DeleteNewsInstance_ShouldSuccess()
        {
            var context    = new MockNewsFeedAPIContext();
            var controller = new NewsInstancesController(context);

            context.NewsInstances.Add(GetNewsInstance());
            var result = controller.DeleteNewsInstance(1) as StatusCodeResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
            var result2 = controller.GetNewsInstance(1);

            Assert.IsNotNull(result2);
            Assert.IsInstanceOfType(result2, typeof(NotFoundResult));
        }