コード例 #1
0
        public void Init()
        {
            var config = new HttpConfiguration();

            WebApiConfig.Register(config);
            MyWebApi.IsUsing(WebApiConfig.Config);
        }
コード例 #2
0
        /// <summary>
        /// Sets custom inline constraint resolver to http configuration
        /// </summary>
        /// <param name="inlineConstraintResolver">Custom route constraint resolver to use.</param>
        /// <returns>New HTTP configuration builder.</returns>
        public IHttpConfigurationBuilder WithInlineConstraintResolver(IInlineConstraintResolver inlineConstraintResolver)
        {
            var config = InitializeHttpConfiguration();

            config.MapHttpAttributeRoutes(inlineConstraintResolver);

            return(MyWebApi.IsUsing(config));
        }
コード例 #3
0
        public void DefaultErrorDetailPolicyShouldBeAlways()
        {
            MyWebApi.IsUsingDefaultHttpConfiguration(TestObjectFactory.GetCustomInlineConstraintResolver());

            Assert.AreEqual(IncludeErrorDetailPolicy.Always, MyWebApi.Configuration.IncludeErrorDetailPolicy);

            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
        }
コード例 #4
0
        public void WithErrorDetailPolicyShouldSetCorrectErrorDetailPolicy()
        {
            MyWebApi.IsUsingDefaultHttpConfiguration().WithErrorDetailPolicy(IncludeErrorDetailPolicy.LocalOnly);

            Assert.AreEqual(IncludeErrorDetailPolicy.LocalOnly, MyWebApi.Configuration.IncludeErrorDetailPolicy);

            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
        }
コード例 #5
0
        public static void AssemblyInit(TestContext context)
        {
            AutoMapperConfig.RegisterMappings(Assembly.Load("Teleimot.WepApi"));

            var config = new HttpConfiguration();

            WebApiConfig.Register(config);
            MyWebApi.IsUsing(config);
        }
コード例 #6
0
        public void IsUsingDefaultConfigurationShouldWorkCorrectly()
        {
            MyWebApi.IsUsingDefaultHttpConfiguration(TestObjectFactory.GetCustomInlineConstraintResolver());

            Assert.IsNotNull(MyWebApi.Configuration);
            Assert.IsTrue(MyWebApi.Configuration.Routes.ContainsKey("API Default"));

            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
        }
コード例 #7
0
        public void IsRegisteredWithShouldWorkCorrectly()
        {
            MyWebApi.IsRegisteredWith(WebApiConfig.Register);

            Assert.IsNotNull(MyWebApi.Configuration);
            Assert.AreEqual(1, MyWebApi.Configuration.Routes.Count);

            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
        }
コード例 #8
0
        public static void AssemblyInitialize(TestContext context)
        {
            AutoMapperConfig.RegisterMappings(Assembly.Load(Assemblies.BALKAN_AIR_API));

            var config = new HttpConfiguration();

            WebApiConfig.Register(config);
            MyWebApi.IsUsing(config);
        }
コード例 #9
0
        public void IsUsingDefaultConfigurationShouldWorkCorrectly()
        {
            MyWebApi.IsUsingDefaultHttpConfiguration();

            Assert.IsNotNull(MyWebApi.Configuration);
            Assert.AreEqual(0, MyWebApi.Configuration.Routes.Count);

            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
        }
コード例 #10
0
        public void WithoutAnyConfigurationShouldInstantiateDefaultOne()
        {
            MyWebApi.IsUsing(null);

            var config = MyWebApi
                         .Handler <CustomDelegatingHandler>()
                         .AndProvideTheHttpConfiguration();

            Assert.IsNotNull(config);

            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
        }
コード例 #11
0
        public void WhenWithInlineConstraintResolverCalledShouldSetNewHttpConfigurationInstance()
        {
            var oldHttpConfiguration = MyWebApi.Configuration;

            MyWebApi
            .IsUsingDefaultHttpConfiguration()
            .WithInlineConstraintResolver(TestObjectFactory.GetCustomInlineConstraintResolver());

            Assert.AreNotSame(MyWebApi.Configuration, oldHttpConfiguration);

            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
        }
コード例 #12
0
        public void LinkGenerationShouldWorkCorrectlyWithDefaultConfiguration()
        {
            MyWebApi.IsUsingDefaultHttpConfiguration(TestObjectFactory.GetCustomInlineConstraintResolver());

            MyWebApi
            .Controller <WebApiController>()
            .Calling(c => c.WithGeneratedLink(1))
            .ShouldReturn()
            .Created()
            .AtLocation("http://localhost/api/test?id=1");

            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
        }
コード例 #13
0
        public void WithoutAnyConfigurationServersShouldThrowException()
        {
            MyWebApi.IsUsing(null);

            MyWebApi
            .Server()
            .Working()
            .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Post).WithRequestUri("api/NoAttributes/WithParameter/5"))
            .ShouldReturnHttpResponseMessage()
            .WithStatusCode(HttpStatusCode.OK)
            .AndAlso()
            .WithResponseModelOfType <int>();
        }
コード例 #14
0
        public void OwinServerStartsShouldReturnCorrectTestBuilder()
        {
            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());

            var server = MyWebApi.Server().Starts <CustomStartup>();

            server
            .WithHttpRequestMessage(req => req.WithHeader("CustomHeader", "CustomValue"))
            .ShouldReturnHttpResponseMessage()
            .WithStatusCode(HttpStatusCode.OK);

            MyWebApi.Server().Stops();
        }
