Exemplo n.º 1
0
        public void StartWithCustomHostShouldWorkCorrectly()
        {
            MyWebApi.Server().Starts <CustomStartup>(host: "https://localhost");

            Assert.AreEqual("https://localhost:80", OwinTestServer.GlobalClient.BaseAddress.OriginalString);

            MyWebApi.Server().Stops();
        }
 public void GetCommentsByUserShouldReturnUnauthorizedWhenUserIsNotAuthorized()
 {
     MyWebApi.Server().Working <Startup>()
     .WithHttpRequestMessage(r => r
                             .WithMethod(HttpMethod.Get)
                             .WithRequestUri("/api/Comments/ByUser/TestUser1"))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.Unauthorized);
 }
Exemplo n.º 3
0
 public void DeleteAlbumShouldReturnCorrectResponseWhenNotAuthorized()
 {
     MyWebApi.Server().Working <Startup>()
     .WithHttpRequestMessage(r => r
                             .WithMethod(HttpMethod.Delete)
                             .WithRequestUri("/api/albums/1"))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.Unauthorized);
 }
Exemplo n.º 4
0
 public void GetAlbumsByUserShouldReturnCorrectResponse()
 {
     MyWebApi.Server().Working <Startup>()
     .WithHttpRequestMessage(r => r
                             .WithMethod(HttpMethod.Get)
                             .WithRequestUri("/api/albums/user"))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.NotFound);
 }
 public void WithDefaultHeaderWithMultipleValuesShouldWorkCorrectly()
 {
     MyWebApi
     .Server()
     .Working <CustomStartup>()
     .WithDefaultRequestHeader("CustomHeader", new[] { "CustomValue", "AnotherValue" })
     .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Get))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.OK);
 }
        public void Init()
        {
            WebApiConfig.DependencyRegistrationAction = builder =>
            {
                builder.RegisterApiControllers(Assembly.Load(Assemblies.WebApi));
                builder.RegisterInstance(TestObjectFactory.GetCommitsService()).As <ICommitsService>();
            };

            MyWebApi.Server().Starts <Startup>();
        }
 public void RemoveDefaultHeadersNonExistingDoesNotThrowException()
 {
     MyWebApi
     .Server()
     .Working <CustomStartup>()
     .WithoutDefaultRequestHeader("Customheader")
     .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Get))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.NotFound)
     .WithStringContent("Header not found!");
 }
 public void RemoveDefaultHeadersAfterAddShouldWorkCorrectly()
 {
     MyWebApi
     .Server()
     .Working <CustomStartup>()
     .WithDefaultRequestHeader("CustomHeader", "CustomValue")
     .WithoutDefaultRequestHeader("Customheader")
     .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Get))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.NotFound)
     .WithStringContent("Header not found!");
 }
Exemplo n.º 9
0
        public void SecondStartsShouldStopTheFirstHttpServer()
        {
            MyWebApi.Server().Starts();

            var server = HttpTestServer.GlobalServer;

            MyWebApi.Server().Starts();

            var secondServer = HttpTestServer.GlobalServer;

            Assert.AreNotSame(server, secondServer);
        }
Exemplo n.º 10
0
        public void SecondStartsShouldStopTheFirstOwinServer()
        {
            MyWebApi.Server().Starts <CustomStartup>();

            var server = OwinTestServer.GlobalServer;

            MyWebApi.Server().Starts <CustomStartup>();

            var secondServer = OwinTestServer.GlobalServer;

            Assert.AreNotSame(server, secondServer);
        }
Exemplo n.º 11
0
 public void DeleteGadgetShouldReturnOk()
 {
     MyWebApi
     .Server()
     .Working()
     .WithHttpRequestMessage(
         request => request
         .WithMethod(HttpMethod.Delete)
         .WithRequestUri("/api/Gadgets/" + createdId))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.OK);
 }
