1

Visual Studio (2010) で非常に単純なドメイン レイヤーを作成しました。次に、新しいテスト ウィザードを使用して、基本的な単体テストを作成しました。ただし、コードをテストできるように using ステートメントを挿入しようとすると、名前空間が見つからなかったと表示されます... Visual Studio を使用するのはこれが初めてなので、自分が何をしているのか途方に暮れています違う。

私のコード

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();

        }
    }
}
4

4 に答える 4

4

using は、特定のクラスではなく名前空間を参照します (クラス名のエイリアスを追加しない限り)。using ステートメントには、Home という単語のみを含める必要があります。

using Home.InventoryType.InventorySelect; 
//becomes
using Home;

ディレクティブの使用に関するMSDN へのリンクは次のとおりです: using Directive (C#)

于 2012-09-09T16:16:46.197 に答える
2

テストクラスは独自のプロジェクトにあると想定しているため、そのプロジェクトへの参照を追加する必要があります。(usingステートメントは参照を追加しません。名前を完全に修飾せずにコードで型を使用できるようにするだけです。)

于 2012-09-09T16:20:08.227 に答える
2

InventoryTypeクラスを次のように宣言しますpublic

InventorySelectクラスprivatepublic

于 2012-09-09T16:08:45.527 に答える