コード例 #1
0
        public void ExecuteAsync_IfBlobHasBeenDeleted_ReturnsSuccessResult()
        {
            // Arrange
            var    account    = new FakeAccount();
            string functionId = "FunctionId";

            // by default, Blob doesn't exist in the fake account, so it's as if it were deleted.
            BlobQueueTriggerExecutor product = CreateProductUnderTest();

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                BlobClient = account.CreateCloudBlobClient(),
                Executor   = CreateDummyTriggeredFunctionExecutor()
            };

            product.Register(functionId, registration);

            var message = CreateMessage(functionId, "OriginalETag");

            // Act
            Task <FunctionResult> task = product.ExecuteAsync(message, CancellationToken.None);

            // Assert
            Assert.True(task.Result.Succeeded);
        }
コード例 #2
0
        public void ExecuteAsync_IfBlobHasChanged_NotifiesWatcherAndReturnsSuccessResult()
        {
            var account = new FakeAccount();

            // Arrange
            string functionId = "FunctionId";

            SetEtag(account, TestContainerName, TestBlobName, "NewETag");
            Mock <IBlobWrittenWatcher> mock = new Mock <IBlobWrittenWatcher>(MockBehavior.Strict);

            mock.Setup(w => w.Notify(It.IsAny <ICloudBlob>()))
            .Verifiable();
            IBlobWrittenWatcher blobWrittenWatcher = mock.Object;

            BlobQueueTriggerExecutor product = CreateProductUnderTest(null, blobWrittenWatcher);

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                BlobClient = account.CreateCloudBlobClient(),
                Executor   = CreateDummyTriggeredFunctionExecutor()
            };

            product.Register(functionId, registration);

            var message = CreateMessage(functionId, "OriginalETag");

            // Act
            Task <FunctionResult> task = product.ExecuteAsync(message, CancellationToken.None);

            // Assert
            task.WaitUntilCompleted();
            mock.Verify();
            Assert.True(task.Result.Succeeded);
        }
コード例 #3
0
        // Set the etag on the specified blob
        private static void SetEtag(FakeAccount account, string containerName, string blobName, string etag)
        {
            Mock <ICloudBlob> mockBlob = new Mock <ICloudBlob>(MockBehavior.Strict);

            mockBlob.SetupGet(b => b.Properties).Returns(new BlobProperties().SetEtag(etag));
            mockBlob.SetupGet(b => b.Name).Returns(blobName);

            account.SetBlob(containerName, blobName, mockBlob.Object);
        }
コード例 #4
0
        public async Task ExecuteAsync_IfBlobIsUnchanged_CallsInnerExecutor()
        {
            // Arrange
            var    account          = new FakeAccount();
            string functionId       = "FunctionId";
            string matchingETag     = "ETag";
            Guid   expectedParentId = Guid.NewGuid();
            var    message          = CreateMessage(functionId, matchingETag);

            SetEtag(account, TestContainerName, TestBlobName, matchingETag);

            IBlobCausalityReader causalityReader = CreateStubCausalityReader(expectedParentId);

            FunctionResult expectedResult          = new FunctionResult(true);
            Mock <ITriggeredFunctionExecutor> mock = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);

            mock.Setup(e => e.TryExecuteAsync(It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>()))
            .Callback <TriggeredFunctionData, CancellationToken>(
                (mockInput, mockCancellationToken) =>
            {
                Assert.Equal(expectedParentId, mockInput.ParentId);

                var resultBlob = (ICloudBlob)mockInput.TriggerValue;
                Assert.Equal(TestBlobName, resultBlob.Name);
            })
            .ReturnsAsync(expectedResult)
            .Verifiable();

            ITriggeredFunctionExecutor innerExecutor = mock.Object;
            BlobQueueTriggerExecutor   product       = CreateProductUnderTest(causalityReader);

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                BlobClient = account.CreateCloudBlobClient(),
                Executor   = innerExecutor
            };

            product.Register(functionId, registration);

            // Act
            FunctionResult result = await product.ExecuteAsync(message, CancellationToken.None);

            // Assert
            Assert.Same(expectedResult, result);
            mock.Verify();
        }
コード例 #5
0
        public void ExecuteAsync_IfInnerExecutorFails_ReturnsFailureResult()
        {
            // Arrange
            var account = new FakeAccount();

            string functionId   = "FunctionId";
            string matchingETag = "ETag";

            SetEtag(account, TestContainerName, TestBlobName, matchingETag);

            IBlobCausalityReader causalityReader = CreateStubCausalityReader();

            FunctionResult expectedResult          = new FunctionResult(false);
            Mock <ITriggeredFunctionExecutor> mock = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict);

            mock.Setup(e => e.TryExecuteAsync(
                           It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(expectedResult)
            .Verifiable();

            BlobQueueTriggerExecutor product = CreateProductUnderTest(causalityReader);

            ITriggeredFunctionExecutor innerExecutor = mock.Object;
            BlobQueueRegistration      registration  = new BlobQueueRegistration
            {
                BlobClient = account.CreateCloudBlobClient(),
                Executor   = innerExecutor
            };

            product.Register(functionId, registration);

            var message = CreateMessage(functionId, matchingETag);

            // Act
            Task <FunctionResult> task = product.ExecuteAsync(message, CancellationToken.None);

            // Assert
            Assert.False(task.Result.Succeeded);
        }