Exemplo n.º 12
0
        public void WithResponseTimeShouldThrowExceptionIfPredicateIsNotValid()
        {
            var request = new HttpRequestMessage(HttpMethod.Post, "/test");

            MyWebApi
            .Server()
            .Working <CustomStartup>()
            .WithHttpRequestMessage(request)
            .ShouldReturnHttpResponseMessage()
            .WithResponseTime(
                responseTime => responseTime.TotalMilliseconds < 0);
        }
Exemplo n.º 13
0
        public void WithResponseTimePredicateShouldWorkCorrectly()
        {
            var request = new HttpRequestMessage(HttpMethod.Post, "/test");

            MyWebApi
            .Server()
            .Working <CustomStartup>()
            .WithHttpRequestMessage(request)
            .ShouldReturnHttpResponseMessage()
            .WithResponseTime(
                responseTime => responseTime.TotalMilliseconds > 0 && responseTime.TotalMilliseconds < int.MaxValue);
        }
 public void ByProjectShouldReturnCorrectResponse()
 {
     MyWebApi
     .Server()
     .Working <Startup>()
     .WithHttpRequestMessage(req => req
                             .WithRequestUri("api/Commits/ByProject/1")
                             .WithMethod(HttpMethod.Get))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.OK)
     .WithResponseModelOfType <List <ListedCommitResponseModel> >()
     .Passing(m => m.Count == 1);
 }
Exemplo n.º 15
0
        public void AndProvideTheResponseTimeShouldWorkCorrectly()
        {
            var request = new HttpRequestMessage(HttpMethod.Post, "/test");

            var responseTime = MyWebApi
                               .Server()
                               .Working <CustomStartup>()
                               .WithHttpRequestMessage(request)
                               .ShouldReturnHttpResponseMessage()
                               .AndProvideTheResponseTime();

            Assert.IsTrue(responseTime.TotalMilliseconds > 0);
        }
Exemplo n.º 16
0
        public void AndAlsoShouldWorkCorrectly()
        {
            var request = new HttpRequestMessage(HttpMethod.Post, "/test");

            MyWebApi
            .Server()
            .Working <CustomStartup>()
            .WithHttpRequestMessage(request)
            .ShouldReturnHttpResponseMessage()
            .WithResponseTime(responseTime => responseTime.TotalMilliseconds > 0)
            .AndAlso()
            .WithStatusCode(HttpStatusCode.Found);
        }
        public void Init()
        {
            NinjectConfig.RebindAction = kernel =>
            {
                kernel.Rebind <IRepository <Book> >().ToConstant(MocksFactory.BooksRepository);
                kernel.Rebind <IRepository <Author> >().ToConstant(MocksFactory.AuthorsRepository);
                kernel.Rebind <ApplicationUserManager>().ToConstant(MocksFactory.ApplicationUserManager);
            };

            this.server = MyWebApi.Server().Starts <Startup>();

            this.GetAccessToken();
        }
        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();
        }
        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>();
        }
Exemplo n.º 20
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);
        }
 public void WithDefaultHeadersShouldWorkCorrectly()
 {
     MyWebApi
     .Server()
     .Working <CustomStartup>()
     .WithDefaultRequestHeaders(new Dictionary <string, IEnumerable <string> >
     {
         { "CustomHeader", new[] { "CustomValue", "AnotherValue" } }
     })
     .WithHttpRequestMessage(req => req.WithMethod(HttpMethod.Get))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.OK);
 }
        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");
        }
        public void OwinTestsShouldWorkCorrectlyWithGlobalTestServer()
        {
            MyWebApi.Server().Starts <CustomStartup>();

            var request        = new HttpRequestMessage(HttpMethod.Post, "/test");
            var jsonRequest    = new HttpRequestMessage(HttpMethod.Post, "/json");
            var noModelRequest = new HttpRequestMessage(HttpMethod.Post, "/nomodel");

            MyWebApi
            .Server()
            .Working()
            .WithHttpRequestMessage(request)
            .ShouldReturnHttpResponseMessage()
            .WithStatusCode(HttpStatusCode.Found);

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

            MyWebApi
            .Server()
            .Working()
            .WithHttpRequestMessage(jsonRequest)
            .ShouldReturnHttpResponseMessage()
            .WithStatusCode(HttpStatusCode.OK)
            .AndAlso()
            .WithResponseModel(new ResponseModel {
                IntegerValue = 1, StringValue = "Test"
            });

            MyWebApi
            .Server()
            .Working()
            .WithHttpRequestMessage(noModelRequest)
            .ShouldReturnHttpResponseMessage()
            .WithStatusCode(HttpStatusCode.OK)
            .AndAlso()
            .WithResponseModel(new { id = 1 });

            MyWebApi
            .Server()
            .Working()
            .WithHttpRequestMessage(new HttpRequestMessage())
            .ShouldReturnHttpResponseMessage()
            .WithStatusCode(HttpStatusCode.NotFound);

            MyWebApi.Server().Stops();
        }
