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 Alt_Ctor_Should_Add_Calling_Assembly_When_GetCallingAssemblyOnInit_Is_True() { // Arrange var assembly = Assembly.GetExecutingAssembly(); ScriptService.Setup(x => x.AddReferences(assembly)).Verifiable(); // Act var processor = new AltQueryProcessor(new AltQueryOptions(), ScriptService.Object); // Assert processor.GetAltQueryOptions().Assemblies.Should().HaveCount(1); processor.GetAltQueryOptions().Assemblies.First().Should().BeSameAs(Assembly.GetExecutingAssembly()); ScriptService.Verify(x => x.AddReferences(assembly), Times.Once); }
public void Configure_Should_Warm_ScriptService_When_ColdStartOnInit_Is_False() { // Arrange ScriptService.Setup(x => x.EvaluateAsync(string.Empty, null, null, default(CancellationToken))).Verifiable(); // Act var processor = new AltQueryProcessor(new AltQueryOptions() { ColdStartOnInit = true }, ScriptService.Object); processor.Configure(new AltQueryOptions()); // Assert ScriptService.Verify(x => x.EvaluateAsync(string.Empty, null, null, default(CancellationToken)), Times.Once); }
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 Alt_Ctor_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 = new AltQueryProcessor(modifiedOptions, ScriptService.Object); // 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); }