public void BeginExecuteInvokesProjectWithNoDataIfUsesInputIsFalseTest()
 {
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         UsesInput = false
     };
     int key = 1;
     var d = new ProjectExecutionDetail() { Key = key };
     var i = CreateItem(args, d);
     var rmMock = new Mock<IRuntimeManager>();
     var mre = new ManualResetEvent(false);
     i.BeginExecute(rmMock.Object, ei => mre.Set());
     mre.WaitOne(200);
     rmMock.Verify(m => m.Invoke(key), Times.Once());
     rmMock.Verify(m => m.Invoke(key, It.IsAny<IEnumerable<object>>()), Times.Never());
 }
 /// <summary>
 /// Identifies whether material information differs between a ProjectExecutionDetail and an
 /// IProjectInvocationRule.
 /// </summary>
 private bool DetailsHaveChanged(ProjectExecutionDetail detail, IProjectInvocationRule rule)
 {
     int ms1 = Helper.GetMilliseconds(detail.TimeLimit, detail.Unit);
     int ms2 = Helper.GetMilliseconds(rule.TimeLimit, rule.Unit);
     return ms1 != ms2 || detail.Path != rule.ProjectPath;
 }
 public void CallbackPassesReferenceToExecutionItemTest()
 {
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         UsesInput = false,
     };
     int key = 1;
     var d = new ProjectExecutionDetail() { Key = key };
     var i = CreateItem(args, d);
     var rm = new Mock<IRuntimeManager>().Object;
     var mre = new ManualResetEvent(false);
     IExecutionItem callbackArg = null;
     i.BeginExecute(rm, ei => {
         callbackArg = ei;
         mre.Set();
     });
     mre.WaitOne(200);
     Assert.AreSame(i, callbackArg);
 }
 private void PerformLoadVerificationTest(int? detailKey, Times loadInvocationTimes)
 {
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         ProjectPath = "path",
         UsesInput = false
     };
     var d = new ProjectExecutionDetail() { Key = detailKey };
     var i = CreateItem(args, d);
     var rmMock = new Mock<IRuntimeManager>();
     var mre = new ManualResetEvent(false);
     i.BeginExecute(rmMock.Object, ei => mre.Set());
     mre.WaitOne(200);
     rmMock.Verify(m => m.Load(args.ProjectPath, It.IsAny<IStartupArgs>()), loadInvocationTimes);
 }
 private void PerformWritesOutputDataTest(OperationStatus result, bool usesOutput)
 {
     object writtenData = null;
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         UsesInput = false,
         UsesOutput = usesOutput,
         WriteOutputData = new Action<object>(o => writtenData = o)
     };
     int key = 1;
     var d = new ProjectExecutionDetail() { Key = key };
     var i = CreateItem(args, d);
     var rmMock = new Mock<IRuntimeManager>();
     object data = new object();
     var orMock = new Mock<IOperationResult>();
     orMock.Setup(m => m.Status).Returns(result);
     orMock.Setup(m => m.Data).Returns(data);
     rmMock.Setup(m => m.Invoke(key)).Returns(orMock.Object);
     var mre = new ManualResetEvent(false);
     i.BeginExecute(rmMock.Object, ei => mre.Set());
     mre.WaitOne(200);
     if (result == OperationStatus.Ok && usesOutput) {
         Assert.AreSame(data, writtenData);
     }
     else {
         Assert.IsNull(writtenData);
     }
 }
 private void PerformAutoCreateLogTest(TextWriter log, bool expectedResult)
 {
     var d = new ProjectExecutionDetail() { Log = log };
     var i = CreateItem(null, d);
     Assert.AreEqual(expectedResult, i.AutoCreateLog);
 }
 private void PerformKeyTest(OperationStatus result, bool expectedKeyIsNull)
 {
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         UsesInput = false
     };
     int key = 1;
     var d = new ProjectExecutionDetail() { Key = key };
     var i = CreateItem(args, d);
     var rmMock = new Mock<IRuntimeManager>();
     var orMock = new Mock<IOperationResult>();
     orMock.Setup(m => m.Status).Returns(result);
     rmMock.Setup(m => m.Invoke(key)).Returns(orMock.Object);
     var mre = new ManualResetEvent(false);
     i.BeginExecute(rmMock.Object, ei => mre.Set());
     mre.WaitOne(200);
     if (expectedKeyIsNull) {
         Assert.IsNull(i.Key);
     }
     else {
         Assert.IsNotNull(i.Key);
         Assert.AreEqual(key, i.Key.Value);
     }
 }
 private static ExecutionItem CreateItem(MockProjectInvocationRuleSetupArgs args = null, ProjectExecutionDetail detail = null)
 {
     IProjectInvocationRule r = CreateRule(args);
     ProjectExecutionDetail d = detail ?? ProjectExecutionDetail.Create(r);
     return new ExecutionItem(r, d);
 }
 private static void SetupForLongInvocation(out ExecutionItem i, out IRuntimeManager manager)
 {
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         UsesInput = false
     };
     int key = 1;
     var d = new ProjectExecutionDetail() { Key = key };
     i = CreateItem(args, d);
     var rmMock = new Mock<IRuntimeManager>();
     rmMock.Setup(m => m.Invoke(key)).Callback(() => Thread.Sleep(200));
     manager = rmMock.Object;
 }
 public void UpToThreeDataAggregationsAttemptedTest()
 {
     int[] data = { 46 };
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         ProjectPath = "path",
         UsesInput = true,
         ReadInputData = data.Cast<object>()
     };
     var d = new ProjectExecutionDetail() { Key = 1 };
     var i = CreateItem(args, d);
     var rmMock = new Mock<IRuntimeManager>();
     var orMock = new Mock<IOperationResult>();
     orMock.Setup(m => m.Status).Returns(OperationStatus.StartupDataConversionProblem);
     rmMock.Setup(m => m.Invoke(It.IsAny<int>(), It.IsAny<object>())).Returns(orMock.Object);
     var mre = new ManualResetEvent(false);
     i.BeginExecute(rmMock.Object, ei => mre.Set());
     mre.WaitOne(200);
     rmMock.Verify(m => m.Invoke(It.IsAny<int>(), It.IsAny<object>()), Times.Exactly(3));
 }
 public void UnloadAttemptedIfAbortCalledWhileExecutingTest()
 {
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         UsesInput = false
     };
     int key = 1;
     var d = new ProjectExecutionDetail() { Key = key };
     var i = CreateItem(args, d);
     var rmMock = new Mock<IRuntimeManager>();
     rmMock.Setup(m => m.Invoke(key)).Callback(() => Thread.Sleep(200));
     i.BeginExecute(rmMock.Object, null);
     Thread.Sleep(100);
     i.Abort(rmMock.Object);
     rmMock.Verify(m => m.Unload(key), Times.Once());
 }
 public void ProjectReloadedIfDataConversionProblemTest()
 {
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         ProjectPath = "path",
         UsesInput = true,
         ReadInputData = new object[1]
     };
     var d = new ProjectExecutionDetail() { Key = 1 };
     var i = CreateItem(args, d);
     var rmMock = new Mock<IRuntimeManager>();
     var orMock = new Mock<IOperationResult>();
     orMock.Setup(m => m.Status).Returns(OperationStatus.StartupDataConversionProblem);
     rmMock.Setup(m => m.Invoke(It.IsAny<int>(), It.IsAny<object>())).Returns(orMock.Object);
     var mre = new ManualResetEvent(false);
     i.BeginExecute(rmMock.Object, ei => mre.Set());
     mre.WaitOne(200);
     rmMock.Verify(m => m.Load(args.ProjectPath, It.IsAny<IStartupArgs>()), Times.AtLeastOnce());
 }
 public void NullReturnFromInvocationIndicatesAbortedProjectTest()
 {
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         UsesInput = false
     };
     int key = 1;
     var d = new ProjectExecutionDetail() { Key = key };
     var i = CreateItem(args, d);
     var rmMock = new Mock<IRuntimeManager>();
     rmMock.Setup(m => m.Invoke(key)).Returns((IOperationResult)null);
     var mre = new ManualResetEvent(false);
     i.BeginExecute(rmMock.Object, ei => mre.Set());
     mre.WaitOne(200);
     Assert.AreEqual(ProjectExecutionState.Aborted, i.State);
 }
 public void InvocationErrorMessageWrittenToLogTest()
 {
     var args = new MockProjectInvocationRuleSetupArgs() {
         CanExecute = true,
         UsesInput = false,
     };
     int key = 1;
     var logMock = new Mock<TextWriter>();
     var d = new ProjectExecutionDetail() { Key = key, Log = logMock.Object };
     var i = CreateItem(args, d);
     var rmMock = new Mock<IRuntimeManager>();
     string errMsg = "This is an error message";
     rmMock.Setup(m => m.Invoke(key)).Callback(() => { throw new Exception(errMsg); });
     var mre = new ManualResetEvent(false);
     i.BeginExecute(rmMock.Object, ei => mre.Set());
     mre.WaitOne(200);
     logMock.Verify(m => m.WriteLine(errMsg));
 }