Ejemplo n.º 1
0
    public void Build_CreatesDefaultCodeTarget()
    {
        // Arrange
        var codeDocument = TestRazorCodeDocument.CreateEmpty();
        var options      = RazorCodeGenerationOptions.CreateDefault();

        var builder = new DefaultCodeTargetBuilder(codeDocument, options);

        var extensions = new ICodeTargetExtension[]
        {
            new MyExtension1(),
            new MyExtension2(),
        };

        for (var i = 0; i < extensions.Length; i++)
        {
            builder.TargetExtensions.Add(extensions[i]);
        }

        // Act
        var result = builder.Build();

        // Assert
        var target = Assert.IsType <DefaultCodeTarget>(result);

        Assert.Equal(extensions, target.Extensions);
    }
Ejemplo n.º 2
0
    public static CodeTarget CreateDefault(
        RazorCodeDocument codeDocument,
        RazorCodeGenerationOptions options,
        Action <CodeTargetBuilder> configure)
    {
        if (codeDocument == null)
        {
            throw new ArgumentNullException(nameof(codeDocument));
        }

        if (options == null)
        {
            throw new ArgumentNullException(nameof(options));
        }

        var builder = new DefaultCodeTargetBuilder(codeDocument, options);

        if (builder.Options.DesignTime)
        {
            AddDesignTimeDefaults(builder);
        }
        else
        {
            AddRuntimeDefaults(builder);
        }

        if (configure != null)
        {
            configure.Invoke(builder);
        }

        return(builder.Build());
    }
Ejemplo n.º 3
0
    public static CodeTarget CreateEmpty(
        RazorCodeDocument codeDocument,
        RazorCodeGenerationOptions options,
        Action <CodeTargetBuilder> configure)
    {
        if (codeDocument == null)
        {
            throw new ArgumentNullException(nameof(codeDocument));
        }

        if (options == null)
        {
            throw new ArgumentNullException(nameof(options));
        }

        var builder = new DefaultCodeTargetBuilder(codeDocument, options);

        configure?.Invoke(builder);
        return(builder.Build());
    }