Пример #1
0
        public void SubscribeOnHomePage_WithDuplicateEmail_AlreadySubscribedMessage()
        {
            // Given
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper, defaults: to => to.Accept("application/json"));

            var result = browser.Post("/", with =>
            {
                with.FormValue("email", "*****@*****.**");
                with.FormValue("real", "");
                with.HttpRequest();
            });

            result = browser.Post("/", with =>
            {
                with.FormValue("email", "*****@*****.**");
                with.FormValue("real", "");
                with.HttpRequest();
            });

            // Then
            var commonResult = result.Body.DeserializeJson <CommonResult>();

            Assert.True(commonResult.Success);
            Assert.Equal("Already subscribed", commonResult.Message);
        }
Пример #2
0
        public void TestSetup()
        {
            // Arrange
            var bootstrapper = new DefaultNancyBootstrapper();

            _browser = new Browser(bootstrapper);
        }
Пример #3
0
        public void DebugRoute()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);


            var requestBody  = "{\"token\":\"fWLgDuiSNnxt2RYDhljCTbs0\",\"team_id\":\"T02FQR5EX\",\"channel_id\":\"C036W3BN3\",\"channel_name\":\"debug\",\"user_id\":\"U02NAKD4K\",\"user_name\":\"casperandersen\",\"command\":\" / imdb\",\"text\":\"test\"}";
            var slackCommand = new Model.SlackCommandRequest()
            {
                token        = "fWLgDuiSNnxt2RYDhljCTbs0",
                team_id      = "T02FQR5EX",
                channel_id   = "C036W3BN3",
                channel_name = "debug",
                user_id      = "U02NAKD4K",
                user_name    = "casperandersen",
                command      = "/imdb",
                text         = "test"
            };

            // When
            var result = browser.Post("/imdb/debug", with => {
                with.HttpRequest();
                with.JsonBody <Model.SlackCommandRequest>(slackCommand);
                with.Body(requestBody);
            });

            // Then
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Пример #4
0
        public void WebhookSearchResultResponse()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);

            var slackCommand = new Model.SlackCommandRequest()
            {
                token        = "fWLgDuiSNnxt2RYDhljCTbs0",
                team_id      = "T02FQR5EX",
                channel_id   = "C036W3BN3",
                channel_name = "debug",
                user_id      = "U02NAKD4K",
                user_name    = "casperandersen",
                command      = "/imdb",
                text         = "the 100"
            };

            // When
            var result = browser.Post("/imdb", with => {
                with.HttpRequest();
                with.JsonBody <Model.SlackCommandRequest>(slackCommand);
            });

            // Then
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Пример #5
0
 public MediatorServer(SystemConfiguration systemConfig, DataSource dataSource)
 {
     config = systemConfig.Servers.First(kvp => kvp.Value.Type == ServerTypes.Mediator).Value;
     controller = new Controller(dataSource);
     //			bootstrapper = new MediatorBootstrapper(controller);
     bootstrapper = new ApiBootstrapper(controller);
 }
Пример #6
0
        public void Setup()
        {
            boostrapper = new DefaultNancyBootstrapper();
            browser     = new Browser(boostrapper, defaults: to => to.Accept("application/json"));

            TestContext.WriteLine("test setup done");
        }
Пример #7
0
        public void can_delete_a_book()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);
            var result = browser.Delete("/books/destroy/1", with => with.HttpRequest());

            Assert.AreEqual(HttpStatusCode.OK.ToString(), result.StatusCode.ToString());
        }
Пример #8
0
        public NancyService()
        {
            var port       = AppSettings.ServerPort;
            var uriBuilder = new UriBuilder("http", "localhost", port);
            INancyBootstrapper bootStrapper = new DefaultNancyBootstrapper();

            _host = new NancyHost(uriBuilder.Uri);
        }
Пример #9
0
        public void ShouldReturnStatusOkWhenRouteExists1()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);
            var result       = browser.Get("/debug", with => { with.HttpRequest(); });

            Assert.AreEqual(HttpStatusCode.OK, result.Result.StatusCode);
        }
Пример #10
0
        protected RequestSpec()
        {
            var defaultNancyBootstrapper = new DefaultNancyBootstrapper();

            defaultNancyBootstrapper.Initialise();

            engine = defaultNancyBootstrapper.GetEngine();
        }
Пример #11
0
        protected RequestSpec()
        {
            var defaultNancyBootstrapper = new DefaultNancyBootstrapper();

            defaultNancyBootstrapper.Initialise();

            engine = defaultNancyBootstrapper.GetEngine();
        }
