[英]asp.net web forms unit test parsing xml test returned collection
I have a web forms application that parses some xml and returns a collection. 我有一个Web窗体应用程序,可以解析一些xml并返回一个集合。 I use a utitily class that parses the xml.
我使用解析XML的实用类。 Im trying to write a unit test to check the returned collection of objects.
我试图编写一个单元测试来检查返回的对象集合。 heres my code
这是我的代码
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Web_Application.Models;
using System.Collections.Generic;
namespace _Web_Application.Tests
{
[TestClass]
public class UnitTest1
{
string source = @"C:\Users\F\Desktop\Web Application\Web Application.Tests\LunchTest.xml";
[TestMethod]
public void ParseXml()
{
XmlUlitilyClass x = new XmlUlitilyClass();
x.ParseXml(source);
Assert.AreEqual(x.ParseXml(source).Last(), 4);
Assert.AreEqual(x.ParseXml(source).Last().Name, "Roast of the day");
Assert.AreEqual(x.ParseXml(source).Last().DesertIncluded, true);
}
}
}
is the correct way to do this or am i way off thanks 是执行此操作的正确方法,还是我离开了?谢谢
It's a good approach. 这是一个好方法。 My only concern is the source file
@"C:\\Users\\F\\Desktop\\Web Application\\Web Application.Tests\\LunchTest.xml";
我唯一关心的是源文件
@"C:\\Users\\F\\Desktop\\Web Application\\Web Application.Tests\\LunchTest.xml";
must be on every machine that runs the test. 必须在运行测试的每台计算机上。
Does XmlUlitilyClass
accept a XML string instead of filename? XmlUlitilyClass
是否接受XML字符串而不是文件名? If so pass it the contents of LunchTest.xml
. 如果是这样,
LunchTest.xml
的内容传递给它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.