private IOption GetOption(RunEnvironment runEnvironment, string?databaseName) { string tempFile = $"PathFinder.Server.Test.{runEnvironment}.{(databaseName ?? "default")}"; string packageFile = FileTools.WriteResourceToTempFile(tempFile, nameof(TestWebsiteHost), typeof(TestWebsiteHost), GetResourceId()); string[] args = new string?[] { $"ConfigFile={packageFile}", !databaseName.IsEmpty() ? $"Store:DatabaseName={databaseName}" : null, } .Where(x => x != null) .ToArray() !; return(new OptionBuilder() .SetArgs(args) .Build()); string GetResourceId() => runEnvironment switch { RunEnvironment.Local => "PathFinder.Server.Test.Application.Local-Config.json", RunEnvironment.Dev => "PathFinder.Server.Test.Application.Dev-Config.json", _ => throw new InvalidOperationException($"{runEnvironment} is not supported"), }; }
public void NewClearsEverything() { var runEnvironment = new RunEnvironment { ContinueLineNumber = 1 }; runEnvironment.ProgramStack.Push(new StackEntry()); runEnvironment.DefinedFunctions.Add("X", new UserDefinedFunction()); var mockProgramRepository = new Mock <IProgramRepository>(); var mockVariableRepository = new Mock <IVariableRepository>(); var mockDataStatementReader = new Mock <IDataStatementReader>(); var sut = new New( runEnvironment, mockProgramRepository.Object, mockVariableRepository.Object, mockDataStatementReader.Object); sut.Execute(); mockVariableRepository.Verify(mvr => mvr.Clear(), Times.Once); mockProgramRepository.Verify(mpr => mpr.Clear(), Times.Once); mockDataStatementReader.Verify(mdsr => mdsr.RestoreToLineNumber(null), Times.Once); Assert.AreEqual(0, runEnvironment.ProgramStack.Count); Assert.AreEqual(0, runEnvironment.DefinedFunctions.Count); Assert.IsFalse(runEnvironment.ContinueLineNumber.HasValue); }
public TestWebsiteHost StartApiServer(RunEnvironment runEnvironment, string?databaseName = null) { _logger.LogInformation($"{nameof(StartApiServer)}: runEnvironment={runEnvironment}, databaseName={databaseName}"); IOption option = GetOption(runEnvironment, databaseName); var host = new HostBuilder() .ConfigureWebHostDefaults(webBuilder => { webBuilder .UseTestServer() .UseStartup <Startup>(); }) .ConfigureLogging(builder => builder.AddDebug()) .ConfigureServices((hostContext, services) => { services .AddSingleton(option) .AddSingleton <ICosmosPathFinderOption>(option.Store); }); _host = host.Start(); _client = _host.GetTestServer().CreateClient(); InitializeDatabase(_host, option).Wait(); return(this); }
public TestHost(ILoggerFactory loggerFactory, RunEnvironment runEnvironment, string?databaseName = null) : base(loggerFactory.CreateLogger <TestHostState>()) { _loggerFactory = loggerFactory; _runEnvironment = runEnvironment; _databaseName = databaseName; }
public void ReturnUsesReturnAddressAndForNextLoops() { var runEnvironment = new RunEnvironment(); var sut = new Return(runEnvironment); var line10 = new ProgramLine(10, new List <IToken> { new Token("1000") }); var line1000 = new ProgramLine(1000, new List <IToken> { }); line10.NextToken(); runEnvironment.CurrentLine = line1000; runEnvironment.ProgramStack.Push(new StackEntry { Line = line10, LineToken = line10.CurrentToken }); runEnvironment.ProgramStack.Push(new StackEntry { Line = line10, LineToken = line10.CurrentToken }); runEnvironment.ProgramStack.Push(new StackEntry { VariableName = "A", Line = line10, LineToken = line10.CurrentToken }); runEnvironment.ProgramStack.Push(new StackEntry { VariableName = "B", Line = line10, LineToken = line10.CurrentToken }); sut.Execute(); Assert.AreEqual(1, runEnvironment.ProgramStack.Count); Assert.AreEqual(line10, runEnvironment.CurrentLine); }
public void ContThrowsExceptionIfNoContinueSet() { var runEnvironment = new RunEnvironment(); var sut = new Cont(runEnvironment, Mock.Of <IProgramRepository>()); Test.Throws <ClassicBasic.Interpreter.Exceptions.CantContinueException>(sut.Execute); }
public bool CreateCifPo(List <QuoteDetail> listOfQuoteDetail, string testEnvironment, bool removeInternalVendorNumber = false) { B2BHomePage.SelectEnvironment(RunEnvironment.ToString()); var orderId = OrderIdBase + DateTime.Today.ToString("yyMMdd") + DateTime.Now.ToString("HHmmss"); string poXml; poXml = PoXmlGenerator.GeneratePoCblForAsn(PoXmlFormat, orderId, IdentityName, listOfQuoteDetail, removeInternalVendorNumber); var parentWindow = webDriver.CurrentWindowHandle; B2BHomePage.ClickQaTools3(); if (!poOperations.SubmitXmlForPoCreation(poXml, RunEnvironment.ToString(), TargetUrl, testEnvironment, out poNumber)) { return(false); } if (!webDriver.CurrentWindowHandle.Equals(parentWindow)) { webDriver.Close(); } webDriver.SwitchTo().Window(parentWindow); return(true); }
public TestBed(RunEnvironment runEnvironment, string apiServiceBaseUrl, IDictionary <string, string> envVars, string[] args, ILoggerFactory loggerFactory) { ApiServiceBaseUrl = apiServiceBaseUrl; RunEnvironment = runEnvironment; _envVars = new ReadOnlyDictionary <string, string>(envVars); _args = args; _logger = loggerFactory.CreateLogger(GetType()); }
private void SetupSut() { _runEnvironment = new RunEnvironment(); _variableRepository = new VariableRepository(); _mockDataStatementReader = new Mock <IDataStatementReader>(); _mockExpressionEvaluator = new Mock <IExpressionEvaluator>(); _mockReadInputParser = new Mock <IReadInputParser>(); _mockDataStatementReader.Setup(mdsr => mdsr.ReadInputParser).Returns(_mockReadInputParser.Object); _sut = new Read(_runEnvironment, _mockExpressionEvaluator.Object, _mockDataStatementReader.Object); }
public static string ToResourceId(this RunEnvironment subject) { return(subject switch { RunEnvironment.Unknown => "unknown", RunEnvironment.Local => "local", RunEnvironment.Dev => "dev", RunEnvironment.PreProd => "preProd", RunEnvironment.Prod => "prod", _ => throw new InvalidOperationException(), } +"-congfig.json"); }
public void DataSkipsToEndOfLine() { var runEnvironment = new RunEnvironment { CurrentLine = new ProgramLine(10, new List <IToken> { new Token("1,abc def, ", TokenClass.Data) }) }; var sut = new Data(runEnvironment); sut.Execute(); Assert.IsTrue(runEnvironment.CurrentLine.EndOfLine); }
public void RemarkEatsNextToken() { var runEnvironment = new RunEnvironment(); var programLine = new ProgramLine(10, new List <IToken> { new Token("Hello Mum", TokenClass.Remark) }); runEnvironment.CurrentLine = programLine; var sut = new Remark(runEnvironment); sut.Execute(); Assert.IsTrue(runEnvironment.CurrentLine.EndOfLine); }
public static string ToResourceId(this RunEnvironment subject) { return(subject switch { RunEnvironment.Unknown => "unknown", RunEnvironment.Local => "local", RunEnvironment.Dev => "dev", RunEnvironment.PreProd => "preProd", RunEnvironment.Prod => "prod", _ => throw new ArgumentException($"Unknown RunEnvironment=(int){(int)subject}"), } +"-config.json"); }
public void DataSkipsThrowsExceptionInImmediateMode() { var runEnvironment = new RunEnvironment { CurrentLine = new ProgramLine( null, new List <IToken> { new Token("1"), new Token(":", TokenClass.Seperator, TokenType.Colon) }) }; var sut = new Data(runEnvironment); Test.Throws <IllegalDirectException>(sut.Execute); }
public void DataSkipsThrowsSyntaxExceptionIfNotFollowedByClassData() { var runEnvironment = new RunEnvironment { CurrentLine = new ProgramLine( 10, new List <IToken> { new Token("1"), new Token(":", TokenClass.Seperator, TokenType.Colon) }) }; var sut = new Data(runEnvironment); Test.Throws <SyntaxErrorException>(sut.Execute); }
public void DataSkipsToNextStatement() { var runEnvironment = new RunEnvironment { CurrentLine = new ProgramLine( 10, new List <IToken> { new Token("1", TokenClass.Data), new Token(":", TokenClass.Seperator, TokenType.Colon) }) }; var sut = new Data(runEnvironment); sut.Execute(); Assert.AreEqual(TokenType.Colon, runEnvironment.CurrentLine.NextToken().Seperator); }
public void TestDim() { _runEnvironment = new RunEnvironment { CurrentLine = new ProgramLine(0, new List <IToken> { }) }; _mockExpressionEvaluator = new Mock <IExpressionEvaluator>(); _mockVariableRepository = new Mock <IVariableRepository>(); _mockExpressionEvaluator.Setup(mee => mee.GetIndexes()).Returns(new short[] { 3, 2 }); _mockExpressionEvaluator.Setup(mee => mee.GetVariableName()).Returns("A"); _sut = new Dim(_runEnvironment, _mockExpressionEvaluator.Object, _mockVariableRepository.Object); _sut.Execute(); _mockVariableRepository.Verify(mvr => mvr.DimensionArray("A", new short[] { 3, 2 }), Times.Once); }
public void TestDimWithEmptyIndexesSkipsCreate() { _runEnvironment = new RunEnvironment { CurrentLine = new ProgramLine(0, new List <IToken> { }) }; _mockExpressionEvaluator = new Mock <IExpressionEvaluator>(); _mockVariableRepository = new Mock <IVariableRepository>(); _mockExpressionEvaluator.Setup(mee => mee.GetIndexes()).Returns(new short[] { }); _mockExpressionEvaluator.Setup(mee => mee.GetVariableName()).Returns("A"); _sut = new Dim(_runEnvironment, _mockExpressionEvaluator.Object, _mockVariableRepository.Object); _sut.Execute(); _mockVariableRepository.Verify(mvr => mvr.DimensionArray(It.IsAny <string>(), It.IsAny <short[]>()), Times.Never); }
public void InterpreterHandlesSyntaxErrorForDataRead() { SetupSut(); var line20 = new ProgramLine(20, new List <IToken> { new Token("A") }); var runLine = new ProgramLine(null, new List <IToken> { new Token("A") }); IRunEnvironment runEnvironment = new RunEnvironment(); _sut = new Interpreter( new TeletypeWithPosition(_mockTeletype), _mockTokeniser.Object, runEnvironment, _mockProgramRepository.Object, _mockExecutor.Object); _mockTeletype.Input.Enqueue("20 PRINT"); _mockTeletype.Input.Enqueue("RUN"); _mockTeletype.Input.Enqueue("SYSTEM"); _mockTokeniser.Setup(mt => mt.Tokenise("20 PRINT")).Returns(line20); _mockTokeniser.Setup(mt => mt.Tokenise("RUN")).Returns(runLine); var syntaxException = new ClassicBasic.Interpreter.Exceptions.SyntaxErrorException(); _mockExecutor.SetupSequence(me => me.ExecuteLine()) .Throws(syntaxException) .Returns(true); runEnvironment.CurrentLine = line20; runEnvironment.DataErrorLine = 40; _sut.Execute(); // Input of line 20 CheckForPrompt(); // Run CheckForPrompt(); CheckForError("?" + syntaxException.ErrorMessage + " ERROR IN 40"); // Prompt after STOP CheckForPrompt(); // Nothing left Assert.AreEqual(0, _mockTeletype.Output.Count); }
public static void LoadLIB() { RunEnvironment r = RunEnvironment.Instance; bool res = r.LoadFunction("print", OutPut, 0, true); res = r.LoadFunction("typeof", GetTypeOf, 1); res = r.LoadFunction("loadstring", LoadString, 1); res = r.LoadFunction("error", Error, 1); res = r.LoadFunction("setmetatable", SetMetatable, 2); res = r.LoadFunction("getmetatable", GetMetatable, 1); }
private Option FinalizeOption(Option option, RunEnvironment runEnvironment) { option.Verify(); option = option with { RunEnvironment = runEnvironment, Store = new DataLakeNamespaceOption { Namespaces = option.Store.Namespaces.Values.ToDictionary(x => x.Namespace, x => x, StringComparer.OrdinalIgnoreCase), } }; return(option); }
public void UploadCrtFile( RunEnvironment environment, string crossReferenceType, string filePath, string description) { B2BHomePage.SelectEnvironment(environment.ToString()); B2BHomePage.ClickCrossReferenceListLink(); B2BCrossReferenceListPage.ClickNewCrossReference(); ////selects CRT Type B2BCrossReferenceMaintenencePage.SelectCrossReferenceType(crossReferenceType); ////Sets the path for File Upload B2BCrossReferenceMaintenencePage.SetUploadFilePath(filePath); B2BCrossReferenceMaintenencePage.SetDescription(description); B2BCrossReferenceMaintenencePage.ClickSave(); }
/// <summary> /// Associate CRT file and return CRID /// </summary> /// <param name="environment"></param> /// <param name="crossReferenceType"></param> /// <param name="filePath"></param> /// <param name="description"></param> /// <param name="profilename"></param> /// <returns></returns> public string AssociateCrtFileReturnCRID( RunEnvironment environment, string crossReferenceType, string filePath, string description, string profilename) { SelectEnviornment(RunEnvironment.Preview); if (environment.Equals(RunEnvironment.Preview)) { //Upload CRT file UploadCrtFile(crossReferenceType, filePath, description); } string Crid = B2BCrossReferenceMaintenencePage.GetCrId(); AssociateCrtWithProfile(crossReferenceType, Crid, profilename); return(Crid); }
public void PopDeletesReturnAddress() { var runEnvironment = new RunEnvironment(); var sut = new Pop(runEnvironment); var line10 = new ProgramLine(10, new List <IToken> { new Token("1000") }); var line1000 = new ProgramLine(1000, new List <IToken> { }); line10.NextToken(); runEnvironment.CurrentLine = line1000; runEnvironment.ProgramStack.Push(new StackEntry { Line = line10, LineToken = line10.CurrentToken }); sut.Execute(); Assert.AreEqual(0, runEnvironment.ProgramStack.Count); Assert.AreEqual(line1000, runEnvironment.CurrentLine); }
public void ContResetsTheCurrentLineAndToken() { var runEnvironment = new RunEnvironment(); var mockProgramRepository = new Mock <IProgramRepository>(); var continueLine = new ProgramLine(1000, new List <IToken> { }); runEnvironment.CurrentLine = new ProgramLine(null, new List <IToken> { }); runEnvironment.ContinueLineNumber = 1000; runEnvironment.ContinueToken = 5; mockProgramRepository.Setup(mpr => mpr.GetLine(1000)).Returns(continueLine); var sut = new Cont(runEnvironment, mockProgramRepository.Object); sut.Execute(); Assert.AreEqual(continueLine, runEnvironment.CurrentLine); Assert.AreEqual(1000, runEnvironment.CurrentLine.LineNumber); Assert.AreEqual(5, runEnvironment.CurrentLine.CurrentToken); }
public bool CreateDomsPo(List <QuoteDetail> listOfQuoteDetail, string testEnvironment) { B2BHomePage.SelectEnvironment(RunEnvironment.ToString()); var orderId = OrderIdBase + DateTime.Today.ToString("yyMMdd") + DateTime.Now.ToString("HHmmss"); crtId = listOfQuoteDetail.FirstOrDefault().CrtId; price = listOfQuoteDetail.FirstOrDefault().Price; string poXml; if (Workflow == Workflow.Eudc) { poXml = PoXmlGenerator.GeneratePoCxmlCblForEudc( PoXmlFormat, IdentityName, DeploymentMode, orderId, price, listOfQuoteDetail.FirstOrDefault().SupplierPartId, crtId); } else { poXml = PoXmlGenerator.GeneratePoCblForAsn(PoXmlFormat, orderId, IdentityName, listOfQuoteDetail); } var parentWindow = webDriver.CurrentWindowHandle; B2BHomePage.ClickQaTools3(); if (!poOperations.SubmitXmlForPoCreation(poXml, RunEnvironment.ToString(), TargetUrl, testEnvironment, out poNumber)) { return(false); } if (!webDriver.CurrentWindowHandle.Equals(parentWindow)) { webDriver.Close(); } webDriver.SwitchTo().Window(parentWindow); return(true); }
private Stream GetResourceStream(RunEnvironment runEnvironment) { const string baseResource = "ArtifactStore.Configs."; const string configSufix = "-config.json"; string resourceId = baseResource + runEnvironment switch { RunEnvironment.Unknown => "unknown", RunEnvironment.Local => "local", RunEnvironment.Dev => "dev", RunEnvironment.PreProd => "preProd", RunEnvironment.Prod => "prod", _ => throw new ArgumentException($"Unknown RunEnvironment=(int){(int)runEnvironment}"), } +configSufix; return(Assembly.GetAssembly(typeof(OptionBuilder)) ! .GetManifestResourceStream(resourceId) .VerifyNotNull($"Resource {resourceId} not found in assembly")); }
public void ReturnThrowsWhenNoReturnAddress() { var runEnvironment = new RunEnvironment(); var sut = new Return(runEnvironment); var line10 = new ProgramLine(10, new List <IToken> { new Token("1000") }); var line1000 = new ProgramLine(1000, new List <IToken> { }); line10.NextToken(); runEnvironment.CurrentLine = line1000; runEnvironment.ProgramStack.Push(new StackEntry { VariableName = "A", Line = line10, LineToken = line10.CurrentToken }); runEnvironment.ProgramStack.Push(new StackEntry { VariableName = "B", Line = line10, LineToken = line10.CurrentToken }); Test.Throws <ReturnWithoutGosubException>(sut.Execute); }
public void TestDimMultipleArrays() { _runEnvironment = new RunEnvironment { CurrentLine = new ProgramLine(0, new List <IToken> { new Token(",", TokenClass.Seperator, TokenType.Comma) }) }; _mockExpressionEvaluator = new Mock <IExpressionEvaluator>(); _mockVariableRepository = new Mock <IVariableRepository>(); _mockExpressionEvaluator.SetupSequence(mee => mee.GetIndexes()) .Returns(new short[] { 3, 2 }) .Returns(new short[] { 11, 12 }); _mockExpressionEvaluator.SetupSequence(mee => mee.GetVariableName()) .Returns("A") .Returns("B$"); _sut = new Dim(_runEnvironment, _mockExpressionEvaluator.Object, _mockVariableRepository.Object); _sut.Execute(); _mockVariableRepository.Verify(mvr => mvr.DimensionArray("A", new short[] { 3, 2 }), Times.Once); _mockVariableRepository.Verify(mvr => mvr.DimensionArray("B$", new short[] { 11, 12 }), Times.Once); }
public void DeleteTestsFromImmediateMode(int?start, bool hasComma, int?end, bool throwsException) { var mockProgramRepository = new Mock <IProgramRepository>(); var tokens = new List <IToken>(); if (start.HasValue) { tokens.Add(new Token(start.Value.ToString())); } if (hasComma) { tokens.Add(new Token(",", TokenClass.Seperator, TokenType.Comma)); } if (end.HasValue) { tokens.Add(new Token(end.Value.ToString())); } var runEnvironment = new RunEnvironment { CurrentLine = new ProgramLine(null, tokens) }; var sut = new Del(runEnvironment, mockProgramRepository.Object); var exceptionThrown = false; try { sut.Execute(); mockProgramRepository.Verify(mpr => mpr.DeleteProgramLines(start.Value, end.Value)); } catch (ClassicBasic.Interpreter.Exceptions.SyntaxErrorException) { exceptionThrown = true; } Assert.AreEqual(throwsException, exceptionThrown); }