Source

SubSpec / test / SubSpec.Tests / test.utility / SubSpecAcceptanceTest.cs

using System.IO;
using System.Xml;
using System;
using System.Linq;
using System.Collections.Generic;
using Xunit.Extensions;
namespace TestUtility
{
    public class SubSpecAcceptanceTest
    {
        public XmlNode ExecuteSpecification( string code )
        {
            return ExecuteWithAdditionalFilesIncluded( code, "SubSpec.cs" );
        }

        public XmlNode ExecuteThesis( string code )
        {
            return ExecuteWithAdditionalFilesIncluded( code, "SubSpec.cs", "SubSpec.Thesis.cs" );
        }

        private static XmlNode ExecuteWithAdditionalFilesIncluded( string code, params string[] files )
        {
            string codeFile = Guid.NewGuid().ToString( "D" ) + ".cs";

            File.WriteAllText( codeFile, code );
            using (new SubSpec.DisposableAction( () => File.Delete( codeFile ) ))
            {
                using (MockAssembly mockAssembly = new MockAssembly())
                {
                    mockAssembly.Compile( files.Prepend( codeFile ).ToArray(), typeof( TheoryAttribute ).Assembly.Location );
                    return mockAssembly.Run();
                }
            }
        }
    }

    internal static class Mixin
    {
        public static IEnumerable<T> Prepend<T>( this IEnumerable<T> source, T item )
        {
            yield return item;

            foreach (var x in source)
            {
                yield return x;
            }
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.