EstablishExecutionEnvironment() public méthode

Set up the execution environment to match a context. Note that we may be running on the same thread where the context was initially created or on a different thread.
public EstablishExecutionEnvironment ( ) : void
Résultat void
Exemple #1
0
        public void SetAndRestoreCurrentCulture()
        {
            var context = new TestExecutionContext(_setupContext);

            try
            {
                CultureInfo otherCulture =
                    new CultureInfo(originalCulture.Name == "fr-FR" ? "en-GB" : "fr-FR");
                context.CurrentCulture = otherCulture;
                Assert.AreEqual(otherCulture, CultureInfo.CurrentCulture, "Culture was not set");
                Assert.AreEqual(otherCulture, context.CurrentCulture, "Culture not in new context");
                Assert.AreEqual(_setupContext.CurrentCulture, originalCulture, "Original context should not change");
            }
            finally
            {
                _setupContext.EstablishExecutionEnvironment();
            }

            Assert.AreEqual(CultureInfo.CurrentCulture, originalCulture, "Culture was not restored");
            Assert.AreEqual(_setupContext.CurrentCulture, originalCulture, "Culture not in final context");
        }
        public void SetAndRestoreCurrentDirectory()
        {
            var context = new TestExecutionContext(setupContext);

            try
            {
                string otherDirectory = System.IO.Path.GetTempPath();
                if (otherDirectory[otherDirectory.Length - 1] == System.IO.Path.DirectorySeparatorChar)
                {
                    otherDirectory = otherDirectory.Substring(0, otherDirectory.Length - 1);
                }
                context.CurrentDirectory = otherDirectory;
                Assert.AreEqual(otherDirectory, Environment.CurrentDirectory, "Directory was not set");
                Assert.AreEqual(otherDirectory, context.CurrentDirectory, "Directory not in new context");
                Assert.AreEqual(setupContext.CurrentDirectory, originalDirectory, "Original context should not change");
            }
            finally
            {
                setupContext.EstablishExecutionEnvironment();
            }

            Assert.AreEqual(Environment.CurrentDirectory, originalDirectory, "Directory was not restored");
            Assert.AreEqual(setupContext.CurrentDirectory, originalDirectory, "Directory not in final context");
        }
        public void SetAndRestoreValueFormatter()
        {
            var context           = new TestExecutionContext(setupContext);
            var originalFormatter = context.CurrentValueFormatter;

            try
            {
                ValueFormatter f = val => "dummy";
                context.AddFormatter(next => f);
                Assert.That(context.CurrentValueFormatter, Is.EqualTo(f));

                context.EstablishExecutionEnvironment();
                Assert.That(MsgUtils.FormatValue(123), Is.EqualTo("dummy"));
            }
            finally
            {
                setupContext.EstablishExecutionEnvironment();
            }

            Assert.That(TestExecutionContext.CurrentContext.CurrentValueFormatter, Is.EqualTo(originalFormatter));
            Assert.That(MsgUtils.FormatValue(123), Is.EqualTo("123"));
        }
        public void SetAndRestoreValueFormatter()
        {
            var context = new TestExecutionContext(setupContext);
            var originalFormatter = context.CurrentValueFormatter;

            try
            {
                ValueFormatter f = val => "dummy";
                context.AddFormatter(next => f);
                Assert.That(context.CurrentValueFormatter, Is.EqualTo(f));

                context.EstablishExecutionEnvironment();
                Assert.That(MsgUtils.FormatValue(123), Is.EqualTo("dummy"));
            }
            finally
            {
                setupContext.EstablishExecutionEnvironment();
            }

            Assert.That(TestExecutionContext.CurrentContext.CurrentValueFormatter, Is.EqualTo(originalFormatter));
            Assert.That(MsgUtils.FormatValue(123), Is.EqualTo("123"));
        }