public void EmptyConfigurationShouldCreateDisabledRootContextOnly() { var options = new KwyjiboOptions(); var tree = new ContextTree(options); tree.Enabled.Should().BeTrue(); tree.GetContext("wibble").Should().BeNull(); }
public void EmptyConfigurationShouldEnableAllContexts() { var configuration = new ConfigurationBuilder() .AddJsonFile("Configuration/empty.json") .Build(); var options = new KwyjiboOptions(); options.Configure(configuration); var tree = new ContextTree(options); tree.Enabled.Should().BeTrue(); }
/// <inheritdoc /> public async Task <bool?> TryEvaluateModuleAsync([NotNull] IEvaluationScheduler scheduler, [NotNull] ModuleDefinition module, QualifierId qualifierId) { // Abstraction between SDK/Workspace/Core/Resolvers is broken here... var moduleDefinition = (ModuleDefinition)module; if (!string.Equals(moduleDefinition.Descriptor.ResolverName, Name, StringComparison.Ordinal)) { return(null); } var downloadData = m_workspaceResolver.Downloads[module.Descriptor.Name]; // Make sure evaluating is guarded by the semaphore, so it only happens one at a time // There is no need to make sure we don't evaluate duplicate work here since module evaluation // happens once per qualifier. await m_evaluationSemaphore.WaitAsync(); try { // Modules of the download resolver are always instantiated with the empty qualifier var moduleRegistry = (ModuleRegistry)m_frontEndHost.ModuleRegistry; var moduleLiteral = moduleRegistry .GetUninstantiatedModuleInfoByPath(downloadData.ModuleSpecFile) .FileModuleLiteral .InstantiateFileModuleLiteral(moduleRegistry, QualifierValue.CreateEmpty(m_context.QualifierTable)); // Evaluate all values of the module using (var contextTree = new ContextTree( m_frontEndHost, m_context, m_logger, m_evaluationStatistics, new QualifierValueCache(), isBeingDebugged: false, decorator: null, moduleLiteral, new EvaluatorConfiguration(trackMethodInvocations: false, cycleDetectorStartupDelay: TimeSpanUtilities.MillisecondsToTimeSpan(10)), scheduler, FileType.Project)) { var moduleTracker = VisitedModuleTracker.Create(isDebug: false); var success = await moduleLiteral.EvaluateAllAsync(contextTree.RootContext, moduleTracker, ModuleEvaluationMode.None); return(success); } } finally { m_evaluationSemaphore.Release(); } }
private void SelectionServiceOnContextAction(object sender, ContextActionEventArgs e) { if (!Renderer.RenderingEngine.SelectionService.ActionActive) { ContextTree contextTree = new ContextTree(Renderer.RenderingEngine, e) { StartPosition = FormStartPosition.Manual, Location = Cursor.Position }; contextTree.Finished -= ContextTreeOnFinished; contextTree.Finished += ContextTreeOnFinished; contextTree.Show(); } }
public void UnconfiguredContextShouldBeNull() { var options = new KwyjiboOptions(); options.ForContext <ContextFixture>() .Enable() .When <IIdentity>(id => id.Name.Contains("kwyjibo")) .Throw <InvalidOperationException>(); var tree = new ContextTree(options); var context = tree.GetContext <KwyjiboFixture>(); context.Should().BeNull(); }
private void ContextTreeOnFinished(object sender, EventArgs eventArgs) { ContextTree contextTree = sender as ContextTree; bool canceled = contextTree?.SelectedSwitch == null; if (!canceled) { var p = contextTree.ContextActionEventArgs.Location; var sw = Renderer.RenderingEngine.AddComponent(contextTree.SelectedSwitch, Renderer.RenderingEngine.TranslatePoint(p)); Renderer.RenderingEngine.SelectionService.FinishContextAction(false, sw); } else { Renderer.RenderingEngine.SelectionService.FinishContextAction(true, null); } }
public void ContextShouldNotHaveUndefinedHandler() { var options = new KwyjiboOptions(); options.ForContext <ContextFixture>() .Enable() .Named("alien") .When <IIdentity>(id => id.Name.Contains("kwyjibo")) .Throw <InvalidOperationException>(); var tree = new ContextTree(options); var context = tree.GetContext <ContextFixture>(); var handler = context.GetHandler("foobar"); handler.Should().BeNull(); }
public void InitialisedConfigurationShouldCreateContext() { var options = new KwyjiboOptions(); options.ForContext <ContextFixture>() .Disable() .When <IIdentity>(id => id.Name.Contains("kwyjibo")) .Throw <InvalidOperationException>(); var tree = new ContextTree(options); tree.Enabled.Should().BeTrue(); var context = tree.GetContext <ContextFixture>(); context.Enabled.Should().BeFalse(); context.Name.Should().Be(this.GetType().Name); context.FullName.Should().Be(this.GetType().FullName); }
public void InitialisedConfigurationShouldCreateIntermediateContexts() { var options = new KwyjiboOptions(); options.ForContext <ContextFixture>() .Enable() .When <IIdentity>(id => id.Name.Contains("kwyjibo")) .Throw <InvalidOperationException>(); var tree = new ContextTree(options); var context = tree.GetContext <ContextFixture>(); context.FullName.Should().Be(this.GetType().FullName); context.Parent.FullName.Should().Be(this.GetType().Namespace); context.Parent.Status.Should().Be(Status.Inherit); context.Parent.Enabled.Should().BeTrue(); context.Parent.Parent.Parent.Parent.Should().Be(tree); context.Parent.Parent.Parent.Parent.Parent.Should().BeNull(); }
public void SpecifiedConfigurationShouldBeReadCorrectly() { var configuration = new ConfigurationBuilder() .AddJsonFile("Configuration/sample.json") .Build(); var options = new KwyjiboOptions(); options.Configure(configuration); options.ForContext <KwyjiboConfigurationExtensionsFixture>() .When <IIdentity>(id => id.Name.Contains("kwyjibo")) .Throw <SecurityException>(); var tree = new ContextTree(options); tree.Enabled.Should().BeFalse(); var context = tree.GetContext <KwyjiboConfigurationExtensionsFixture>(); context.Enabled.Should().BeFalse(); context.Parent.Enabled.Should().BeFalse(); context.Parent.Parent.Enabled.Should().BeTrue(); context.Parent.Parent.Parent.Enabled.Should().BeTrue(); }
public void ContextShouldHaveHandler() { var options = new KwyjiboOptions(); options.ForContext <ContextFixture>() .Enable() .Named("foobar") .When <IIdentity>(id => id.Name.Contains("kwyjibo")) .Throw <InvalidOperationException>(); var tree = new ContextTree(options); var context = tree.GetContext <ContextFixture>(); var handler = context.GetHandler("foobar"); handler.Should().NotBeNull(); handler.InputType.Should().Be(typeof(IIdentity)); var mockIdentity = new Mock <IIdentity>(); mockIdentity.SetupGet(id => id.Name).Returns("kwyjibo"); handler.Predicate(mockIdentity.Object).Should().BeTrue(); handler.ExceptionBuilder().Should().BeOfType <InvalidOperationException>(); }
private EvaluationResult CreateResult(bool success, ModuleLiteral module = null, ContextTree tree = null) { if (IsBeingDebugged) { var contexts = tree != null && module != null ? new[] { new ModuleAndContext(module, tree) } : CollectionUtilities.EmptyArray <ModuleAndContext>(); return(new EvaluationResult(success, contexts)); } return(new EvaluationResult(success, CollectionUtilities.EmptyArray <ModuleAndContext>())); }
public KwyjiboBuilder(KwyjiboOptions options) { _contextTree = new ContextTree(options); }