Exemplo n.º 24
0
 public void GetAlbumsByIdShouldReturnCorrectResponse()
 {
     MyWebApi.Server().Working <Startup>()
     .WithHttpRequestMessage(r => r
                             .WithMethod(HttpMethod.Get)
                             .WithRequestUri("/api/albums/1"))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.NotFound)
     .WithResponseModelOfType <AlbumViewModel>()
     .Passing(album =>
     {
         Assert.AreEqual(null, album);
     });
 }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
0
        public void GetCategoriesShouldReturnCorrectResponse()
        {
            MyWebApi
            .Server()
            .Working()
            .WithHttpRequestMessage(req => req
                                    .WithRequestUri("api/categories/2")
                                    .WithMethod(HttpMethod.Get))
            .ShouldReturnHttpResponseMessage()
            .WithStatusCode(HttpStatusCode.OK)
            .WithResponseModelOfType <CategoryResponseModel>();

            MyWebApi.Server().Stops();
        }
 public void GamesShouldReturnCorrectResponse()
 {
     MyWebApi.Server().Working <Startup>()
     .WithHttpRequestMessage(req => req
                             .WithMethod(HttpMethod.Get)
                             .WithRequestUri("/api/games"))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.OK)
     .WithResponseModelOfType <List <PublicGameResponseModel> >()
     .Passing(model =>
     {
         Assert.AreEqual(1, model.Count);
     });
 }
Exemplo n.º 28
0
        public void StartsAndStopsShouldWorkCorrectlyForHttpServers()
        {
            MyWebApi.Server().Starts(TestObjectFactory.GetHttpConfigurationWithRoutes());

            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);
        }
Exemplo n.º 29
0
 public void GetAlbumsAllShouldReturnCorrectResponse()
 {
     MyWebApi.Server().Working <Startup>()
     .WithHttpRequestMessage(r => r
                             .WithMethod(HttpMethod.Get)
                             .WithRequestUri("/api/albums/all"))
     .ShouldReturnHttpResponseMessage()
     .WithStatusCode(HttpStatusCode.OK)
     .WithResponseModelOfType <ICollection <AlbumViewModel> >()
     .Passing(collection =>
     {
         Assert.AreEqual(0, collection.Count);
     });
 }
Exemplo n.º 30
0
        public void SecondIsLocatedAtShouldReconfigureGlobalRemoteServer()
        {
            MyWebApi.Server().IsLocatedAt("http://google.com");

            var client = RemoteServer.GlobalClient;

            MyWebApi.Server().IsLocatedAt("http://mytestedasp.net");

            var secondClient = RemoteServer.GlobalClient;

            Assert.AreNotSame(client, secondClient);
            Assert.IsNotNull(secondClient);
            Assert.IsTrue(RemoteServer.GlobalIsConfigured);
            Assert.AreEqual("http://mytestedasp.net", RemoteServer.GlobalClient.BaseAddress.OriginalString);
        }