DotNet中获取系统信息(二)

    首次使用TDD,还有很多不大清楚,敬请高人指教!
    单元测试代码如下:
using  System;
using  System.Net;
using  NUnit.Framework;

namespace  SystemInfomation
{
    
/**//// <summary>
    
/// Summary description for GetInfoFixture.
    
/// </summary>

    [TestFixture]
    
public class SystemInfomationFixture
    
{
        
private const string OS_VERION = "Microsoft Windows NT 5.2.3790.0";
        
private const string MACHINE_NAME = "VC";
        
private const string USER_NAME = "Vincent";
        
private const string BOOT_MODE = "Normal";
        
private const string LOGICAL_DRIVERS = @"A:\;C:\;D:\;E:\;F:\;G:\;H:\;I:\;J:\;K:\;L:\;M:\;O:\;";
        
private const string IP_ADDR = "192.168.0.10 192.168.35.1 192.168.188.1 ";
        
private const string DOMAIN_NAME = "VC";
        
private const string SYSTEM_DIR = @"C:\Windows\System32";
        
private const string TEMP_DIR = @"C:\DOCUME~1\VINCENT\LOCALS~1\TEMP";
        
private const string FX_VVERSION = "1.1.4322.573";
        
private const string PROCESSOR_NAME = "AMD Athlon(tm) XP 1600+";
        
private const string PROCESSOR_IDENTIFIER = "x86 Family 6 Model 6 Stepping 2";
        
private const string PROCESSOR_FREQUENCY = "1405 MHz";
        
private const string BIOS_IDENTIFIER = "AT/AT COMPATIBLE";
        
private const string SYSTEM_BISO_VERSION = "AMIINT - 10";
        
private const string VIDEO_BISO_VERSION = "Version 3.11.01.24.00 ";
        
private const string VIDEO_BISO_DATE = "10/31/01";
        
private const string NETWORK_CARDS = "Realtek RTL8139 Family PCI Fast Ethernet NIC";

        
private SystemInfomation info;

        
public SystemInfomationFixture()
        
{
            
//
            
// TODO: Add constructor logic here
            
//
        }


        [SetUp]
        
public void Init()
        
{
            info 
= new SystemInfomation();
        }


        [Test]
        
public void testGetOSVersion()
        
{
            Console.Out.WriteLine(info.GetOSVersion());
            Assert.AreEqual(OS_VERION, info.GetOSVersion());
        }


        [Test]
        
public void testGetMachineName()
        
{
            Console.Out.WriteLine(info.GetMachineName());
            Assert.AreEqual(MACHINE_NAME, info.GetMachineName());
        }


        [Test]
        
public void testGetBootMode()
        
{
            Console.Out.WriteLine(info.GetBootMode());
            Assert.AreEqual(BOOT_MODE, info.GetBootMode());
        }


        [Test]
        
public void testGetUserName()
        
{
            Console.Out.WriteLine(info.GetUserName());
            Assert.AreEqual(USER_NAME, info.GetUserName());
        }


        [Test]
        
public void testGetLogicalDrives()
        
{
            
string drivers = "";
            
foreach (string drive in info.GetLogicalDrives())
            
{
                drivers 
+= drive + ";";
            }

            Console.WriteLine(drivers);
            Assert.AreEqual(LOGICAL_DRIVERS, drivers);
        }


        [Test]
        
public void testGetIPAddr()
        
{
            
string ip = "";
            IPAddress[] ipAddress
= info.GetIPAddr();
            
foreach (IPAddress address in ipAddress)
            
{
                Console.Out.WriteLine(address.ToString());
                ip 
+= address.ToString() + " ";
            }

            Assert.AreEqual(IP_ADDR, ip);
        }


        [Test]
        
public void testGetDomainName()
        
{
            Console.Out.WriteLine(info.GetDomainName());
            Assert.AreEqual(DOMAIN_NAME, info.GetDomainName());
        }


        [Test]
        
public void testGetUsedMemory()
        
{
            Console.Out.WriteLine(info.GetUsedMemory());
            Assert.IsNotNull(info.GetUsedMemory());
        }


        [Test]
        
public void testGetSystemDirectory()
        
{
            Console.Out.WriteLine(info.GetSystemDirectory());
            Assert.AreEqual(SYSTEM_DIR.ToUpper(), info.GetSystemDirectory().ToUpper());
        }


        [Test]
        
public void testGetTempDirectory()
        
{
            Console.Out.WriteLine(info.GetTempDirectory());
            Assert.AreEqual(TEMP_DIR.ToUpper(), info.GetTempDirectory().ToUpper());
        }


        [Test]
        
public void testGetFxVersion()
        
{
            Console.Out.WriteLine(info.GetFxVersion());
            Assert.AreEqual(FX_VVERSION, info.GetFxVersion());
        }


        [Test]
        
public void testGetOSRunnedTime()
        
{
            RunnedTime runnedTime 
= info.GetOSRunnedTime();
            
string time = runnedTime.hour + " hour " + 
                runnedTime.minute 
+ " minute " + runnedTime.second + " second";
            Console.WriteLine(time);            
            Assert.IsNotNull(time);
        }


        [Test]
        
public void testGetProcessorName()
        
{
            Console.WriteLine(info.GetProcessorName()[
0]);
            Assert.AreEqual(PROCESSOR_NAME, info.GetProcessorName()[
0]);
        }


        [Test]
        
public void testGetProcessorIdentifier()
        
{
            Console.WriteLine(info.GetProcessorIdentifier()[
0]);
            Assert.AreEqual(PROCESSOR_IDENTIFIER, info.GetProcessorIdentifier()[
0]);
        }


        [Test]
        
public void testGetProcessorFrequency()
        
{
            Console.WriteLine(info.GetProcessorFrequency()[
0]);
            Assert.AreEqual(PROCESSOR_FREQUENCY, info.GetProcessorFrequency()[
0]);
        }


        [Test]
        
public void testGetBiosIdentifier()
        
{
            Console.Out.WriteLine(info.GetBiosIdentifier());
            Assert.AreEqual(BIOS_IDENTIFIER, info.GetBiosIdentifier());
     &#

你可能感兴趣的:(windows,XP,OS,TDD,vc++)