Пример #12
0
        public void Status_is_ok_on_root_path() {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            var result = browser.Get("/", with => with.HttpRequest());

            Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(result.Body.AsString(), Does.Not.Contain("[ERR!]"));
        }
Пример #13
0
        static void Main(string[] args)
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            bootstrapper.Initialise();
            var host = new NancyHost(bootstrapper, new Uri("http://127.0.0.1:8080"));

            host.Start();

            Console.ReadLine();
        }
        public void TestGet()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            var url = string.Format("/getProtoBuf/{0}/{1}", UserName, UserAge);
            var response = browser.Get(url, with => with.HttpRequest());

            CheckResponse(response, UserName, UserAge);
        }
Пример #15
0
        public async Task MainEndpoint()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);
            var result       = await browser.Get("/", with => {
                with.HttpRequest();
            });

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }
Пример #16
0
        public async Task Should_GetAnEmptyListOfStudentsAsync()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);

            var result = await browser.Get("/students", with => with.HttpRequest());

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            Assert.Equal("[]", result.Body.AsString());
        }
Пример #17
0
        public void Configuration(IAppBuilder app)
        {
            var bootstrapper = new DefaultNancyBootstrapper();

            app
                .UseFunc(LogRequests) // defined below
                .UseShowExceptions() // from Gate.Middleware package
                .MapHubs("/signalr") // from SignalR.Server assembly
                .RunNancy(bootstrapper); // from Gate.Adapters.Nancy package
        }
Пример #18
0
        public void Return_Not_Found_When_Asking_For_Empty_Guid()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);

            var result = browser.Get($"/scrape/1", with => {
                with.HttpRequest();
            });

            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
        public void DefaultTest()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            var result = browser.Get("/", with => {
                with.HttpRequest();
            });

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Пример #20
0
    public void WaitClientNotRegistered()
    {
      var bootstrapper = new DefaultNancyBootstrapper();
      var browser = new Browser(bootstrapper);

      var response = browser.Get(string.Format("http://127.0.0.1/Poll/Wait?clientId={0}&seqCode={1}", Guid.NewGuid().ToString(), 0));
      Assert.IsNotNull(response);
      var responseAsString = response.Body.AsString();
      Assert.IsNotNull(responseAsString);
      Assert.IsTrue(responseAsString.Contains("ClientNotRegistered"));
    }
Пример #21
0
        public void ReturnOKWhenDefaultRouteHit()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);

            // When
            var result = browser.Get("/", with => { with.HttpRequest(); });

            // Then
            Assert.Equal(HttpStatusCode.OK, result.Result.StatusCode);
        }
Пример #22
0
        public void TestOK()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);

            var result = browser.Get("/", with => {
                with.HttpRequest();
            });

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Пример #23
0
        public async Task SendData()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);
            var result       = await browser.Post("/data", with =>
            {
                with.HttpRequest();
            });

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }
Пример #24
0
        public void ReturnNotFoundWhenRouteDoesntExist()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);

            // When
            var result = browser.Get("/bla", with => { with.HttpRequest(); });

            // Then
            Assert.Equal(HttpStatusCode.NotFound, result.Result.StatusCode);
        }
Пример #25
0
        public void LoadAllModulesAndTestView()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            var response = browser.Get("/authors", (with) => {
                with.HttpRequest();
            });

            response.ShouldHaveRedirectedTo("/homeWithStylishMaster");
        }
Пример #26
0
        public void Bootstrapper_should_use_locator_if_not_specified()
        {
            // Given
            var bootstrapper = new DefaultNancyBootstrapper();
            NancyBootstrapperLocator.Bootstrapper = bootstrapper;

            //When
            //Then
            this.nancyOptions.Bootstrapper.ShouldNotBeNull();
            this.nancyOptions.Bootstrapper.ShouldBeSameAs(bootstrapper);
        }
