Garota de Programas
Garota de Programas

Reputation: 23

C# Unit Test is not recognizing other classes

1st - Help the community, if you give a negative mark, at least explain why, so I will not repeat it!

I am a Begginer, and I'm trying to test a simple class. But my UnitTest do not recognize the other namespace, even though I have added the Reference. See the reference above

I can not use the "using" directive:

enter image description here

It's a .net Core 3.1 project. VS 2019 community

It probably is something really silly, but I'm stuck in it,and have tried everything I know.

The class I want to import

namespace DI.BLL
{
    public class ContainerBuilder
    {
        private readonly IList<Type> _registration = new List<Type>();

        public void Register<T>()
        {
            this._registration.Add(typeof(T));
        }

        public Container Build() => new Container(_registration);
    }
}

The test code:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
using DI.BLL;

namespace DI.Test
{
    [TestClass]
    public class Container
    {
        [Fact]
        public void Should_Be_Able_To_Resolve_A_Class_Instance()
        {

            var builder = new ContainerBuilder();
            builder.Register<Cars>();
            var sut = builder.Build();
            Assert.IsNotNull(instance);
        }

    }
}

Upvotes: 1

Views: 2220

Answers (1)

Garota de Programas
Garota de Programas

Reputation: 23

As Geoff James said, I was using different versios of the framework The project class was using the Core framework, while the Test project was using the .NET 4.7. Got them into the same version and it's working perfectly

Upvotes: 1

Related Questions