Comments (3)
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.
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.
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)
- How can I solve nested stubble values from mustache HOT 1
- Any idea to .net core Startup.cs Factory for StubbleBuilder? HOT 2
- Render variable names instead of empty strings? HOT 3
- Compiled renderer evaluating int? truthy value incorrectly HOT 1
- Get output as object rather than string from Render HOT 4
- Render a tag correctly however it is null! HOT 1
- Not compatible with .Net standard 2.1 and .Net Core 3.1 HOT 3
- SetIgnoreCaseOnKeyLookup does not work HOT 2
- An attribute in the template is "User.Name" Parse error HOT 1
- Parent nested object access HOT 2
- Render pipeline is not passed to partials HOT 1
- Execute method with parameter's default value HOT 4
- Add Cake plugin
- Compiled renderer throws exception when compiling interpolated nullable int HOT 1
- Truthiness on a Dictionary<string, object> HOT 5
- PartialTagParser exhaustion side effect?!
- [Question/Discussion] Rework of the Parser to support more information on its output
- Anonymous object property is not retrieved HOT 4
- Please add Extensions Setting Support for system.text.json HOT 1
- How to count number of variables in a template ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stubble.