private static DefaultRazorDirectiveFeature GetDirectiveFeature(RazorProjectEngineBuilder builder)
    {
        var directiveFeature = builder.Features.OfType <DefaultRazorDirectiveFeature>().FirstOrDefault();

        if (directiveFeature == null)
        {
            directiveFeature = new DefaultRazorDirectiveFeature();
            builder.Features.Add(directiveFeature);
        }

        return(directiveFeature);
    }
    public void AddDirective_UsesExistingFeatureIfExistsAndAddsTo()
    {
        // Arrange
        var builder          = new DefaultRazorProjectEngineBuilder(RazorConfiguration.Default, Mock.Of <RazorProjectFileSystem>());
        var directiveFeature = new DefaultRazorDirectiveFeature();

        builder.Features.Add(directiveFeature);
        var expecteDirective = Mock.Of <DirectiveDescriptor>();

        // Act
        builder.AddDirective(expecteDirective);

        // Assert
        var feature = Assert.Single(builder.Features);

        Assert.Same(directiveFeature, feature);
        var directive = Assert.Single(directiveFeature.Directives);

        Assert.Same(expecteDirective, directive);
    }
    public void AddDirective_ExistingFeature_UsesFeature()
    {
        // Arrange
        var expected = new DefaultRazorDirectiveFeature();
        var engine   = RazorEngine.CreateEmpty(b =>
        {
            b.Features.Add(expected);

            // Act
            b.AddDirective(DirectiveDescriptor.CreateDirective("test", DirectiveKind.SingleLine));
        });

        // Assert
        var actual = Assert.Single(engine.Features.OfType <IRazorDirectiveFeature>());

        Assert.Same(expected, actual);

        var directive = Assert.Single(actual.Directives);

        Assert.Equal("test", directive.Directive);
    }