Coder Social home page Coder Social logo

Comments (3)

Romanx avatar Romanx commented on August 14, 2024

Hi there,

Would you mind explaining what use case you could see for this that we could help with?

We already throw exceptions when parsing and rendering that you can use for such tracking so you could easily write an extension for your preferred asserting framework.

from stubble.

Bchir avatar Bchir commented on August 14, 2024

Hi,
Yes sure, here is what am expecting the assert function should do :
the assert function will need the template and the class that we would pass as view

  • Assert that the template doesn't have any syntax error like not Unclosed Block
  • Assert that there is no unknown property used like for example my class is a user class and it has username and email , but in the template i used phoneNumber, so it should fail the test for unknown property ( you can achieve this by using reflection on passed class )
  • I don't know all the features for this framework but if there is a method to add formatter or something it should validate that the formatter exists

it doesn't have to be used throw asserting framework for exmeple automapper framework has it's own assert method Mapper.Configuration.AssertConfigurationIsValid();
so it would be something similar to this like
StubbleVisitorRenderer.AssertRenderAsync<TSource>(string template,TSource view)

from stubble.

Romanx avatar Romanx commented on August 14, 2024

Hey there,

I've thought about this request and think it's probably best to live separately from the core library. If you'd be interested in creating an asserting project I can give you an example of something building on Xunit's existing functionality which would cover some of the basic cases you mentioned.

public static void AssertTemplateValidAsync<TSource>(string template, TSource view)
{
    if (assert == null)
    {
        throw new ArgumentNullException(nameof(assert));
    }

    var exception = Record.Exception(() =>
    {
        StaticStubbleRenderer.Instance.Render(template, view, new Settings.RenderSettings
        {
            ThrowOnDataMiss = true,
        });
    });

    if (exception is StubbleDataMissException dataMissException)
    {
        throw new Exception("Data was missing in template", dataMissException);
    }
    else if (exception is StubbleException stubbleException)
    {
        throw new Exception("An error occured validating template", stubbleException);
    }

    Assert.Null(exception);
}

Please let me know if you have any issues, thanks for using the library!

from stubble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.