Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael 8 posts 88 karma points
    Jul 29, 2022 @ 15:20
    Michael
    0

    Same code work in Umbraco 8 but failure version 10

    Hi :

    I have to migrate unit test, but find the error in Umbraco 10

    [Fact]
            public void MyCodeTest() {
                var parentAlias = "parentAlias";
                var testParentCode = new Mock<IPublishedContent>();
                var testParentCodeProperty = new Mock<IPublishedProperty>();
                var cultureCodeElement = new List<IPublishedElement>();
                testParentCodeProperty.Setup(s => s.Alias).Returns(parentAlias);
                testParentCodeProperty.Setup(s => s.GetValue(null, null)).Returns(cultureCodeElement);
                testParentCodeProperty.Setup(s => s.HasValue(null, null)).Returns(true);
                testParentCode.Setup(s => s.GetProperty(parentAlias)).Returns(testParentCodeProperty.Object);
    
                var testSiteNode = new Mock<IGetSiteNode>();
                testSiteNode.Setup(x => x.FromNodePath(It.IsAny<string>())).Returns(testParentCode.Object);
    
                var resultNode = testSiteNode.Object.FromNodePath(parentAlias);
                var result = resultNode?.Value(parentAlias) as IEnumerable<IPublishedElement>;
                result.Should().NotBeNull();
            }
    

    This code is work for Umbraco 8, when I go to Umbraco 10 during the code var result = resultNode?.Value(parentAlias) as IEnumerable<IPublishedElement>; it throw the exception :

    System.TypeInitializationException: 'The type initializer for 'Umbraco.Extensions.FriendlyPublishedContentExtensions' threw an exception.'
    

    Inner exception :

    ArgumentNullException: Value cannot be null. (Parameter 'provider')
    

    do you have any idea?

  • Hüseyin 13 posts 103 karma points
    Nov 20, 2023 @ 10:01
    Hüseyin
    0

    Hi there, I need to write some unit tests but we still got this error. I use these packages and this code. nothing else . umbraco v12.2.0 . xunit v2.5.3 . NSubstitute v5.1.0

    var content = Substitute.For<IPublishedContent>();
    content.Value<string>("title").Returns("Title");
    

    @DennisAdolfi @RasmusOlofsson

Please Sign in or register to post replies

Write your reply to:

Draft