0

I have referenced my WPF project to an NUnit Test Project I made. I am trying to call a function of it but I get the following compilation error:

Reference to type 'DependencyObject' claims it is defined in 'WindowsBase', but it could not be found

I have added PresentationFramework, PresentationCore and WindowsBase as references in the "Assemblies" section of the NUnit test but no go... Not sure what I'm doing wrong... the code is very basic...

using NUnit.Framework;
using System.Collections.Generic;
using System.Threading;
using CM;

namespace Tests
{
    [TestFixture, Apartment(ApartmentState.STA)]
    public class Tests
    {
        InstUserControl userControlMV = new InstUserControl ();

        [Test]
        public void Test1()
        {
            List<string> pOptions = new List<string>() { "2x4", "4x6" };
            userControlMV.SetPOptions(pOptions);
            Assert.Pass();
        }
    }
}

Anyone know what I'm doing wrong.

1
  • I know that the NUnit has a version of .NET Core... and my WPF is 4.7.2... Commented Sep 10, 2019 at 13:10

1 Answer 1

2

You cannot create a NUnit Test Project (.NET Core) to test a WPF application that targets the .NET Framework. Here is what you should do:

  • Create a new Unit Test Project (.NET Framwork)
  • Install the NUnit and NUnit3TestAdapter NuGet packages into it
  • Add a reference to the WPF project to be tested
  • Add a reference to PresentationFramework.dll
  • Add a reference to PresentationCore.cll
  • Add a reference to WindowsBase.dll
  • Run your tests.
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks mm8! What about adding a STAttribute or anything like that?
The ApartmentAttribute that you have decorated your Tests class with still applies.
Thanks mm8... always helping me out!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.