ATPKING文章...

今天在做小项目的时候,有个需求,是比较List 中的对象是否存在过

而比较的对象是通过新建得来的(反序列化)

正当我使用Contains做比较的时候,

就发现问题了.

以下是测试代码

[TestMethod()]
public void RemoveDiscendantPowerTest() {
    Power Parent = new Power
    {
        Alias = "testRoot",
        CanDelete = false,
        Description = "测试根目录",
        id = 100,
        PowerName = "测试根目录",
        Childs = new List<Power>
        {
            new Power{
                Alias = "testBranch1",
                CanDelete = true,
                Description = "枝干节点1",
                id = 100100,
                PowerName = "枝干节点1",
                Childs = new List<Power>{
                    new Power{
                     Alias = "leaf1",
                     CanDelete = true,
                     Description = "叶子节点1",
                     id = 100100100,
                     PowerName = "叶子节点1"
                    },
                    new Power{
                     Alias = "leaf2",
                     CanDelete = true,
                     Description = "叶子节点2",
                     id = 100100101,
                     PowerName = "叶子节点2"
                    }
                }
            },
            new Power{
                Alias ="testBranch2",
                CanDelete = true,
                Description = "枝干节点2",
                id = 100101,
                PowerName = "枝干接点2",
                Childs = new List<Power>{
                    new Power{
                     Alias = "leaf3",
                     CanDelete = true,
                     Description = "叶子节点3",
                     id = 100101100,
                     PowerName = "叶子节点3"
                    },
                    new Power{
                     Alias = "leaf4",
                     CanDelete = true,
                     Description = "叶子节点4",
                     id = 100101101,
                     PowerName = "叶子节点4"
                    }
                }
                
            }
        }
    }; // TODO: 初始化为适当的值
    Power Discendant = new Power{
                     Alias = "leaf4",
                     CanDelete = true,
                     Description = "叶子节点4",
                     id = 100101101,
                     PowerName = "叶子节点4"
                    };
    // TODO: 初始化为适当的值
 
 
    Assert.IsTrue(Parent.Childs[1].Childs.Contains(Discendant), "测试失败,Contains 不能抓出");
 
 
 
 
}

相关文章:

  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2021-09-14
  • 2021-10-13
猜你喜欢
  • 2021-12-19
  • 2022-01-17
  • 2022-01-15
  • 2022-01-12
  • 2021-12-21
相关资源
相似解决方案