Closed Bchir closed 5 years ago
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.
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
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)
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!
Add Assert Template compile correctly for unit testing