Unit Test not longer work after update from Kentico 9 to Kentico 10

214 views Asked by At

My unitTests not longer work after Update from Kentico 9 to Kentico 10.

I have a UnitTest like this. (worked fine on Kentico 9)

    [SetUp]
    public void setUp()
    {
        this.pageCreator = new PageCreator();
        this.fixture = new Fixture();
        this.fixture.Customize(new AutoMoqCustomization());
    }
     [Test]
    public void execute()
    {
        this.pageCreator.Execute(null);
    }

I just try to call this Function

 public class PageCreator : ITask
 {
  public string Execute(TaskInfo task)
    {
        try
        {
            this.treeProvider = new TreeProvider(MembershipContext.AuthenticatedUser);
            this.createPages(this.treeProvider);

            return successMessage;
        }
        catch (Exception ex)
        {
            this.sendMailToDeveloper(ex.Message);
            return "Fail";
        }

The Problem is, when I try run my test, I get an Error (because of MembershipContext.AuthenticatedUser [CMS.Membership.MembershipContext.AuthenticatedUser" hat eine Ausnahme vom Typ "System.InvalidOperationException" verursacht])

enter image description here

When I try to make the same in debugMode, everything is working fine.

enter image description here

What can be the problem and how can I fix it ?
I have load all the new Dll from Kentico 10 but nothing changed.

Thanks for your help

1

There are 1 answers

1
eugenecp On

try updating your references on the test project to use the Kentico10 nuget packages. the release notes have a section on Automated Tests - https://docs.kentico.com/k10/release-notes-kentico-10

"Automated testing – New Kentico.Libraries.Tests integration package, which separately provides all functionality related to automated testing of the Kentico API. The testing API is no longer available directly within Kentico projects or the main Kentico.Libraries integration package."