代码之家  ›  专栏  ›  技术社区  ›  Humberto

创建nunit约束意味着“集合不包含项”

  •  29
  • Humberto  · 技术社区  · 15 年前

    我正在努力断言枚举中没有某个特定项。具体来说,我的测试是这样的:

    // Take an item from a queue of scheduled items...
    ItemQueue pendingQueue = schedule.PendingItems; // PendingItems is an IEnumerable<int>
    int item = pendingQueue.FirstItem;
    
    // ...process the item...
    processor.DoSomethingWith(item);
    
    // ...and the schedule must not contain the item anymore:
    Assert.That(schedule.PendingItems, Does.Not.Contain(item));
    

    当然, 不包含 不是有效的nunit约束。如何用有效的流利语法来表达它?

    3 回复  |  直到 7 年前
        1
  •  47
  •   Jeff B    11 年前
    Assert.That(schedule.PendingItems, Has.No.Member(item))
    

    仅适用于Nunit 2.4/2.5

        2
  •  11
  •   Rok StrniÅ¡a    7 年前

    使用 CollectionAssert 方法:

    CollectionAssert.DoesNotContain(schedule.PendingItems, item);
    
        3
  •  5
  •   Darin Dimitrov    15 年前

    如果您使用的是Nunit 2.4/2.5,您可以在 collection constraints