尝试单元测试某个类项目的一些简单代码,但是在我的测试代码中 - 它一直告诉我我的InventorySelect找不到。它问我是否缺少使用声明等,但就我所见,这一切都是正确的。c#,找不到类型?
我的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Home
{
class InventoryType
{
/// <summary>
/// Selects the inventory type and returns the selected value
/// </summary>
public class InventorySelect
{
private string inventoryTypes;
public String InventoryTypes
{
set
{
inventoryTypes = value;
}
get
{
return inventoryTypes;
}
}
/// <summary>
/// Validate that the inventory is returning some sort of value
/// </summary>
/// <returns></returns>
public bool Validate()
{
if (InventoryTypes == null) return false;
return true;
}
}
}
}
我的测试代码
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Home.InventoryType.InventorySelect;
namespace HomeTest
{
[TestClass]
public class TestInventoryTypeCase
{
[TestMethod]
public void TestInventoryTypeClass()
{
InventorySelect select = new InventorySelect();
select.inventoryTypes = "Collection";
if (Validate() = true)
Console.WriteLine("Test Passed");
else
if (Validate() = false)
Console.WriteLine("Test Returned False");
else
Console.WriteLine("Test Failed To Run");
Console.ReadLine();
}
}
}
你意外地嵌套你的类。内部类称为'InventoryType.InventorySelect'。 – CodesInChaos
CodesInChaos说,你嵌套你的类。此外,任何C#类的默认可见性都是内部的,因此InventoryType对测试项目不可见。 –
@CodesInChaos发表您的评论作为回答 –