umbraco / UmbracoDocs

The official Umbraco Documentation
https://docs.umbraco.com
MIT License
266 stars 770 forks source link

Mocking/faking IPublishedContent ContentType.Alias #1664

Closed stevetemple closed 5 years ago

stevetemple commented 5 years ago

Missing documentation

What article/section is this about? Following on from Twitter discussion: https://twitter.com/zpqrtbnk/status/1115297266036875265 about unit testing IPublishedContent in v8

Describe the issue:

In v7 IPublishedContent has a DocTypeAlias property which let you very easily mock/fake it.

In v8 you have ContentType which isn't using an interface put a concrete type which is fairly difficult to create.

Is there a good way of Mocking that or is creating a fake like the following the best way ?

https://github.com/umco/umbraco-ditto/blob/6ad7853f9502dbde4736d894f882debf11b67c45/tests/Our.Umbraco.Ditto.Tests/Mocks/MockPublishedContent.cs#L70

jmayntzhusen commented 5 years ago

Hey @stevetemple

Thanks for bringing it here so we can hopefully get it documented for v8!

zpqrtbnk commented 5 years ago

See https://github.com/umbraco/Umbraco-CMS/issues/5170 which is introducing an IPublishedContentType interface where a concrete PublishedContentType class was used - should make it was easier to mock?

Feel free to comment on https://github.com/umbraco/Umbraco-CMS/issues/5170 if you need more!

stevetemple commented 5 years ago

Thanks @zpqrtbnk this does make it look easier, I will give it a whirl

nul800sebastiaan commented 5 years ago

This issue has been in the up for grabs state for quite a while now and it seems nobody is ready to pick this one up.

For now we'll close this issue to prevent the list of up for grabs from becoming very stale. We're happy to re-open it if someone still thinks it's good to work on this.

If anyone is about to pick this issue up to fix it, make sure to test first if you can reproduce the problem in the latest version before you start to work on it.

Thanks! Sebastiaan on behalf of Umbraco HQ.