public void RemoteServerShouldWorkCorrectlyWithGlobalConfiguration()
        {
            MyWebApi.Server().IsLocatedAt("https://google.com");

            MyWebApi
            .Server()
            .WorkingRemotely()
            .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Get))
            .ShouldReturnHttpResponseMessage()
            .WithResponseTime(time => time.TotalMilliseconds > 0)
            .WithStatusCode(HttpStatusCode.OK);

            MyWebApi
            .Server()
            .WorkingRemotely()
            .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Delete))
            .ShouldReturnHttpResponseMessage()
            .WithResponseTime(time => time.TotalMilliseconds > 0)
            .WithStatusCode(HttpStatusCode.MethodNotAllowed);

            MyWebApi
            .Server()
            .WorkingRemotely()
            .WithHttpRequestMessage(req => req.WithRequestUri("/notfound"))
            .ShouldReturnHttpResponseMessage()
            .WithResponseTime(time => time.TotalMilliseconds > 0)
            .WithStatusCode(HttpStatusCode.NotFound);

            RemoteServer.DisposeGlobal();
        }
Пример #2
0
        public void RemoteServerShouldWorkCorrectlyWithGlobalConfiguration()
        {
            MyHttpServer.IsLocatedAt("http://google.com", clientHandler =>
            {
                clientHandler.AllowAutoRedirect = true;
            });

            MyHttpServer
            .WorkingRemotely()
            .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Get))
            .ShouldReturnHttpResponseMessage()
            .WithResponseTime(time => time.TotalMilliseconds > 0)
            .WithStatusCode(HttpStatusCode.OK)
            .ContainingContentHeader(HttpContentHeader.ContentType);

            MyHttpServer
            .WorkingRemotely()
            .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Delete))
            .ShouldReturnHttpResponseMessage()
            .WithResponseTime(time => time.TotalMilliseconds > 0)
            .WithStatusCode(HttpStatusCode.MethodNotAllowed);

            MyHttpServer
            .WorkingRemotely()
            .WithHttpRequestMessage(req => req.WithRequestUri("/notfound"))
            .ShouldReturnHttpResponseMessage()
            .WithResponseTime(time => time.TotalMilliseconds > 0)
            .WithStatusCode(HttpStatusCode.NotFound);

            RemoteServer.DisposeGlobal();
        }
        public void WorkingRemotelyWithoutAnyBaseAddressShouldThrowException()
        {
            RemoteServer.DisposeGlobal();

            MyWebApi
            .Server()
            .WorkingRemotely()
            .WithHttpRequestMessage(req => req.WithRequestUri("/users/ivaylokenov/repos"))
            .ShouldReturnHttpResponseMessage()
            .WithResponseTime(time => time.TotalMilliseconds > 0)
            .WithStatusCode(HttpStatusCode.NotFound)
            .ContainingContentHeader(HttpContentHeader.ContentType, "text/html; charset=UTF-8");
        }
Пример #4
0
        public void IsLocatedAtShouldConfigureGlobalRemoteServer()
        {
            MyWebApi.Server().IsLocatedAt("http://google.com");

            Assert.IsNotNull(RemoteServer.GlobalClient);
            Assert.IsTrue(RemoteServer.GlobalIsConfigured);
            Assert.AreEqual("http://google.com", RemoteServer.GlobalClient.BaseAddress.OriginalString);

            RemoteServer.DisposeGlobal();

            Assert.IsNull(RemoteServer.GlobalClient);
            Assert.IsFalse(RemoteServer.GlobalIsConfigured);
        }
Пример #5
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());
        }
Пример #6
0
        public void WorkingRemotelyWithoutAnyBaseAddressShouldThrowException()
        {
            RemoteServer.DisposeGlobal();

            var exception = Assert.Throws <InvalidOperationException>(() =>
            {
                MyHttpServer
                .WorkingRemotely()
                .WithHttpRequestMessage(req => req.WithRequestUri("/users/ivaylokenov/repos"))
                .ShouldReturnHttpResponseMessage()
                .WithResponseTime(time => time.TotalMilliseconds > 0)
                .WithStatusCode(HttpStatusCode.NotFound)
                .ContainingContentHeader(HttpContentHeader.ContentType, "text/html; charset=UTF-8");
            });

            Assert.Equal("No remote server is configured for this particular test case. Either call MyHttpServer.IsLocatedAt() to configure a new remote server or provide test specific base address.", exception.Message);
        }
Пример #7
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();
        }