Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
There is any posibilty to mock PublishedDataType class?
I need to make a mock of IPublishedContent with property witch contains PublishedPropertyType with specify PublishedDataType.
I wrote somthing like that:
var publishedDataType = Mock.Of<PublishedDataType>(dt => dt.EditorAlias == editorAlias && dt.Configuration == defaultConfiguration); var publishedPropertyType = new Mock<PublishedPropertyType>(); publishedPropertyType.Setup(s => s.DataType).Returns(publishedDataType); var publishedContentMock = new Mock<IPublishedContent>(); SetupPropertyValue(publishedContentMock, publishedPropertyType.Object, "propertyName", null); PublishedContentQuery.Setup(c => c.Content(contentId)).Returns(publishedContentMock.Object); public void SetupPropertyValue(Mock<IPublishedContent> publishedContentMock, IPublishedPropertyType publishedPropertyType, string alias, object value, string culture = null, string segment = null) { var property = new Mock<IPublishedProperty>(); property.Setup(x => x.Alias).Returns(alias); property.Setup(x => x.GetValue(culture, segment)).Returns(value); property.Setup(x => x.HasValue(culture, segment)).Returns(value != null); property.Setup(x => x.PropertyType).Returns(publishedPropertyType); publishedContentMock.Setup(x => x.GetProperty(alias)).Returns(property.Object); }
But PublishedDataType class has only internal constructor so I can't create them. Is any way to get around this problem?
Hi,
The most simple way is to let your test assembly identity as "Umbraco.Tests".
From Umbraco.Tests:
https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Tests/Properties/AssemblyInfo.cs
From Umbraco.Core:
https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Core/Properties/AssemblyInfo.cs
Umbraco does this, to allow internals to be called from their own tests.
Thank for the hint. I added the below tags to project file (.csproj) of my unit tests and it's works.
<PropertyGroup> <AssemblyName>Umbraco.Tests</AssemblyName> </PropertyGroup>
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Unit testing: Mock PublishedDataType
There is any posibilty to mock PublishedDataType class?
I need to make a mock of IPublishedContent with property witch contains PublishedPropertyType with specify PublishedDataType.
I wrote somthing like that:
But PublishedDataType class has only internal constructor so I can't create them. Is any way to get around this problem?
Hi,
The most simple way is to let your test assembly identity as "Umbraco.Tests".
From Umbraco.Tests:
https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Tests/Properties/AssemblyInfo.cs
From Umbraco.Core:
https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Core/Properties/AssemblyInfo.cs
Umbraco does this, to allow internals to be called from their own tests.
Thank for the hint. I added the below tags to project file (.csproj) of my unit tests and it's works.
is working on a reply...