Example #1
0
        public void GetShowDataIDExistsShouldPassTest()
        {
            StaticCache.LoadStaticCache();
            ShowController sc = new ShowController();

            var config  = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:22121/api/show/GetShowData");
            var route   = config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary {
                { "controller", "show" }
            });

            sc.ControllerContext = new HttpControllerContext(config, routeData, request);
            request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var response = sc.GetShowData(1);

            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);

            response = sc.GetShowData(100);
            Assert.AreEqual(response.StatusCode, HttpStatusCode.NotFound);
        }