When creating the task I can get this alias. However when the enqueued job runs I get a null reference exception
Product.GetModelPropertyType(x => x.Sku).Alias;
Stack trace (not much)
Object reference not set to an instance of an object.
at Umbraco.ModelsBuilder.Embedded.PublishedModelUtility.GetModelContentType(PublishedItemType itemType, String alias)
So I worked around this. Again the beauty of tdd. What it exposed is in my validator class i should not be passing in IContent. Reason is my class then is doing more than one thing i.e getting values then validating. Its responsibility should only be validation.
So bit of refactor now my method looks like:
public ValidationResult Validate(IAlert alertContent)
Now in my event I can create new IAlert and map properties using modelsbuilder. However in my test I can pass in IAlert I have created myself with know values although I get those values via IContent mock but the aliases are magic strings. Not ideal but better than before.
Tdd with IContent and models builder
I have a test suite that tests logic of a class that validates IContent object based on its property values. All works fine.
In the class under test to get property values I am using magic strings, ideally I want to use models builder to get the property so instead of:
I want to do:
However trying to do that causes the tests to blow up with exception
So is there a way of stopping that?
Regards
Ismail
I have the same issue in v8 using hangfire.
When creating the task I can get this alias. However when the enqueued job runs I get a null reference exception
Stack trace (not much)
Matt,
So I worked around this. Again the beauty of tdd. What it exposed is in my validator class i should not be passing in IContent. Reason is my class then is doing more than one thing i.e getting values then validating. Its responsibility should only be validation.
So bit of refactor now my method looks like:
Now in my event I can create new IAlert and map properties using modelsbuilder. However in my test I can pass in IAlert I have created myself with know values although I get those values via IContent mock but the aliases are magic strings. Not ideal but better than before.
Ismail
In v8 I set in my background task once I had used an
IUmbracoContextFactory
create me a context.is working on a reply...