public void ApplicationCommandProcessorProcessReturnsOnlyNonNullResults() { 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.DeleteAsync(It.IsAny <IOperationDescription>(), It.IsAny <IOperationContext>())) .Throws(new Exception()); var context = new OperationContext(CancellationToken.None, TimeSpan.FromMinutes(10)); var descriptions = new List <IOperationDescription>() { new ApplicationOperationDescription() { OperationType = OperationType.CreateOrUpdate, OperationSequenceNumber = 0, ResourceId = "/app1" }, new ApplicationOperationDescription() { OperationType = OperationType.Delete, OperationSequenceNumber = 1, ResourceId = "/app1" } }; var task = command.ProcessAsync(descriptions, context); Assert.AreEqual(task.Result.Count, 1); }
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 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 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 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); }
public void ApplicationCommandProcessorProcessReturnsEmptyStatus() { var mockClient = new Mock <IFabricClientApplicationWrapper>(); var command = new ApplicationCommandProcessor(mockClient.Object); var descriptions = new List <IOperationDescription>(); var context = new OperationContext(CancellationToken.None, TimeSpan.FromMinutes(1)); var task = command.ProcessAsync(descriptions, context); Assert.IsFalse(task.Result.Any(), "Processing empty list should return no results."); }
public void ApplicationCommandProcessorProcessFaultsOnNull() { var mockClient = new Mock <IFabricClientApplicationWrapper>(); var command = new ApplicationCommandProcessor(mockClient.Object); try { command.ProcessAsync(null, null).Wait(); Assert.Fail($"Null {nameof(IOperationDescription)} did not throw an exception"); } catch (AggregateException ae) { Assert.IsTrue(ae.InnerException != null); Assert.IsInstanceOfType(ae.InnerException, typeof(ArgumentNullException)); } }
public void ApplicationCommandProcessorConstructorThrowsOnNullFabricClientWrapper() { var command = new ApplicationCommandProcessor(null); }