コード例 #15
0
        public void AndStartsServerShouldStartServerCorrectly()
        {
            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes()).AndStartsServer();

            Assert.IsNotNull(HttpTestServer.GlobalServer);
            Assert.IsNotNull(HttpTestServer.GlobalClient);
            Assert.IsTrue(HttpTestServer.GlobalIsStarted);

            MyWebApi.Server().Stops();

            Assert.IsNull(HttpTestServer.GlobalServer);
            Assert.IsNull(HttpTestServer.GlobalClient);
            Assert.IsFalse(HttpTestServer.GlobalIsStarted);
        }
コード例 #16
0
        public static void AssemblyInit(TestContext context)
        {
            AutoMapperConfig.RegisterMappings(Assembly.Load(Constants.DataTransferModelsAssembly));
            Mapper.CreateMap <AttachmentRequestModel, Attachment>();
            Mapper.CreateMap <ProjectRequestModel, Project>();
            Mapper.CreateMap <ProjectWorkLogRequestModel, WorkLog>();
            Mapper.CreateMap <CategoryRequestModel, Category>();

            var config = new HttpConfiguration();

            WebApiConfig.Register(config);
            MyWebApi.IsUsing(config);

            // DatabaseConfig.Initialize();
        }
コード例 #17
0
        public void LinkGenerationShouldWorkCorrectlyWithCustomBaseAddress()
        {
            MyWebApi
            .IsUsingDefaultHttpConfiguration(TestObjectFactory.GetCustomInlineConstraintResolver())
            .WithBaseAddress("http://mytestedasp.net");

            MyWebApi
            .Controller <WebApiController>()
            .Calling(c => c.WithGeneratedLink(1))
            .ShouldReturn()
            .Created()
            .AtLocation("http://mytestedasp.net/api/test?id=1");

            RemoteServer.DisposeGlobal();
            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
        }
コード例 #18
0
        public void ServerStartsShouldReturnCorrectTestBuilder()
        {
            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());

            var server = MyWebApi.Server().Starts();

            server
            .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Post).WithRequestUri("api/NoAttributes/WithParameter/5"))
            .ShouldReturnHttpResponseMessage()
            .WithStatusCode(HttpStatusCode.OK)
            .AndAlso()
            .WithResponseModelOfType <int>()
            .Passing(m => m == 5);

            MyWebApi.Server().Stops();
        }
コード例 #19
0
        public void WithoutAnyConfigurationShouldInstantiateDefaultOne()
        {
            MyWebApi.IsUsing(null);

            var config = MyWebApi
                         .Controller <WebApiController>()
                         .WithHttpRequestMessage(request => request.WithMethod(HttpMethod.Get))
                         .Calling(c => c.CustomRequestAction())
                         .ShouldReturn()
                         .BadRequest()
                         .AndProvideTheController()
                         .Configuration;

            Assert.IsNotNull(config);

            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
        }
コード例 #20
0
        public static void Initialize(TestContext testContext)
        {
            NinjectConfig.DependenciesRegistration = kernel =>
            {
                kernel.Bind(typeof(IRepository <User>)).ToConstant(Repositories.GetUsersRepository());

                kernel.Bind(typeof(IRepository <RealEstate>)).ToConstant(Repositories.GetRealEstatesRepository());

                kernel.Bind(typeof(IRepository <Comment>)).ToConstant(Repositories.GetCommentsRepository());
            };

            AutoMapperConfig.RegisterMappings(Assemblies.WebApi);

            var config = new HttpConfiguration();

            WebApiConfig.Register(config);
            MyWebApi.IsUsing(config);
        }
コード例 #21
0
        public void WithBaseAddressShouldChangedDefaultAddress()
        {
            Assert.IsFalse(RemoteServer.GlobalIsConfigured);
            Assert.AreEqual(MyWebApi.DefaultHost, MyWebApi.BaseAddress.OriginalString);

            string address = "http://mytestedasp.net";

            MyWebApi
            .IsUsingDefaultHttpConfiguration(TestObjectFactory.GetCustomInlineConstraintResolver())
            .WithBaseAddress(address);

            Assert.AreEqual(address, MyWebApi.BaseAddress.OriginalString);
            Assert.IsTrue(RemoteServer.GlobalIsConfigured);

            MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());

            Assert.AreEqual(MyWebApi.DefaultHost, MyWebApi.BaseAddress.OriginalString);

            RemoteServer.DisposeGlobal();
        }
コード例 #22
0
        public void GetAnIssue()
        {
            // starts HTTP server with global configuration
            // set with MyWebApi.IsUsing
            // * the server is disposed after the test
            // * HTTP request can be set just like in the controller unit tests
            // * HTTP response can be tested just like in the controller unit tests
            //MyWebApi.IsUsing(GlobalConfiguration.Configuration)

            var config = new HttpConfiguration {
                IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always
            };

            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "TestRoute",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional });
            var controllerFactory = new TestIssuesControllerActivator();

            config.Services.Replace(
                typeof(IHttpControllerActivator),
                controllerFactory);

            MyWebApi.IsUsing(config);
            MyWebApi
            .Server()
            .Working()     // working will instantiate new HTTP server with the global configuration
            .WithHttpRequestMessage(
                request => request
                .WithMethod(HttpMethod.Get)
                .WithRequestUri("api/issues"))
            .ShouldReturnHttpResponseMessage()
            .WithStatusCode(HttpStatusCode.OK);
        }
コード例 #23
0
 public void RestoreConfiguration()
 {
     MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
 }
コード例 #24
0
ファイル: ServerTests.cs プロジェクト: vip32/MyTested.WebApi
        public void StartsShouldThrowExceptionWithoutAnyConfiguration()
        {
            MyWebApi.IsUsing(null);

            MyWebApi.Server().Starts();
        }