Пример #27
0
        public void Should_return_status_ok_for_root()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            var result = browser.Get("/", with => {
                with.HttpRequest();
            });

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }
Пример #28
0
 public IntergrationTests()
 {
     // Given
     mock = new CallBacksMock();
     var bootstrapper = new DefaultNancyBootstrapper();
     var browser      = new Browser(bootstrapper);
     // When
     var result = browser.Get("/mock/callback", with =>
     {
         with.HttpRequest();
     });
 }
        public void Should_return_status_ok_when_route_exists()
        {
            // Given
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper, defaults: to => to.Accept("application/json"));

            // When
            var result = browser.Get("/", with => with.HttpRequest());

            // Then
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Пример #30
0
        public void ShouldReturnStatusOkWhenRouteExists()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            var result = browser.Get("/", with =>
            {
                with.HttpRequest();
            });

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Пример #31
0
        public void Main()
        {
            var host = new WebHostBuilder()
                       .UseStartup <Startup>()
                       .Build();

            host.Run();

            var bootstrapper = new DefaultNancyBootstrapper();

            _browser = new Browser(bootstrapper);
        }
Пример #32
0
        public void Bootstrapper_should_use_locator_if_not_specified()
        {
            // Given
            var bootstrapper = new DefaultNancyBootstrapper();

            NancyBootstrapperLocator.Bootstrapper = bootstrapper;

            //When
            //Then
            this.nancyOptions.Bootstrapper.ShouldNotBeNull();
            this.nancyOptions.Bootstrapper.ShouldBeSameAs(bootstrapper);
        }
Пример #33
0
        public void WaitClientNotRegistered()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);

            var response = browser.Get(string.Format("http://127.0.0.1/Poll/Wait?clientId={0}&seqCode={1}", Guid.NewGuid().ToString(), 0));

            Assert.IsNotNull(response);
            var responseAsString = response.Body.AsString();

            Assert.IsNotNull(responseAsString);
            Assert.IsTrue(responseAsString.Contains("ClientNotRegistered"));
        }
Пример #34
0
        public static void Amanda_Exposes_1_Parameter_Action()
        {
            var bootstraper = new DefaultNancyBootstrapper();
            var browser     = new Browser(bootstraper);

            var result = browser.Get("/api/DoNothingFor", ctx =>
            {
                ctx.Query("i", "5");
                ctx.HttpRequest();
            });

            result.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Пример #35
0
        public void Should_answer_Not_Empty_on_root_path()
        {
            // Given
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);

            // When
            var response = browser.Get("/image/", with => {
                with.HttpRequest();
            });

            Assert.NotEmpty(response.Result.Body);
        }
Пример #36
0
        public async Task Should_GetListOfStudentsAsync()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);
            var testStudent  = await browser.CreateTestStudentAsync();

            var result = await browser.Get("/students", with => with.HttpRequest());

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            var studentList = result.Body.DeserializeJson <Student[]>();

            Assert.Single(studentList, testStudent);
        }
Пример #37
0
        public void can_create_a_book()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);
            var newTitle = Guid.NewGuid().ToString();
            var result = browser.Post("/books/new", with =>
            {
                with.HttpRequest();
                with.FormValue("Title", newTitle);
            });

            Assert.AreEqual(HttpStatusCode.Created.ToString(), result.StatusCode.ToString());
        }
Пример #38
0
        public static void Amanda_Exposes_1_Parameter_Action()
        {
            var bootstraper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstraper);

            var result = browser.Get("/api/DoNothingFor", ctx =>
                                                              {
                                                                  ctx.Query("i", "5");
                                                                  ctx.HttpRequest();
                                                              });

            result.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Пример #39
0
        public async Task Should_GetListOfTeachersAsync()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);
            var testTeacher  = await browser.CreateTestTeacherAsync();

            var result = await browser.Get("/teachers", with => with.HttpRequest());

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
            var teacherList = result.Body.DeserializeJson <Teacher[]>();

            Assert.Single(teacherList, testTeacher);
        }
Пример #40
0
        public void TestMethod1()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);
            // When
            var result = browser.Post("/", with => {
                with.HttpRequest();
                with.Body(testdata_resources.customer);
            });

            // Then
            Assert.AreEqual(HttpStatusCode.OK, result.Result.StatusCode);
        }
        public async Task Should_return_status_ok_when_route_exists()
        {
            // Given
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper, defaults: to => to.Accept("application/json"));

            // When
            var result = await browser.Get("/shoppingcart/123", with => {
                with.HttpRequest();
            });

            // Then
            Assert.Equal(HttpStatusCode.OK, result.StatusCode);
        }
Пример #42
0
        public void TestNotFound()
        {
            //Arrange
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            //Act
            var result = browser.Delete("/routes", with => {
                with.HttpRequest();
            });

            //Assert
            Assert.AreEqual (HttpStatusCode.MethodNotAllowed, result.StatusCode);
        }
