public void ExecuteAsync_IfInnerExecutorFails_ReturnsFailureResult()
        {
            // Arrange
            string functionId   = "FunctionId";
            string matchingETag = TouchBlob(TestContainerName, TestBlobName);

            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
            {
                BlobServiceClient = _blobServiceClient,
                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);
        }
        public void ExecuteAsync_IfBlobHasChanged_NotifiesWatcherAndReturnsSuccessResult()
        {
            // Arrange
            string functionId = "FunctionId";
            string eTag       = TouchBlob(TestContainerName, TestBlobName);
            Mock <IBlobWrittenWatcher> mock = new Mock <IBlobWrittenWatcher>(MockBehavior.Strict);

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

            BlobQueueTriggerExecutor product = CreateProductUnderTest(null, blobWrittenWatcher);

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                BlobServiceClient = _blobServiceClient,
                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);
        }
        public void ExecuteAsync_IfBlobHasBeenDeleted_ReturnsSuccessResult()
        {
            // Arrange
            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
            {
                BlobServiceClient = _blobServiceClient,
                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);

            // Validate log is written
            var logMessage = _loggerProvider.GetAllLogMessages().Single();

            Assert.AreEqual("BlobNotFound", logMessage.EventId.Name);
            Assert.AreEqual(LogLevel.Debug, logMessage.Level);
            Assert.AreEqual(3, logMessage.State.Count());
            Assert.AreEqual(TestBlobName, logMessage.GetStateValue <string>("blobName"));
            Assert.AreEqual(TestQueueMessageId, logMessage.GetStateValue <string>("queueMessageId"));
            Assert.True(!string.IsNullOrWhiteSpace(logMessage.GetStateValue <string>("{OriginalFormat}")));
        }
示例#4
0
        public void Register(string functionId, BlobQueueRegistration registration)
        {
            if (_started)
            {
                throw new InvalidOperationException("Registrations may not be added while the shared listener is running.");
            }

            _executor.Register(functionId, registration);
        }
示例#5
0
        private void RegisterWithSharedBlobQueueListenerAsync(
            SharedBlobQueueListener sharedBlobQueueListener,
            BlobServiceClient blobClient,
            QueueServiceClient queueClient)
        {
            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                Executor           = _executor,
                BlobServiceClient  = blobClient,
                QueueServiceClient = queueClient
            };

            sharedBlobQueueListener.Register(_functionDescriptor.Id, registration);
        }
        public async Task ExecuteAsync_IfBlobIsUnchanged_CallsInnerExecutor()
        {
            // Arrange
            string functionId       = "FunctionId";
            Guid   expectedParentId = Guid.NewGuid();

            string matchingETag = TouchBlob(TestContainerName, TestBlobName);
            var    message      = CreateMessage(functionId, 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.AreEqual(expectedParentId, mockInput.ParentId);

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

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

            BlobQueueRegistration registration = new BlobQueueRegistration
            {
                BlobServiceClient = _blobServiceClient,
                Executor          = innerExecutor
            };

            product.Register(functionId, registration);

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

            // Assert
            Assert.AreSame(expectedResult, result);
            mock.Verify();
        }
            private QueueClient GetPoisonQueue(QueueMessage message)
            {
                if (message == null)
                {
                    throw new ArgumentNullException(nameof(message));
                }

                var blobTriggerMessage = JsonConvert.DeserializeObject <BlobTriggerMessage>(message.Body.ToValidUTF8String());

                BlobQueueRegistration registration = null;

                if (_executor.TryGetRegistration(blobTriggerMessage.FunctionId, out registration))
                {
                    var poisonQueue = registration.QueueServiceClient.GetQueueClient(HostQueueNames.BlobTriggerPoisonQueue);
                    return(poisonQueue);
                }

                return(null);
            }
 public void Register(string functionId, BlobQueueRegistration registration)
 {
     _registrations.AddOrUpdate(functionId, registration, (i1, i2) => registration);
 }
 public bool TryGetRegistration(string functionId, out BlobQueueRegistration registration)
 {
     return(_registrations.TryGetValue(functionId, out registration));
 }