public void InvokeTriggeredJob_ReadOnlyFileSystem_ShouldReturn503()
        {
            var triggeredJobsManagerMock = new Mock<ITriggeredJobsManager>();

            // simulate read-only enviroment
            triggeredJobsManagerMock
                .Setup(t => t.InvokeTriggeredJob(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
                .Throws<UnauthorizedAccessException>();

            var controller = new JobsController(
                triggeredJobsManagerMock.Object,
                Mock.Of<IContinuousJobsManager>(),
                Mock.Of<ITracer>());

            var fileSystem = new Mock<IFileSystem>();
            var dirBase = new Mock<DirectoryBase>();
            fileSystem.Setup(f => f.Directory).Returns(dirBase.Object);
            dirBase.Setup(d => d.CreateDirectory(It.IsAny<string>())).Throws<UnauthorizedAccessException>();
            FileSystemHelpers.Instance = fileSystem.Object;
            FileSystemHelpers.TmpFolder = @"D:\";   // value doesn`t really matter, just need to have something other than default value

            controller.Request = new HttpRequestMessage();

            HttpResponseMessage resMsg = controller.InvokeTriggeredJob("foo");
            Assert.Equal(HttpStatusCode.ServiceUnavailable, resMsg.StatusCode);
        }
Exemple #2
0
        public void InvokeTriggeredJob_ReadOnlyFileSystem_ShouldReturn503()
        {
            var triggeredJobsManagerMock = new Mock<ITriggeredJobsManager>();

            // simulate read-only enviroment
            triggeredJobsManagerMock
                .Setup(t => t.InvokeTriggeredJob(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
                .Throws<UnauthorizedAccessException>();

            var controller = new JobsController(
                triggeredJobsManagerMock.Object,
                Mock.Of<IContinuousJobsManager>(),
                Mock.Of<ITracer>());

            var fileSystem = new Mock<IFileSystem>();
            var dirBase = new Mock<DirectoryBase>();
            fileSystem.Setup(f => f.Directory).Returns(dirBase.Object);
            dirBase.Setup(d => d.CreateDirectory(It.IsAny<string>())).Throws<UnauthorizedAccessException>();
            FileSystemHelpers.Instance = fileSystem.Object;

            controller.Request = new HttpRequestMessage();

            using (KuduUtils.MockAzureEnvironment())
            {
                HttpResponseMessage resMsg = controller.InvokeTriggeredJob("foo");
                Assert.Equal(HttpStatusCode.ServiceUnavailable, resMsg.StatusCode);
            }
        }
        public void InvokeTriggeredJob_ShouldReturn202()
        {
            var controller = new JobsController(
                Mock.Of<ITriggeredJobsManager>(),
                Mock.Of<IContinuousJobsManager>(),
                Mock.Of<ITracer>());

            controller.Request = new HttpRequestMessage();

            HttpResponseMessage resMsg = controller.InvokeTriggeredJob("foo");
            Assert.Equal(HttpStatusCode.Accepted, resMsg.StatusCode);
        }
        public void InvokeARMTriggeredJob_ShouldReturn200()
        {
            var controller = new JobsController(
                Mock.Of<ITriggeredJobsManager>(),
                Mock.Of<IContinuousJobsManager>(),
                Mock.Of<ITracer>());

            controller.Request = new HttpRequestMessage();

            // Add header to simulate ARM request
            controller.Request.Headers.Add(Arm.ArmUtils.GeoLocationHeaderKey, "East US");

            HttpResponseMessage resMsg = controller.InvokeTriggeredJob("foo");
            Assert.Equal(HttpStatusCode.OK, resMsg.StatusCode);
        }