❔ How do I can use my class objects in UnitTest project?

I wanted to try make unit tests for my projects. I'm getting an error with missing directive (CS0246). I had watched many tutorials and thier compiler hadn't problem with loading classes from original project. I'm using NUnit project added for my Solution (I couldn't do it with Ninject so I changed). I had done the project references. and
using <projectName>;
using <projectName>;
doesn't work. Program.cs (NUnit package was installed from NugGet)
// See https://aka.ms/new-console-template for more information
using System;
using System.Drawing;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
namespace testmati2709
{
class Program
{
public class User
{public Int64 ID;public String Name;public Boolean IsAdmin;}
class Rezerwacja
{
public User MadeBy {get;set;}
public Boolean CanBeCanceled(User u)
{
if(u.IsAdmin) { return true; }
if(u == MadeBy) { return true; }
return false;
}
}
static void Main(string[] args)
{
User Karolina = new User();Karolina.IsAdmin = true;User Mateusz = new User();
User Jurek = new User(); User Ola = new User();Ola.IsAdmin = true;
Rezerwacja Reze = new Rezerwacja { MadeBy = Mateusz};
Console.WriteLine(Reze.CanBeCanceled(Jurek));
}
}
}
// See https://aka.ms/new-console-template for more information
using System;
using System.Drawing;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
namespace testmati2709
{
class Program
{
public class User
{public Int64 ID;public String Name;public Boolean IsAdmin;}
class Rezerwacja
{
public User MadeBy {get;set;}
public Boolean CanBeCanceled(User u)
{
if(u.IsAdmin) { return true; }
if(u == MadeBy) { return true; }
return false;
}
}
static void Main(string[] args)
{
User Karolina = new User();Karolina.IsAdmin = true;User Mateusz = new User();
User Jurek = new User(); User Ola = new User();Ola.IsAdmin = true;
Rezerwacja Reze = new Rezerwacja { MadeBy = Mateusz};
Console.WriteLine(Reze.CanBeCanceled(Jurek));
}
}
}
(NUnit package was already installed) UnitTest1.cs
using System.Reflection.Metadata;
namespace testmati2709.UnitTest
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void Test1()
{
//a
var uzytkownik1 = new User();
//a
//a
}
}
}
using System.Reflection.Metadata;
namespace testmati2709.UnitTest
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void Test1()
{
//a
var uzytkownik1 = new User();
//a
//a
}
}
}
Usings.cs
global using NUnit.Framework;
global using testmati2709;
global using NUnit.Framework;
global using testmati2709;
Thanks
3 Replies
daysleeper
daysleeper13mo ago
take the User class outside of Program class
Ματι㊎②⑦⓪⑨
It works.
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.