Exemple #1
0
        private static void TestValidPost(string toUrl, JobRequestObject requestObject, Action<Mock<IBrightstarService>, Mock<IJobInfo>> brightstarSetup)
        {
            var mockJobInfo = new Mock<IJobInfo>();
            mockJobInfo.Setup(s => s.JobId).Returns("ABCD");
            var brightstar = new Mock<IBrightstarService>();
            brightstarSetup(brightstar, mockJobInfo);
            var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));

            // Execute
            var response = app.Post(toUrl, with =>
                {
                    with.Accept(MediaRange.FromString("application/json"));
                    with.JsonBody(requestObject);
                });

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created));
            Assert.That(response.Headers["Location"], Is.EqualTo("foo/jobs/ABCD"));
            brightstar.Verify();
        }
Exemple #2
0
        private void AssertPermissionRequired(JobRequestObject jobRequest, StorePermissions witheldPermission)
        {
            var brightstar = new Mock<IBrightstarService>();
            var permissionsService = new Mock<AbstractStorePermissionsProvider>();
            permissionsService.Setup(s => s.GetStorePermissions(null, "foo"))
                              .Returns(StorePermissions.All ^ witheldPermission)
                              .Verifiable();
            var app = new Browser(new FakeNancyBootstrapper(brightstar.Object, permissionsService.Object));

            // Execute
            var response = app.Post("/foo/jobs", with =>
            {
                with.Accept(MediaRange.FromString("application/json"));
                with.JsonBody(jobRequest);
            });

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
            permissionsService.Verify();
        }