1

I'm not even trying to test anything there yet, just wanted to create an instance of class Book(that I would like to test in the future) in my testing BookTests.cs file. I've added reference to GradeBook.Tests.csproj as whole source code to Gradebook is in the other folder. Yet it still returns CS0246 error : The type or namespace name 'Book' Could not be found. Are you missing a using directive of assembly reference?

Gradebook.Tests.csproj with directory tree

using System.Collections.Generic;
namespace Gradebook
{   
    public class Book
    {
       private List<double> grades; 
        private string name;
        public Book(string name)
        {
            this.name = name;
            grades  = new List<double>();
        }
        public void AddGrade(double grade)
        {
           grades.Add(grade);

        }
    }  
}

Book.cs

using System;
using Xunit;

namespace GradeBook.Tests
{
    public class BookTests
    {
        [Fact]
        public void Test1()
        {
            //arrange 
            var book2 = new Book("test");           


        }
    }
}

BookTests.cs

The code is pretty simple as I'm following Pluralsight course C# Fundamentals and I did everything like on the video. Tried also dotnet restore command. Path to project that contains Book.cs is probably correct(when i change something other errors occur). Working on VSC. What am I missing here?

suszonko
  • 15
  • 3

1 Answers1

0

I know it's been 2 months since this has last had an update, but the reason you're having an issue is because you're using the namespace Gradebook in Book.cs, but using GradeBook in BookTests.cs. (Notice the capital B)

Rename it so they're both Gradebook and ensure your directory names are correct and you should have no issues.