Example #1
0
 public void Initialize()
 {
     MainApplicationContext.Initialize();
     TimesCommon.Current.TimesInitialize();
     Amount.Initialize();
     // [DM] not needed
     //amount_t::stream_fullstrings = true; // make reports from UnitTests accurate
 }
Example #2
0
 private void Initialize()
 {
     MainContextAcquirer = new MainApplicationContext().AcquireCurrentThread();
     TimesCommon.Current.TimesInitialize();
     Amount.Initialize();
     // [DM] not needed
     //amount_t::stream_fullstrings = true; // make reports from UnitTests accurate
 }
Example #3
0
        public virtual MainApplicationContext CloneContext(MainApplicationContext mainApplicationContext, MemoryStreamManager memoryStreamManager)
        {
            if (mainApplicationContext == null)
            {
                throw new ArgumentNullException(nameof(mainApplicationContext));
            }

            return(mainApplicationContext.Clone(CreateApplicationServiceProvider(memoryStreamManager)));
        }
Example #4
0
        public virtual MainApplicationContext CreateContext(MemoryStreamManager memoryStreamManager)
        {
            var context = new MainApplicationContext(CreateApplicationServiceProvider(memoryStreamManager));

            context.IsAtty = false;

            ConfigureContext?.Invoke(context);

            return(context);
        }
Example #5
0
        private void Initialize()
        {
            MainContextAcquirer = new MainApplicationContext().AcquireCurrentThread();
            TimesCommon.Current.TimesInitialize();

            // Cause the display precision for dollars to be initialized to 2.
            Amount x1 = new Amount("$1.00");

            Assert.True((bool)x1);

            // [DM] not needed
            //amount_t::stream_fullstrings = true; // make reports from UnitTests accurate
        }
Example #6
0
        private void CloseSession()
        {
            if (GlobalScope != null && MainApplicationContext != null)
            {
                using (MainApplicationContext.AcquireCurrentThread())
                {
                    GlobalScope.QuickClose();
                    GlobalScope.Dispose();
                    GlobalScope = null;

                    Logger.Current.Info(() => LedgerSessionEnded);
                }
            }
        }
Example #7
0
        public void TestCleanup()
        {
            ContextInit contextInit = GetContextInit();

            CustomTestCleanup();

            if (contextInit.HasFlag(ContextInit.SaveCultureInfo))
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo;
            }
            if (contextInit.HasFlag(ContextInit.InitMainApplicationContext))
            {
                MainApplicationContext.Cleanup();
            }
        }
Example #8
0
        /// <summary>
        /// Popupates the main application context with effective settings for a console application
        /// </summary>
        public void ConfigureConsole(MainApplicationContext context)
        {
            context.IsAtty   = IsAtty.Value;
            context.TimeZone = TimeZoneId.Value;

            Console.OutputEncoding = OutputEncoding.Value;
            if (AnsiTerminalEmulation.Value)
            {
                AnsiTextWriter.Attach();
            }

            context.SetVirtualConsoleProvider(() => new VirtualConsoleProvider(Console.In, Console.Out, Console.Error));
            context.DefaultPager = DefaultPager.Value;

            context.SetEnvironmentVariables(SettingsContainer.VarSettings.EnvironmentVariables);
        }
        /// <summary>
        /// Popupates the main application context with effective settings for a console application
        /// </summary>
        public MainApplicationContext CreateConsoleApplicationContext()
        {
            Console.OutputEncoding = OutputEncoding.Value;
            if (AnsiTerminalEmulation.Value)
            {
                AnsiTextWriter.Attach();
            }

            var context = new MainApplicationContext()
            {
                IsAtty       = IsAtty.Value,
                TimeZone     = TimeZoneId.Value,
                DefaultPager = DefaultPager.Value
            };

            context.SetEnvironmentVariables(SettingsContainer.VarSettings.EnvironmentVariables);
            return(context);
        }
Example #10
0
        public void TestInitialize()
        {
            ContextInit contextInit = GetContextInit();

            if (contextInit.HasFlag(ContextInit.InitMainApplicationContext))
            {
                MainContextAcquirer = new MainApplicationContext().AcquireCurrentThread();
            }
            if (contextInit.HasFlag(ContextInit.InitTimesCommon))
            {
                TimesCommon.Current.TimesInitialize();
            }
            if (contextInit.HasFlag(ContextInit.SaveCultureInfo))
            {
                CultureInfo = Thread.CurrentThread.CurrentCulture;
            }

            CustomTestInitialize();
        }
Example #11
0
 private void Initialize()
 {
     MainContextAcquirer = new MainApplicationContext().AcquireCurrentThread();
     TimesCommon.Current.TimesInitialize();
 }
Example #12
0
 public void Cleanup()
 {
     MainApplicationContext.Cleanup();
 }
Example #13
0
        public WorkingUI(MainApplicationContext context)
        {
            cntx = context;

            UI(true, cntx);
        }
Example #14
0
 public Installer(MainApplicationContext context)
 {
     cntx = context;
 }
