示例#1
0
        public void ServiceCommandProcessorExceptionOnDeleteReturnsFailedStatus()
        {
            var mockClient = new Mock <IFabricClientApplicationWrapper>();
            var command    = new ServiceCommandProcessor(mockClient.Object);
            var result     = new FabricOperationResult()
            {
                OperationStatus = new ServiceOperationStatus()
            };

            mockClient
            .Setup(c => c.GetAsync(It.IsAny <IOperationDescription>(), It.IsAny <IOperationContext>()))
            .Returns(Task.FromResult <IFabricOperationResult>(result));
            mockClient
            .Setup(c => c.DeleteAsync(It.IsAny <IOperationDescription>(), It.IsAny <IOperationContext>()))
            .Throws(new Exception());
            var description = new StatefulServiceOperationDescription("statefulServiceResource1")
            {
                OperationType = OperationType.Delete
            };
            var context = new OperationContext(CancellationToken.None, TimeSpan.FromMinutes(1));

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

            Assert.IsInstanceOfType(task, typeof(ServiceOperationStatus));
            Assert.AreEqual(task.ResourceId, description.ResourceId);
            Assert.AreEqual(task.Status, ResultStatus.Failed);
        }
示例#2
0
        public void ServiceCommandProcessorDeleteWithNonNullStatus()
        {
            var mockClient = new Mock <IFabricClientApplicationWrapper>();
            var command    = new ServiceCommandProcessor(mockClient.Object);
            var result     = new FabricOperationResult()
            {
                OperationStatus = new ServiceOperationStatus()
            };

            mockClient
            .Setup(c => c.GetAsync(It.IsAny <IOperationDescription>(), It.IsAny <IOperationContext>()))
            .Returns(Task.FromResult <IFabricOperationResult>(result));
            mockClient
            .Setup(c => c.DeleteAsync(It.IsAny <IOperationDescription>(), It.IsAny <IOperationContext>()))
            .Returns(Task.FromResult(0));
            var description = new StatefulServiceOperationDescription()
            {
                OperationType           = OperationType.Delete,
                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.DeleteAsync(description, It.IsAny <IOperationContext>()),
                Times.Once());
        }