public void ApplicationCommandProcessorExceptionOnDeleteReturnsFailedStatus() { var mockClient = new Mock <IFabricClientApplicationWrapper>(); var command = new ApplicationCommandProcessor(mockClient.Object); var result = new FabricOperationResult() { OperationStatus = new ApplicationOperationStatus() }; 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 ApplicationOperationDescription("appResource1") { OperationType = OperationType.Delete }; var context = new OperationContext(CancellationToken.None, TimeSpan.FromMinutes(1)); var task = command.CreateOperationStatusAsync(description, context).Result; Assert.IsInstanceOfType(task, typeof(ApplicationOperationStatus)); Assert.AreEqual(task.ResourceId, description.ResourceId); Assert.AreEqual(task.Status, ResultStatus.Failed); }
public void ApplicationCommandProcessorNoActionForOperationInProgress() { var mockClient = new Mock <IFabricClientApplicationWrapper>(); var command = new ApplicationCommandProcessor(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 ApplicationOperationDescription() { OperationType = OperationType.CreateOrUpdate, OperationSequenceNumber = 0, ResourceId = "/app1" }; 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>()), Times.Once()); mockClient .Verify( c => c.UpdateAsync(description, It.IsAny <IFabricOperationResult>(), It.IsAny <IOperationContext>()), Times.Never); }
public void ApplicationCommandProcessorDeleteWithNonNullStatus() { var mockClient = new Mock <IFabricClientApplicationWrapper>(); var command = new ApplicationCommandProcessor(mockClient.Object); var result = new FabricOperationResult() { OperationStatus = new ApplicationOperationStatus() }; 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 ApplicationOperationDescription() { OperationType = OperationType.Delete, OperationSequenceNumber = 0, ResourceId = "/app1" }; 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()); }
public void ApplicationCommandProcessorCreateAppIfNotExist() { var mockClient = new Mock <IFabricClientApplicationWrapper>(); var command = new ApplicationCommandProcessor(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 ApplicationOperationDescription() { OperationType = OperationType.CreateOrUpdate, OperationSequenceNumber = 0, ResourceId = "/app1" }; var context = new OperationContext(CancellationToken.None, TimeSpan.FromMinutes(1)); var task = command.CreateOperationStatusAsync(description, context); Assert.AreEqual(task.Result, null); mockClient .Verify( c => c.GetAsync(description, context), Times.Exactly(2)); 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); }