Example #15
0
        private static void UI(bool show, MainApplicationContext cntx)
        {
            if (show)
            {
                workingUICounter++;
            }
            else
            {
                workingUICounter--;
            }

            if (workingUIShown == false && workingUICounter > 0)
            {
                workingUIShown = true;

                cntx.BeginInvoke(new MethodInvoker(() =>
                {
                    try
                    {
                        cntx.TrayIcon.Visible = false;
                    }
                    catch
                    {
                    }

                    workingUI = new frmWorking();
                    if (parent != null
                        && parent.IsDisposed == false
                        && parent.Visible)
                    {
                        try
                        {
                            parent.BeginInvoke(new MethodInvoker(() =>
                                {
                                    workingUI.ShowDialog(parent);
                                }));
                        }
                        catch
                        {
                            workingUI.Show();
                        }
                    }
                    else
                    {
                        workingUI.Show();
                    }
                    workingUI.Activate();
                }));
            }
            else if (workingUIShown && workingUICounter <= 0)
            {
                workingUIShown = false;
                workingUICounter = 0;

                cntx.BeginInvoke(new MethodInvoker(() =>
                {
                    try
                    {
                        cntx.TrayIcon.Visible = true;
                    }
                    catch
                    {
                    }

                    try
                    {
                        workingUI.Close();
                    }
                    catch
                    {
                    }
                }));
            }
        }
Example #16
0
 public void Initialize()
 {
     MainApplicationContext.Initialize();
     TimesCommon.Current.TimesInitialize();
 }
Example #17
0
        public void Run()
        {
            foreach (var testCase in TestCases)
            {
                Console.WriteLine($"Test case: file {Path.GetFileName(testCase.FileName)}; arguments: {testCase.CommandLine}");

                // Environment variables
                var envs = new Dictionary <string, string>();

                // Tests are configured for 80 symbols in row
                envs["COLUMNS"] = "80";

                try
                {
                    var expectedExitCode = 0;

                    var args = testCase.CommandLine;

                    // Find expected exit code of exists
                    var regexExitCode = Regex.Match(args, "(.*) -> ([0-9]+)");
                    if (regexExitCode.Success)
                    {
                        expectedExitCode = Int32.Parse(regexExitCode.Groups[2].Value);
                        args             = args.Substring(regexExitCode.Groups[1].Index, regexExitCode.Groups[1].Length);
                    }

                    // Check whether -f option is already presented; add it if does not
                    var regexHasFileOption = Regex.Match(args, @"(^|\s)-f\s");
                    if (!regexHasFileOption.Success)
                    {
                        args += $" -f '{FileName}'";
                    }

                    // Check whether "--pager" option is presented to add extra options for paging test
                    if (args.Contains("--pager"))
                    {
                        args += " --force-pager";                 // Pager test requires this option to override IsAtty=false that is default for other tests
                        envs["nledgerPagerForceOutput"] = "true"; // Pager test needs to force writing to output to test text that is ate by the pager process
                    }

                    // Check whether output is redirected to null; remove it if so
                    var ignoreStdErr         = false;
                    var stdErrRedirectToNull = "2>/dev/null";
                    if (args.Contains(stdErrRedirectToNull))
                    {
                        args         = args.Replace(stdErrRedirectToNull, "");
                        ignoreStdErr = true;
                    }

                    // Check whether input pipe is needed
                    string stdInContent = String.Empty;
                    var    regexStdIn   = Regex.Match(args, @"-f (-|/dev/stdin)(\s|$)");
                    if (regexStdIn.Success)
                    {
                        stdInContent = File.ReadAllText(FileName);
                    }

                    // Check whether arguments have escaped dollar sign; remove it if so
                    args = args.Replace(@" \$ ", " $ ");

                    // Set custom environment variables
                    foreach (var name in testCase.SetVariables.Keys)
                    {
                        envs[name] = testCase.SetVariables[name];
                    }

                    using (var inReader = new StringReader(stdInContent))
                    {
                        using (var outWriter = new StringWriter())
                        {
                            using (var errWriter = new StringWriter())
                            {
                                var appServiceProvider = new ApplicationServiceProvider(virtualConsoleProviderFactory: () => new TestConsoleProvider(inReader, outWriter, errWriter));
                                var context            = new MainApplicationContext(appServiceProvider);
                                context.IsAtty   = false;             // Simulating pipe redirection in original tests
                                context.TimeZone = PreferredTimeZone; // Either "Central Standard Time" for Windows or "America/Chicago" for other systems
                                context.SetEnvironmentVariables(envs);
                                var main = new Main(context);

                                var exitCode = main.Execute(args);

                                outWriter.Flush();
                                var output = outWriter.ToString();

                                errWriter.Flush();
                                var err = errWriter.ToString();

                                var normalizedExpectedOutput = NormalizeOutput(testCase.ExpectedOutput);
                                var normalizedOutput         = NormalizeOutput(output);

                                var normalizedExpectedErr = NormalizeOutput(testCase.ExpectedError);
                                var normalizedErr         = ignoreStdErr ? "" : NormalizeOutput(err);

                                Assert.True(normalizedExpectedOutput == normalizedOutput, $"Produced output does not match expected one ({DescribeDifference(normalizedExpectedOutput, normalizedOutput)})");
                                Assert.True(normalizedExpectedErr == normalizedErr, $"Produced error stream does not match expected one ({DescribeDifference(normalizedExpectedErr, normalizedErr)})");

                                Assert.True(expectedExitCode == exitCode, "Unexpected exit code");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Assert.True(false, $"Test case failed with runtime error: {ex.Message}");
                }
            }
        }