Пример #43
0
        public void ShouldReturnStatusOkWhenRouteExists3()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);
            var result       = browser.Get("/debugdataJson", with => { with.HttpRequest(); });

            Assert.AreEqual(HttpStatusCode.OK, result.Result.StatusCode);
            var actual = result.Result.Body.AsString().Replace(" ", string.Empty);
            var expect = JsonConvert.SerializeObject(new WorkerModule.DebugData {
                Name = "xxx", Status = true, Crc = 12345
            }).Replace(" ", string.Empty).ToLower();

            Assert.AreEqual(expect, actual);
        }
Пример #44
0
        public void TestThatEmptyPost_BadRequest()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);

            // When
            var result = browser.Post("/api/login", with =>
            {
                with.HttpRequest();
            });

            // Then
            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
        }
Пример #45
0
        public void TestThatEmptyPost_BadRequest()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            // When
            var result = browser.Post("/api/login", with =>
            {
                with.HttpRequest();
            });

            // Then
            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
        }
Пример #46
0
        public async Task TestGetAsync()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);
            var url          = string.Format("/getmsgpack/{0}/{1}", UserName, UserAge);

            var response = await browser.Get(url, with =>
            {
                with.HttpRequest();
                with.Accept(ConstValue.MessagePackContentType);
            });

            CheckResponse(response, UserName, UserAge);
        }
Пример #47
0
        public void ShouldReturnStatusOkWhenRouteExists2()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser      = new Browser(bootstrapper);
            var result       = browser.Get("/debugdataText", with => { with.HttpRequest(); });

            Assert.AreEqual(HttpStatusCode.OK, result.Result.StatusCode);
            var actual = result.Result.Body.AsString();
            var expect = new WorkerModule.DebugData {
                Name = "xxx", Status = true, Crc = 12345
            }.ToString();

            Assert.AreEqual(expect, actual);
        }
Пример #48
0
        public ComputeServer(SystemConfiguration systemConfig, string name, AlgorithmFactory algoFactory)
        {
            uuid = Guid.NewGuid().ToString();
            this.name = name;
            config = systemConfig.Servers[name];

            var mediatorConfig = systemConfig.Servers.First(kvp => kvp.Value.Type == ServerTypes.Mediator).Value;
            mediator = new MediatorConnector(mediatorConfig);

            workerPool = new WorkerPool(config.PoolSize, uuid, mediator);

            //bootstrapper = new ComputeBootstrapper(this, workerPool);
            bootstrapper = new ApiBootstrapper(this, workerPool, algoFactory);
        }
Пример #49
0
        public void LoadAllModulesAndTestThem()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            BrowserResponse response = browser.Get("/books", (with) => {
                with.HttpRequest();
                with.Accept("application/json");
            });

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual("application/json; charset=utf-8", response.Body.ContentType);
            Assert.IsTrue(response.Body.AsString().Length > 0);
            Console.WriteLine(response.Body.AsString());
        }
Пример #50
0
        public void TestMethod1()
        {
            // Given
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            // When
            var result = browser.Get("/", with =>
            {
                with.HttpRequest();
            });

            // Then
            Assert.IsTrue(HttpStatusCode.OK == result.StatusCode);
        }
Пример #51
0
        public void smoke_test()
        {
            // Given
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            // When
            var result = browser.Get("/books", with =>
            {
                with.HttpRequest();
            });

            // Then
            Assert.AreEqual(HttpStatusCode.OK.ToString(), result.StatusCode.ToString());
        }
Пример #52
0
        public void TestThatNonNetlightPost_BadRequest()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            // When
            var result = browser.Post("/api/login", with =>
            {
                with.FormValue("Username", "*****@*****.**");
                with.HttpRequest();
            });

            // Then
            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
        }
Пример #53
0
        public void TestPut()
        {
            //Arrange
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            //Act
            var result = browser.Put("/routes", with => {
                with.HttpRequest();
            });

            //Assert
            Assert.AreEqual (HttpStatusCode.OK, result.StatusCode);
            Assert.AreEqual ("Response with Put\n", result.Body.AsString());
        }
