Sha256: 9216ae62ad717f42c1c684ba234701e64df651857fe196192b51838b85c73a9b

Contents?: true

Size: 1.3 KB

Versions: 65

Compression:

Stored size: 1.3 KB

Contents

using System.Collections.Generic;
using System.Linq;
using Generators.Methods;

namespace Generators.Classes
{
    public static class TestClassRenderer
    {
        private const string TestClassTemplate =
@"{UsingNamespaces}

public class {ClassName}
{
{Body}
}";

        public static string Render(TestClass testClass) =>
            TestClassTemplate
                .Replace("{UsingNamespaces}", RenderUsingNamespaces(testClass))
                .Replace("{ClassName}", testClass.ClassName)
                .Replace("{Body}", RenderBody(testClass));

        private static string RenderUsingNamespaces(TestClass testClass) =>
           string.Join("\n", testClass.UsingNamespaces.Select(usingNamespace => $"using {usingNamespace};"));

        private static string RenderBody(TestClass testClass) =>
           string.Join("\n\n", GetBodyParts(testClass));

        private static IEnumerable<string> GetBodyParts(TestClass testClass) =>
            from bodyPart in new [] { testClass.BeforeTestMethods, RenderTestMethods(testClass), testClass.AfterTestMethods }
            where !string.IsNullOrWhiteSpace(bodyPart)
            select bodyPart;

        private static string RenderTestMethods(TestClass testClass) =>
           string.Join("\n\n", testClass.TestMethods.Select(TestMethodRenderer.Render));
    }
}

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
trackler-2.1.0.34 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.33 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.32 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.31 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.30 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.29 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.28 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.27 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.26 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.25 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.24 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.23 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.22 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.21 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.20 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.19 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.18 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.17 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.16 tracks/csharp/generators/Classes/TestClassRenderer.cs
trackler-2.1.0.15 tracks/csharp/generators/Classes/TestClassRenderer.cs