我目前正在尝试学习如何使用单元测试,并且我已经创建了 3 个动物对象的实际列表和 3 个动物对象的预期列表。问题是我如何断言检查列表是否相等?我试过 CollectionAssert.AreEqual 和 Assert.AreEqual 但无济于事。任何帮助,将不胜感激。
测试方法:
[TestMethod]
public void createAnimalsTest2()
{
animalHandler animalHandler = new animalHandler();
// arrange
List<Animal> expected = new List<Animal>();
Animal dog = new Dog("",0);
Animal cat = new Cat("",0);
Animal mouse = new Mouse("",0);
expected.Add(dog);
expected.Add(cat);
expected.Add(mouse);
//actual
List<Animal> actual = animalHandler.createAnimals("","","",0,0,0);
//assert
//this is the line that does not evaluate as true
Assert.Equals(expected ,actual);
}
Run Code Online (Sandbox Code Playgroud) 我目前正试图了解所有不同的设计模式,我已经设置了IQueryable基于不同列排序的任务,这是当前实现的方式:
if (choice == 1)
{
return from Animals in ctx.Animals orderby Animals.AnimalID descending select Animals;
}
else if (choice == 2)
{
return from Animals in ctx.Animals orderby Animals.Name descending select Animals;
}
else if (choice == 3)
{
return from Animals in ctx.Animals orderby Animals.Age descending select Animals;
}
Run Code Online (Sandbox Code Playgroud)
然而,这似乎是一个糟糕的代码味道,它没有能力轻松添加不同的字段或排序选项,我的导师告诉我,实施策略模式并使用a Dictionary选择策略实现我们会更好但是,我不确定战略模式将如何应用于这种情况,任何有用的提示将非常感激,如果需要更多信息,请问.
我有一个奇怪的问题,我在每一行都有一个这个公式的列:
=IF(C6="";"";D6-LEN(B6))
Run Code Online (Sandbox Code Playgroud)
它工作得很好,如果它旁边的单元格为空,则将其设为空单元格,如果不是,则显示计算的长度.但是,当我尝试使用条件格式在长度大于5时使其变为红色时,它会突出显示"空白"的单元格(具有公式,但显示为空白).任何关于为什么会发生这种情况的想法将不胜感激.
PS.我目前正在使用Open Office 4.0.1,它似乎工作正常,但当我将文档发送到客户端(Excel 2010)时,它突出显示空单元格.我已经尝试清除条件格式并使用内置条件格式的Excel,它完全相同.
詹姆斯,先谢谢你.