public void ConstructorSetsProject() { var project = new Project(); var context = new IntegrationContext(project); Assert.AreSame(project, context.Item); }
public void WaitWillContinueIfNotLocked() { var project = new Project(); var context = new IntegrationContext(project); var released = context.Wait(TimeSpan.FromMilliseconds(5)); Assert.IsTrue(released); }
/// <summary> /// Constructor. /// </summary> /// <param name="context">Integration context.</param> protected FeatureCoordinator(IntegrationContext context) { Configuration = context.Configuration; _featureAggregator = new FeatureReportGenerator(Configuration.ReportWritersConfiguration().ToArray()); RunnerRepository = new FeatureRunnerRepository(context); ValueFormattingService = context.ValueFormattingService; }
/// <summary> /// Asks the host if an integration can start. /// </summary> /// <returns> /// <c>true</c> if the integration can start; <c>false</c> otherwise. /// </returns> private bool AskHost() { var integrate = this.Host == null; if (!integrate && (this.currentContext == null)) { this.currentContext = new IntegrationContext(this); logger.Debug("Asking host if '{0}' can integrate", this.Name); this.Host.AskToIntegrate(this.currentContext); if (this.currentContext.IsLocked) { this.currentContext.Released += OnContextReleased; } else { integrate = !this.currentContext.WasCancelled; if (!integrate) { this.currentContext = null; } } } return(integrate); }
public void AskToIntegrateFailsIfUnableToLock() { var project = new ProjectStub(); var queue = new TestQueue(); var context = new IntegrationContext(project); queue.Lock(); Assert.Throws<Exception>(() => queue.AskToIntegrate(context)); }
public void AskToIntegrateDoesNothingWithNoHost() { var project = new Project(); var context = new IntegrationContext(project); project.AskToIntegrate(context); Assert.IsTrue(context.Wait(TimeSpan.FromMilliseconds(1))); }
public FeatureRunner(Type featureType, IntegrationContext integrationContext) { _featureType = featureType; _integrationContext = integrationContext; _exceptionProcessor = new ExceptionProcessor(_integrationContext); _featureResult = new FeatureResult(_integrationContext.MetadataProvider.GetFeatureInfo(featureType)); integrationContext.FeatureProgressNotifier.NotifyFeatureStart(_featureResult.Info); }
public ScenarioBuilder(object fixture, IntegrationContext integrationContext, ExceptionProcessor exceptionProcessor, Action <IScenarioResult> onScenarioFinished) { _context = new RunnableScenarioContext( integrationContext, exceptionProcessor, onScenarioFinished, integrationContext.ScenarioProgressNotifierProvider.Invoke(fixture), ProvideSteps); }
public void AskToIntegrateFailsIfUnableToLock() { var project = new ProjectStub(); var queue = new TestQueue(); var context = new IntegrationContext(project); queue.Lock(); Assert.Throws <Exception>(() => queue.AskToIntegrate(context)); }
public void CompletingAnIntegrationFailsIfUnableToLock() { var project = new ProjectStub(); var queue = new TestQueue(); var context = new IntegrationContext(project); queue.AskToIntegrate(context); queue.Lock(); Assert.Throws<Exception>(context.Complete); }
public void WaitWillTimeoutIfNotReleased() { var project = new Project(); var context = new IntegrationContext(project); context.Lock(); var released = context.Wait(TimeSpan.FromMilliseconds(5)); Assert.IsFalse(released); Assert.IsFalse(context.WasCancelled); }
public void CompletedIsFiredOnComplete() { var project = new Project(); var context = new IntegrationContext(project); var wasFired = false; context.Completed += (o, e) => wasFired = true; context.Complete(); Assert.IsTrue(wasFired); }
/// <summary> /// Called when an integration has completed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void OnIntegrationCompleted(object sender, EventArgs e) { var context = sender as IntegrationContext; if ((this.currentContext != null) && !this.currentContext.IsCompleted) { logger.Debug("Telling host integration has completed in '{0}'", this.Name); this.currentContext.Complete(); this.currentContext = null; } IntegrationContext nextRequest = null; var locked = false; try { locked = this.interleave.TryEnterWriteLock(TimeSpan.FromSeconds(1)); if (locked) { logger.Debug("Removing '{0}' from '{1}'", context.Item.Name, this.Name); context.Completed -= OnIntegrationCompleted; this.activeRequests.Remove(context); if ((this.pendingRequests.Count > 0) && this.AskHost()) { nextRequest = this.pendingRequests[0]; this.pendingRequests.Remove(nextRequest); logger.Info("Activating '{0}' in '{1}'", nextRequest.Item.Name, this.Name); this.activeRequests.Add(nextRequest); nextRequest.Completed += OnIntegrationCompleted; } } else { var message = "Unable to update queue '" + this.Name + "' - unable to acquire lock"; logger.Error(message); // TODO: Replace with custom exception throw new Exception(message); } } finally { if (locked) { this.interleave.ExitWriteLock(); } } // Release the next request if (nextRequest != null) { nextRequest.Release(); } }
public void CompletingAnIntegrationFailsIfUnableToLock() { var project = new ProjectStub(); var queue = new TestQueue(); var context = new IntegrationContext(project); queue.AskToIntegrate(context); queue.Lock(); Assert.Throws <Exception>(context.Complete); }
public void CompletingAnIntegrationRemovesItFromActiveRequests() { var project = new ProjectStub(); var queue = new Queue(); var context = new IntegrationContext(project); queue.AskToIntegrate(context); context.Complete(); Assert.AreEqual(0, queue.GetActiveRequests().Count()); Assert.AreEqual(0, queue.GetPendingRequests().Count()); }
/// <summary> /// Called when the current context has been released. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void OnContextReleased(object sender, EventArgs e) { var integrate = !this.currentContext.WasCancelled; var locked = false; IntegrationContext nextRequest = null; try { locked = this.interleave.TryEnterWriteLock(TimeSpan.FromSeconds(1)); if (locked) { if (this.pendingRequests.Count > 0) { nextRequest = this.pendingRequests[0]; this.pendingRequests.Remove(nextRequest); if (integrate) { logger.Info("Activating '{0}' in '{1}'", nextRequest.Item.Name, this.Name); this.activeRequests.Add(nextRequest); nextRequest.Completed += OnIntegrationCompleted; } } } else { var message = "Unable to update queue '" + this.Name + "' - unable to acquire lock"; logger.Error(message); // TODO: Replace with custom exception throw new Exception(message); } } finally { if (locked) { this.interleave.ExitWriteLock(); } } // Release or cancel the next request if (nextRequest != null) { if (integrate) { nextRequest.Release(); } else { logger.Info("Cancelling '{0}' in '{1}'", nextRequest.Item.Name, this.Name); nextRequest.Cancel(); } } }
public FeatureRunner(Type featureType, IntegrationContext integrationContext) { _featureType = featureType; _integrationContext = integrationContext; _featureResult = new FeatureResult(_integrationContext.MetadataProvider.GetFeatureInfo(featureType)); _scenarioExecutor = new ScenarioExecutor(new ExtendableExecutor(integrationContext.ExecutionExtensions)); _scenarioExecutor.ScenarioExecuted += _featureResult.AddScenario; integrationContext.FeatureProgressNotifier.NotifyFeatureStart(_featureResult.Info); }
public RunnableScenarioContext(IntegrationContext integrationContext, ExceptionProcessor exceptionProcessor, Action <IScenarioResult> onScenarioFinished, IScenarioProgressNotifier progressNotifier, ProvideStepsFunc stepsProvider) { IntegrationContext = integrationContext; ExceptionProcessor = exceptionProcessor; OnScenarioFinished = onScenarioFinished; ProgressNotifier = progressNotifier; StepsProvider = stepsProvider; }
public void AskToIntegrateWillTriggerProjectIfFirst() { var project = new ProjectStub(); var queue = new Queue(); var context = new IntegrationContext(project); queue.AskToIntegrate(context); var canIntegrate = context.Wait(TimeSpan.FromSeconds(5)); Assert.IsTrue(canIntegrate); var active = queue.GetActiveRequests(); Assert.AreEqual(1, active.Count()); Assert.AreEqual(0, queue.GetPendingRequests().Count()); Assert.AreSame(active.First(), context); }
public void WaitWillContinueWhenReleased() { var project = new Project(); var context = new IntegrationContext(project); var releaseThread = new Thread(o => { Thread.Sleep(TimeSpan.FromSeconds(1)); context.Release(); }); releaseThread.Start(); context.Lock(); var released = context.Wait(TimeSpan.FromSeconds(5)); Assert.IsTrue(released); }
public void CancelWillReleaseALock() { var project = new Project(); var context = new IntegrationContext(project); var releaseThread = new Thread(o => { Thread.Sleep(TimeSpan.FromSeconds(1)); context.Cancel(); }); releaseThread.Start(); context.Lock(); var released = context.Wait(TimeSpan.FromSeconds(5)); Assert.IsFalse(released); Assert.IsTrue(context.WasCancelled); }
public void AskToIntegrateAsksHostToContinue() { var context = new IntegrationContext(null); var wasCalled = false; var hostMock = new Mock <ServerItem>(MockBehavior.Strict); hostMock.Setup(h => h.AskToIntegrate(context)).Callback(() => wasCalled = true); var project = new Project { Host = hostMock.Object }; project.AskToIntegrate(context); Assert.IsTrue(context.Wait(TimeSpan.FromMilliseconds(1))); Assert.IsTrue(wasCalled); }
public void AskToIntegrateWillQueueSubsequentItems() { var queue = new Queue(); var project1 = new ProjectStub(); var project2 = new ProjectStub(); var context1 = new IntegrationContext(project1); var context2 = new IntegrationContext(project2); queue.AskToIntegrate(context1); queue.AskToIntegrate(context2); var active = queue.GetActiveRequests(); var pending = queue.GetPendingRequests(); Assert.AreEqual(1, active.Count()); Assert.AreEqual(1, pending.Count()); Assert.AreSame(active.First(), context1); Assert.AreSame(pending.First(), context2); }
public void CompletingReleasingSubsequentItems() { var queue = new Queue(); var project1 = new ProjectStub(); var project2 = new ProjectStub(); var context1 = new IntegrationContext(project1); var context2 = new IntegrationContext(project2); queue.AskToIntegrate(context1); queue.AskToIntegrate(context2); context1.Complete(); var active = queue.GetActiveRequests(); Assert.AreEqual(1, active.Count()); Assert.AreEqual(0, queue.GetPendingRequests().Count()); Assert.AreSame(context2, active.First()); }
/// <summary> /// Asks if an item can integrate. /// </summary> /// <param name="context">The context to use.</param> public override void AskToIntegrate(IntegrationContext context) { var locked = false; try { logger.Debug("Adding integration request for '{0}' to '{1}'", context.Item.Name, this.Name); locked = this.interleave.TryEnterWriteLock(TimeSpan.FromSeconds(1)); if (locked) { if ((this.activeRequests.Count < this.AllowedActive.GetValueOrDefault(1)) && this.AskHost()) { logger.Info("Activating '{0}' in '{1}'", context.Item.Name, this.Name); this.activeRequests.Add(context); context.Completed += OnIntegrationCompleted; } else { logger.Info("Adding '{0}' to pending in '{1}'", context.Item.Name, this.Name); this.pendingRequests.Add(context); context.Lock(); } } else { var message = "Unable to add new request to '" + this.Name + "' - unable to acquire lock"; logger.Error(message); // TODO: Replace with custom exception throw new Exception(message); } } finally { if (locked) { this.interleave.ExitWriteLock(); } } }
public static string EnsureDataTableQualify(DataTable dt, string schemapath, Hashtable param) { if (param == null) { param = new Hashtable(); } try { IntegrationContext context = new IntegrationContext(param); context.Schema = ValidationUtils.GetDataSchemaFromFile(schemapath); if (context.Schema == null) { return(string.Format("无法解析出[{0}]的schema", schemapath)); } DataTableStorage.GetDataFromSourceDataTable(dt, context); return(context.Message); } catch (Exception ex) { return(ex.Message); } }
public static ExtendedScenarioRunner <TContext> Create(IFeatureFixtureRunner runner, IntegrationContext context) { return(new ExtendedScenarioRunner <TContext>(runner, context)); }
public MockBddRunner(IntegrationContext ctx, IScenarioRunner scenarioRunner) { _ctx = ctx; _scenarioRunner = scenarioRunner; }
/// <summary> /// Asks if an item can integrate. /// </summary> /// <param name="context">The context to use.</param> public override void AskToIntegrate(IntegrationContext context) { throw new NotImplementedException(); }
public ExceptionProcessor(IntegrationContext integrationContext) { _exceptionToStatusMapper = integrationContext.ExceptionToStatusMapper; _exceptionFormatter = integrationContext.Configuration.ExceptionHandlingConfiguration().ExceptionDetailsFormatter; }
public void HandlesQueueOfQueues() { var integrations = new List<string>(); var contexts = new List<IntegrationContext>(); var projects = new Project[6]; for (var loop = 0; loop < projects.Length; loop++) { var project = new Project("Project" + loop); projects[loop] = project; } var queue1 = new Queue("Queue1", projects[0], projects[1]); var queue2 = new Queue("Queue2", projects[2], projects[3]); var queue3 = new Queue("Queue3", projects[4], projects[5]); var queue4 = new Queue("Queue4", queue1, queue2, queue3) { AllowedActive = 2 }; // Trying to simulate async code here - need to fire the completion events in the // order they are released var completed = new List<IntegrationContext>(); foreach (var project in projects) { var context = new IntegrationContext(project); contexts.Add(context); project.Host.AskToIntegrate(context); if (context.IsLocked) { context.Released += (o, e) => { var subContext = o as IntegrationContext; completed.Add(subContext); integrations.Add(subContext.Item.Name); }; } else { completed.Add(context); integrations.Add(project.Name); } } // completed will be modified at the same time we are iterating through it so can't // use foreach here for (var loop = 0; loop < completed.Count; loop++) { completed[loop].Complete(); } // These should both be empty at the end of the process Assert.AreEqual(0, queue4.GetActiveRequests().Count()); Assert.AreEqual(0, queue4.GetPendingRequests().Count()); // Check that there is the correct order var expected = new[] { "Project0", "Project2", "Project4", "Project1", "Project3", "Project5" }; CollectionAssert.AreEqual(expected, integrations); }
public TRunner Enrich(IFeatureFixtureRunner _, IntegrationContext ctx) { return(_runnerFactory(_contextualRunner, ctx)); }
public override void AskToIntegrate(IntegrationContext context) { }
public ExtendedScenarioRunner(IFeatureFixtureRunner runner, IntegrationContext context) { _runner = runner; _context = context; }
/// <summary> /// Asks the host if an integration can start. /// </summary> /// <returns> /// <c>true</c> if the integration can start; <c>false</c> otherwise. /// </returns> private bool AskHost() { var integrate = this.Host == null; if (!integrate && (this.currentContext == null)) { this.currentContext = new IntegrationContext(this); logger.Debug("Asking host if '{0}' can integrate", this.Name); this.Host.AskToIntegrate(this.currentContext); if (this.currentContext.IsLocked) { this.currentContext.Released += OnContextReleased; } else { integrate = !this.currentContext.WasCancelled; if (!integrate) { this.currentContext = null; } } } return integrate; }
public void AskToIntegrateAsksHostToContinue() { var context = new IntegrationContext(null); var wasCalled = false; var hostMock = new Mock<ServerItem>(MockBehavior.Strict); hostMock.Setup(h => h.AskToIntegrate(context)).Callback(() => wasCalled = true); var project = new Project { Host = hostMock.Object }; project.AskToIntegrate(context); Assert.IsTrue(context.Wait(TimeSpan.FromMilliseconds(1))); Assert.IsTrue(wasCalled); }