Given.Common.TestStateManager.WriteSpecification C# (CSharp) Method

WriteSpecification() public method

public WriteSpecification ( object[]>.Action consoleAction = null ) : void
consoleAction object[]>.Action
return void
        public void WriteSpecification(Action<string, object[]> consoleAction = null)
        {
            foreach (var given in TestRunManager.TransientGivens.Where(x => x.Key == TestType.Name).SelectMany(x => x.Value))
            {
                AddGiven(given.Key, given.Value);
            }

            consoleAction = consoleAction ?? Console.WriteLine;
            var currentPrefix = Text.Given;
            foreach (var pair in Givens)
            {
                consoleAction(Text.Print, new object[] { currentPrefix, pair.Value.Replace("_", " ") });
                currentPrefix = Text.And;
            }
            currentPrefix = Text.When;
            foreach (var pair in Whens)
            {
                consoleAction(Text.Print, new object[] { currentPrefix, pair.Value.Replace("_", " ") });
                currentPrefix = Text.And;
            }
            currentPrefix = Text.Then;
            foreach (var pair in Thens)
            {
                consoleAction(Text.Print, new object[] { currentPrefix, pair.Value.Name.Replace("_", " ") });
                if (!string.IsNullOrEmpty(pair.Value.Message))
                    consoleAction(pair.Value.Message, new object[0]);

                currentPrefix = Text.And;
            }
        }

Usage Example

Ejemplo n.º 1
0
        public void Setup()
        {
            _testStateManager = new TestStateManager(this);
            var initializer = new TestInitializer(this,_testStateManager);

            //todo: there needs to be a common way to ignore setup for scenarios where all tests are ignored.  this sucks.
            if (!GetType().GetMethods().Any(y => new DefaultTestRunnerConfiguration().ThenIdentificationMethod(y) &&
                                                 !y.GetCustomAttributes(typeof (IgnoreAttribute), true).Any()))
            {
                return;
            }

            initializer.ProcessDelegates();
            _testStateManager.WriteSpecification();
        }