Пример #54
0
        public static void Amanda_Exposes_No_Parameter_Action()
        {
            var bootstraper = new DefaultNancyBootstrapper();
            var browser = new Browser(x =>
                                          {
                                              x.RootPathProvider(new DefaultRootPathProvider());
                                          });

            var result = browser.Get("/api/DoNothing", ctx =>
                                                           {
                                                               ctx.HttpRequest();
                                                           });

            result.StatusCode.Should().Be(HttpStatusCode.OK);
        }
        public void TestPost()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            // get the serialized bytes to the service
            var response = browser.Post(
                "/postProtoBuf",
                with =>
                {
                    with.HttpRequest();
                    with.FormValue("Name", UserName);
                    with.FormValue("Age", UserAge.ToString());
                });

            CheckResponse(response, UserName, UserAge);
        }
Пример #56
0
        public static void Amanda_Exposes_No_Parameter_Func()
        {
            var bootstraper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstraper);

            var wasteTime = browser.Get("/api/DoNothing", ctx =>
            {
                ctx.HttpRequest();
            });

            var result = browser.Get("/api/GetWastedTime", ctx =>
            {
                ctx.HttpRequest();
            });

            result.StatusCode.Should().Be(HttpStatusCode.OK);
            result.Body.AsString().Should().Be("1000");
        }
Пример #57
0
        public void Should_return_list_of_autocomplete_suggestions()
        {
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper);

            var result = browser.Get("/autocomplete", with => {
                with.HttpRequest();
                with.Accept(new Nancy.Responses.Negotiation.MediaRange("application/json"));
                with.Query("q", "man");
            });

            Assert.Equal(HttpStatusCode.OK, result.StatusCode);

            var response = (dynamic)JsonConvert.DeserializeObject<ExpandoObject>(result.Body.AsString());
            Assert.Equal(response.q, "man");
            Assert.Contains(response.d, (Predicate<dynamic>)(destination => (int)destination.k > 0));
            Assert.Contains(response.h, (Predicate<dynamic>)(hotel => (int)hotel.id > 0));
        }
Пример #58
0
    public void Register()
    {
      var bootstrapper = new DefaultNancyBootstrapper();
      var browser = new Browser(bootstrapper);

      var response = browser.Get("http://127.0.0.1/Poll/Register");
      var obj = JObject.Parse(response.Body.AsString()).ToObject<dynamic>();

      Assert.IsNotNull(obj);
      Assert.IsNotNull(obj.success);
      Assert.IsNotNull(obj.retcode);
      Assert.IsNotNull(obj.messageName);
      Assert.IsNotNull(obj.data);

      Assert.AreEqual(true, obj.success.Value);
      Assert.AreEqual("Ok", obj.retcode.Value);
      Assert.AreEqual(null, obj.messageName.Value);
      Assert.IsTrue(obj.data.Value is string);
    }
        public void Test1OneToOne()
        {
            // given
            var bootstrapper = new DefaultNancyBootstrapper();
            var browser = new Browser(bootstrapper, defaults: to => to.Accept("application/json"));
            ApiBootstrapper.AddOrUpdate("mock", new ApiMock());

            // request simple route.
            var result = browser.Get("mock/routing", with =>
            {
                with.Body(string.Empty);
                with.Header("content-type", "application/json");
                with.Query("vehicle", "car");
                with.Query("loc", "1,1");
                with.Query("loc", "3,4");
                with.HttpRequest();
            });

            // then not acceptable
            Assert.IsNotNull(result);
            var response = OsmSharp.Geo.Streams.GeoJson.GeoJsonConverter.ToFeatureCollection(result.Body.AsString());
            Assert.IsNotNull(response);
            Assert.AreEqual(1, response.Count);

            // request simple route but return full format.
            result = browser.Get("mock/routing", with =>
            {
                with.Body(string.Empty);
                with.Header("content-type", "application/json");
                with.Query("vehicle", "car");
                with.Query("loc", "1,1");
                with.Query("loc", "3,4");
                with.Query("format", "osmsharp");
                with.HttpRequest();
            });

            // then not acceptable
            Assert.IsNotNull(result);
            var route = result.Body.DeserializeJson<OsmSharp.Routing.Route>();
            Assert.IsNotNull(response);
            Assert.AreEqual(1, response.Count);
        }
Пример #60
0
        public static NancyHostWrapper CreateAndOpenSelfHost(INancyBootstrapper nancyBootstrapper = null, HostConfiguration configuration = null)
        {
            if (nancyBootstrapper == null)
            {
                nancyBootstrapper = new DefaultNancyBootstrapper();
            }

            var host = new NancyHost(nancyBootstrapper, configuration, BaseUri);

            try
            {
                host.Start();
            }
            catch
            {
                throw new Exception();
            }

            return new NancyHostWrapper(host);
        }