Example #1
0
        public void ServiceCommandProcessorNoActionForOperationInProgress()
        {
            var mockClient = new Mock <IFabricClientApplicationWrapper>();
            var command    = new ServiceCommandProcessor(mockClient.Object);

            mockClient
            .Setup(c => c.GetAsync(It.IsAny <IOperationDescription>(), It.IsAny <IOperationContext>()))
            .Returns(Task.FromResult <IFabricOperationResult>(null));
            mockClient
            .Setup(c => c.CreateAsync(It.IsAny <IOperationDescription>(), It.IsAny <IOperationContext>()))
            .Returns(Task.FromResult(0));
            var description = new StatelessServiceOperationDescription()
            {
                OperationType           = OperationType.CreateOrUpdate,
                OperationSequenceNumber = 0,
                ResourceId = "/svc1"
            };
            var context = new OperationContext(CancellationToken.None, TimeSpan.FromMinutes(1));

            command.CreateOperationStatusAsync(description, context).Wait();
            command.CreateOperationStatusAsync(description, context).Wait();
            mockClient
            .Verify(
                c => c.GetAsync(description, context),
                Times.Exactly(3));
            mockClient
            .Verify(
                c => c.CreateAsync(description, It.IsAny <IOperationContext>() /*context is changed in the method*/),
                Times.Once());
            mockClient
            .Verify(
                c => c.UpdateAsync(description, It.IsAny <IFabricOperationResult>(), It.IsAny <IOperationContext>()),
                Times.Never);
        }
Example #2
0
        public void ServiceCommandProcessorTransientExceptionReturnsNoStatus()
        {
            var mockClient = new Mock <IFabricClientApplicationWrapper>();
            var command    = new ServiceCommandProcessor(mockClient.Object);

            mockClient
            .Setup(c => c.GetAsync(It.IsAny <IOperationDescription>(), It.IsAny <IOperationContext>()))
            .Returns(Task.FromResult <IFabricOperationResult>(null));
            mockClient
            .Setup(c => c.CreateAsync(It.IsAny <IOperationDescription>(), It.IsAny <IOperationContext>()))
            .Throws(new System.Fabric.FabricTransientException());
            var description = new StatelessServiceOperationDescription("statelessServiceResource1")
            {
                OperationType = OperationType.CreateOrUpdate
            };
            var context = new OperationContext(CancellationToken.None, TimeSpan.FromMinutes(1));

            var status = command.CreateOperationStatusAsync(description, context).Result;

            Assert.AreEqual(status, null);
        }
Example #3
0
        public void ServiceCommandProcessorUpdateAppIfExists()
        {
            var mockClient = new Mock <IFabricClientApplicationWrapper>();
            var command    = new ServiceCommandProcessor(mockClient.Object);
            var result     = new FabricOperationResult()
            {
                OperationStatus = new ServiceOperationStatus(),
                QueryResult     = new ServiceClientFabricQueryResult(null)
            };

            mockClient
            .Setup(c => c.GetAsync(It.IsAny <IOperationDescription>(), It.IsAny <IOperationContext>()))
            .Returns(Task.FromResult <IFabricOperationResult>(result));
            mockClient
            .Setup(c => c.UpdateAsync(It.IsAny <IOperationDescription>(), It.IsAny <IFabricOperationResult>(), It.IsAny <IOperationContext>()))
            .Returns(Task.FromResult(0));
            var description = new StatelessServiceOperationDescription()
            {
                OperationType           = OperationType.CreateOrUpdate,
                OperationSequenceNumber = 0,
                ResourceId = "/svc1"
            };
            var context = new OperationContext(CancellationToken.None, TimeSpan.FromMinutes(1));

            var task = command.CreateOperationStatusAsync(description, context);

            Assert.AreNotEqual(task.Result, null);
            mockClient
            .Verify(
                c => c.GetAsync(description, context),
                Times.Exactly(2));
            mockClient
            .Verify(
                c => c.CreateAsync(description, It.IsAny <IOperationContext>()),
                Times.Never);
            mockClient
            .Verify(
                c => c.UpdateAsync(description, result, It.IsAny <IOperationContext>()),
                Times.Once());
        }