public void GetAltQueryOption_Should_Clone_AltQueryOptions_When_Called() { // Arrange var options = new AltQueryOptions() { GetCallingAssemblyOnInit = false, ColdStartOnInit = true, Assemblies = new List <Assembly>() { Assembly.GetEntryAssembly() }, }; // Act var sut = new AltQueryProcessor(options); var clonedOptions = sut.GetAltQueryOptions(); // Grabbing the private property var prop = sut.GetType().GetProperty(nameof(AltQueryOptions), BindingFlags.NonPublic | BindingFlags.Instance); MethodInfo getter = prop.GetGetMethod(nonPublic: true); var privateOptions = getter.Invoke(sut, null) as AltQueryOptions; // Assert clonedOptions.Should().BeEquivalentTo(options); clonedOptions.Should().NotBeSameAs(options); clonedOptions.Should().BeEquivalentTo(privateOptions); clonedOptions.Should().NotBeSameAs(privateOptions); }
public void AltQueryOptions_Property_Count_Test() { //Arrange // Act var props = new AltQueryOptions().GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); // Assert props.Should().HaveCount(5); }
public AltQueryProcessor(IAltQueryScriptService scriptService = null, IAltQueryParser parserService = null, IAltQueryComposer composerService = null) { AltQueryOptions = new AltQueryOptions(); _scriptService = scriptService ?? new AltQueryScriptService(); _parserService = parserService ?? new AltQueryParser(AltQueryOptions); _composerService = composerService ?? new AltQueryComposer(AltQueryOptions); AddAssembliesViaOptions(AltQueryOptions.Assemblies); WarmScriptEngineViaOptions(); }
public void Configure(AltQueryOptions options) { if (options == null) { throw new ArgumentNullException(nameof(AltQueryOptions)); } AltQueryOptions.GetCallingAssemblyOnInit = options.GetCallingAssemblyOnInit; AltQueryOptions.ColdStartOnInit = options.ColdStartOnInit; AltQueryOptions.ComparisonOperatorOptions = options.ComparisonOperatorOptions; AltQueryOptions.LogicalOperatorOptions = options.LogicalOperatorOptions; AltQueryOptions.Assemblies = options.Assemblies; AddAssembliesViaOptions(AltQueryOptions.Assemblies); WarmScriptEngineViaOptions(); }
public void Alt_Ctor_Should_Not_Warm_ScriptService_When_ColdStartOnInit_Is_True() { // Arrange var modifiedOptions = new AltQueryOptions() { ColdStartOnInit = true }; ScriptService.Setup(x => x.EvaluateAsync(string.Empty, null, null, default(CancellationToken))).Verifiable(); // Act new AltQueryProcessor(modifiedOptions, ScriptService.Object); // Assert ScriptService.Verify(x => x.EvaluateAsync(string.Empty, null, null, default(CancellationToken)), Times.Never); }
public void Alt_Ctor_Should_Not_Add_Assembly_When_GetCallingAssemblyOnInit_Is_False() { // Arrange var modifiedOptions = new AltQueryOptions() { GetCallingAssemblyOnInit = false }; ScriptService.Setup(x => x.AddReferences(It.IsAny <Assembly>())).Verifiable(); // Act var processor = new AltQueryProcessor(modifiedOptions, ScriptService.Object); // Assert processor.GetAltQueryOptions().Assemblies.Should().HaveCount(0); ScriptService.Verify(x => x.AddReferences(It.IsAny <Assembly>()), Times.Never); }
public void Configure_Should_Set_Modify_DefaultOptions_When_Called() { // Arrange var modifiedOptions = new AltQueryOptions { ColdStartOnInit = true, GetCallingAssemblyOnInit = false, ComparisonOperatorOptions = { Equal = "mock eq" }, LogicalOperatorOptions = { And = "mock and" }, Assemblies = new List <Assembly>() { Assembly.GetEntryAssembly() } }; // Act var processor = CreateSut(); processor.Configure(modifiedOptions); // Assert var options = processor.GetAltQueryOptions(); options.ColdStartOnInit.Should().Be(true); options.GetCallingAssemblyOnInit.Should().Be(false); options.ComparisonOperatorOptions.Should().BeEquivalentTo(new ComparisonOperatorOptions() { Equal = "mock eq", NotEqual = "ne", GreaterThan = "gt", GreaterThanOrEqual = "ge", LessThan = "lt", LessThanOrEqual = "le" }); options.LogicalOperatorOptions.Should().BeEquivalentTo(new LogicalOperatorOptions() { And = "mock and", Or = "or", Not = "not" }); options.Assemblies.Should().Contain(Assembly.GetEntryAssembly()); }
public void AddReferences_Should_Call_AddReferences_On_ScriptService_When_Called() { // Arrange var options = new AltQueryOptions() { GetCallingAssemblyOnInit = false }; var assemblies = new List <Assembly>() { Assembly.GetEntryAssembly() }.ToArray(); ScriptService.Setup(x => x.AddReferences(assemblies)).Verifiable(); // Act var sut = new AltQueryProcessor(options, ScriptService.Object); sut.AddReferences(assemblies); // Assert ScriptService.Verify(x => x.AddReferences(assemblies), Times.Once); }
public void Should_Return_Correct_FilterOption_When_Parsing_Custom_EqualTo_Operator() { // arrange var moddedOptions = new AltQueryOptions() { ComparisonOperatorOptions = new ComparisonOperatorOptions() { Equal = "MOCK-EQUAL" } }; var query = "property MOCK-EQUAL 5"; var expected = new SearchModelBuilder() .WithStatment("property", "MOCK-EQUAL", "5") .Build(); // Act var result = CreateSut(moddedOptions).ToSearchModel(query); // Assert result.Should().BeEquivalentTo(expected); }
public void Should_Return_Correct_LinqQuery_When_Composing_Custom_EqualTo_Operator() { // arrange var moddedOptions = new AltQueryOptions() { ComparisonOperatorOptions = new ComparisonOperatorOptions() { Equal = "MOCK-EQUAL" } }; var searchModel = new SearchModelBuilder() .WithStatment("property", "MOCK-EQUAL", "5") .Build(); var expected = $"{SearchModel.SearchPrefix}.property == 5"; // Act var result = CreateSut(moddedOptions).ToQuery(searchModel); // Assert result.Should().BeEquivalentTo(expected); }
public AltQueryProcessor(AltQueryOptions options, IAltQueryScriptService scriptService = null, IAltQueryParser parserService = null) { if (options == null) { throw new ArgumentNullException(nameof(AltQueryOptions)); } AltQueryOptions = new AltQueryOptions { GetCallingAssemblyOnInit = options.GetCallingAssemblyOnInit, ColdStartOnInit = options.ColdStartOnInit, ComparisonOperatorOptions = options.ComparisonOperatorOptions, LogicalOperatorOptions = options.LogicalOperatorOptions, Assemblies = options.Assemblies }; _scriptService = scriptService ?? new AltQueryScriptService(); _parserService = parserService ?? new AltQueryParser(AltQueryOptions); AddAssembliesViaOptions(AltQueryOptions.Assemblies); WarmScriptEngineViaOptions(); }
public void Should_Return_Correct_FilterOptions_When_Parsing_Custom_And_Operator() { // arrange var moddedOptions = new AltQueryOptions() { LogicalOperatorOptions = new LogicalOperatorOptions() { And = "MOCK-AND" } }; var query = "propertyX le 5 MOCK-AND propertyY gt 1"; var expected = new SearchModelBuilder() .WithStatment("propertyX", "le", "5") .WithStatment("propertyY", "gt", "1", "MOCK-AND") .Build(); // Act var result = CreateSut(moddedOptions).ToSearchModel(query); // Assert result.Should().BeEquivalentTo(expected); }
public void Should_Return_Correct_LinqQuerys_When_Composing_Custom_And_Operator() { // arrange var moddedOptions = new AltQueryOptions() { LogicalOperatorOptions = new LogicalOperatorOptions() { And = "MOCK-AND" } }; var searchModel = new SearchModelBuilder() .WithStatment("propertyX", "le", "5") .WithStatment("propertyY", "gt", "1", "MOCK-AND") .Build(); var expected = $"{SearchModel.SearchPrefix}.propertyX <= 5 && {SearchModel.SearchPrefix}.propertyY > 1"; // Act var result = CreateSut(moddedOptions).ToQuery(searchModel); // Assert result.Should().BeEquivalentTo(expected); }
public AltQueryComposer CreateSut(AltQueryOptions options = null) { return(new AltQueryComposer(options ?? new AltQueryOptions())); }
public AltQueryComposer(AltQueryOptions options) { _comparisonOperators = OperatorHelper.GenerateComparisonOperatorDictionary(options.ComparisonOperatorOptions); _logicalOperators = OperatorHelper.GenerateLogicalOperatorDictionary(options.LogicalOperatorOptions); _notSymbol = OperatorHelper.GetNotSymbol(_logicalOperators); }