Ejemplo n.º 1
0
        public void API_ReturnsCachedModels(string apiDescriptionId)
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            HelpController controller = new HelpController(config);

            ViewResult result = Assert.IsType<ViewResult>(controller.Api(apiDescriptionId));
            ViewResult result2 = Assert.IsType<ViewResult>(controller.Api(apiDescriptionId));

            Assert.NotNull(result.Model);
            Assert.NotNull(result2.Model);

            // Make sure the model is cached
            Assert.Same(config.GetHelpPageApiModel(apiDescriptionId), result.Model);
            Assert.Same(result.Model, result2.Model);
        }
Ejemplo n.º 2
0
        public void Index_ReturnsCachedModels()
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            HelpController controller = new HelpController(config);

            ViewResult result = Assert.IsType<ViewResult>(controller.Index());
            ViewResult result2 = Assert.IsType<ViewResult>(controller.Index());

            Assert.NotNull(result.Model);
            Assert.NotNull(result2.Model);

            // Make sure the model is cached
            Assert.Same(config.Services.GetApiExplorer().ApiDescriptions, result.Model);
            Assert.Same(result.Model, result2.Model);
        }
Ejemplo n.º 3
0
        public void API_ReturnsNullModels_WhenApiIdIsInvalid(string apiDescriptionId)
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            HelpController controller = new HelpController(config);

            ViewResult result = Assert.IsType<ViewResult>(controller.Api(apiDescriptionId));
            ViewResult result2 = Assert.IsType<ViewResult>(controller.Api(apiDescriptionId));

            Assert.Null(result.Model);
            Assert.Null(result2.Model);
        }
Ejemplo n.º 4
0
 public void Constructor_OneParameter()
 {
     HttpConfiguration config = new HttpConfiguration();
     HelpController controller = new HelpController(config);
     Assert.Same(config, controller.Configuration);
 }
Ejemplo n.º 5
0
        public void ResourceModel_ReturnsNullModels_WhenAModelNameIsInvalid(string modelName)
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            HelpController controller = new HelpController(config);

            ViewResult result = Assert.IsType<ViewResult>(controller.ResourceModel(modelName));
            ViewResult result2 = Assert.IsType<ViewResult>(controller.ResourceModel(modelName));

            Assert.Null(result.Model);
            Assert.Null(result2.Model);
        }
Ejemplo n.º 6
0
 public void Constructor_Default()
 {
     HelpController controller = new HelpController();
     Assert.Same(GlobalConfiguration.Configuration, controller.Configuration);
 }
Ejemplo n.º 7
0
        public void ResourceModel_ReturnsCachedModels_UnusedParameters(string modelName)
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{unused}/{id}", new { id = RouteParameter.Optional });
            HelpController controller = new HelpController(config);
            ModelDescriptionGenerator modelDescriptionGenerator = config.GetModelDescriptionGenerator();
            ModelDescription expectedModelDescription;
            modelDescriptionGenerator.GeneratedModels.TryGetValue(modelName, out expectedModelDescription);

            ViewResult result = Assert.IsType<ViewResult>(controller.ResourceModel(modelName));
            ViewResult result2 = Assert.IsType<ViewResult>(controller.ResourceModel(modelName));

            Assert.Same(expectedModelDescription, result.Model);
            Assert.Same(result.Model, result2.Model);
        }