Esempio n. 1
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());
        }
Esempio n. 2
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);
        }
        public void AppReturnsBadRequestWhenCancelingPaidOrder()
        {
            var app = new Browser(new Bootstrapper());

              var createdResponse = CreatedOrder(app);
              var orderPath = GetOrderPath(createdResponse);

              var paymentResponse = app.Post(orderPath + "/payment/",
                                     with =>
                                     {
                                       with.HttpRequest();
                                       var xmlString = new PaymentRepresentation { CardNumber = "321", CardOwner = "Jose" }.ToXmlString();
                                       with.Body(xmlString);
                                     });
              Assert.That(paymentResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));

              var cancelResponse = app.Delete(orderPath);
              Assert.That(cancelResponse.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
        }
        public void AppCanCreateAndDeleteOrder()
        {
            var app = new Browser(new Bootstrapper());

              var createdResponse = CreatedOrder(app);

              Assert.That(createdResponse.StatusCode, Is.EqualTo(HttpStatusCode.Created));
              Assert.That(createdResponse.Headers.Keys, Contains.Item("Location"));

              var orderPath = GetOrderPath(createdResponse);

              var getOrderResponse = app.Get(orderPath);
              Assert.That(getOrderResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK), string.Format("order at {0} not found", orderPath));

              var deletedResponse = app.Delete(orderPath);
              Assert.That(deletedResponse.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));

              var getDeletedOrderResponse = app.Get(orderPath);
              Assert.That(getDeletedOrderResponse.StatusCode, Is.EqualTo(HttpStatusCode.MovedPermanently));
        }
Esempio n. 5
0
 protected override BrowserResponse ExecuteInternal(Browser browser)
 {
     return browser.Delete(Path, OnContext);
 }
Esempio n. 6
0
 public void TestDeleteDefaultGraph()
 {
     var mockJobInfo = new Mock<IJobInfo>();
     mockJobInfo.Setup(m => m.JobCompletedOk).Returns(true);
     IEnumerable<string> graphs = new string[] { "http://example.org/g1", "http://example.org/g2" };
     var brightstar = new Mock<IBrightstarService>();
     brightstar.Setup(s => s.DoesStoreExist("foo")).Returns(true).Verifiable();
     brightstar.Setup(s => s.ExecuteUpdate("foo", "DROP DEFAULT", true, "Drop Default Graph"))
         .Returns(mockJobInfo.Object).Verifiable();
     var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));
     var response = app.Delete("foo/graphs", with => with.Query("default", ""));
     Assert.That(response, Is.Not.Null);
     Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent));
     brightstar.Verify();
 }
Esempio n. 7
0
 public void TestDeleteUnknownNamedGraphReturnsNotFound()
 {
     IEnumerable<string> graphs = new string[] {"http://example.org/g1", "http://example.org/g2"};
     var brightstar = new Mock<IBrightstarService>();
     brightstar.Setup(s => s.DoesStoreExist("foo")).Returns(true).Verifiable();
     brightstar.Setup(s => s.ListNamedGraphs("foo")).Returns(graphs).Verifiable();
     var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));
     var response = app.Delete("foo/graphs", with => with.Query("graph", "http://example.org/g"));
     Assert.That(response, Is.Not.Null);
     Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
     brightstar.Verify();
 }
Esempio n. 8
0
        public void DeleteCorporation_ShouldReturn200()
        {
            var boostrapper = new Bootstrapper();
            var browser = new Browser(boostrapper, to => to.Accept("application/json"));
            var response = browser.Delete(@"http://localhost:59536/DeleteCorporation/564db279b99f725971d81658", with =>
            {
                with.HttpRequest();
                with.Accept(new MediaRange("application/json"));
            });

            var x = response.ReasonPhrase;

            Assert.AreEqual(Nancy.HttpStatusCode.OK, response.StatusCode);
        }
Esempio n. 9
0
        public void TestDeleteRequiresStoreAdminPermission()
        {
            var brightstar = new Mock<IBrightstarService>();
            var storePermissions = new Mock<AbstractStorePermissionsProvider>();

            storePermissions.Setup(s => s.HasStorePermission(null, "foo", StorePermissions.Admin)).Returns(false).Verifiable();
            var app = new Browser(new FakeNancyBootstrapper(brightstar.Object, storePermissions.Object));

            // Execute
            var response = app.Delete("/foo");

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
        }
Esempio n. 10
0
        public void TestDeleteHtmlResponse()
        {
            var brightstar = new Mock<IBrightstarService>();
            brightstar.Setup(s=>s.DoesStoreExist("foo")).Returns(true).Verifiable();
            brightstar.Setup(s => s.DeleteStore("foo")).Verifiable();
            var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));

            var response = app.Delete("/foo", c => c.Accept(MediaRange.FromString("text/html")));

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(response.Body.AsString(), Contains.Substring("Store 'foo' deleted successfully."));
            brightstar.Verify();
            
        }
Esempio n. 11
0
        public void TestDeleteReturnsOk()
        {
            var brightstar = new Mock<IBrightstarService>();
            brightstar.Setup(s=>s.DoesStoreExist("foo")).Returns(true).Verifiable();
            brightstar.Setup(s=>s.DeleteStore("foo")).Verifiable();
            var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));

            var response = app.Delete("/foo", c=>c.Accept(MediaRange.FromString("application/json")));

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            brightstar.Verify();
        }
Esempio n. 12
0
        public void Should_Return_Unauthorized_If_InvalidUser_Deleting()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            fakePostRepository.Setup(x => x.Delete(It.IsAny<int>())).Returns(false);

            var browser = new Browser(
                cfg =>
                {
                    cfg.Module<BlogModule>();
                    cfg.Dependencies<IPostRepository>(fakePostRepository.Object);
                });

            var result = browser.Delete("/1", with =>
            {
                with.HttpRequest();
                with.FormValue("Content", "Test Content");
            });

            Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode);
        }
Esempio n. 13
0
        public void Should_Return_ServerError_If_Cannot_Delete()
        {
            var fakePostRepository = new Mock<IPostRepository>();
            fakePostRepository.Setup(x => x.Delete(It.IsAny<int>())).Returns(false);

            var browser = new Browser(
                cfg =>
                {
                    cfg.Module<BlogModule>();
                    cfg.Dependencies<IPostRepository>(fakePostRepository.Object);
                    cfg.RequestStartup((container, pipelines, context) =>
                    {
                        context.CurrentUser = new UserIdentity { UserName = "******" };
                    });
                });

            var result = browser.Delete("/999", with =>
            {
                with.HttpRequest();
                with.FormValue("Content", "Test Content");
            });

            Assert.Equal(HttpStatusCode.InternalServerError, result.StatusCode);
        }