ienumerable 에 mbunit에 클래스 Someclass의 모든 항목이 있음을 어떻게 테스트합니까?

StackOverflow https://stackoverflow.com/questions/1082224

  •  22-08-2019
  •  | 
  •  

문제

ienumerable이 mbunit에 클래스 Someclass의 모든 항목을 가지고 있음을 어떻게 테스트합니까?

한 번도 Visual Studio Unit Test Framework를 사용하여 찾았습니다. CollectionAssert.AllAreInstancesOfType 또는 그것을 확인해야 할 것.

그러나 mbunit에서 어떻게해야합니까?

도움이 되었습니까?

해결책

나는 mbunit에서 아무것도 보지 못했습니다 CollectionAssert 여기서 당신을 도울 수있는 수업

당신은 자신의 것을 쉽게 쓸 수 있습니다 (테스트되지 않은).

public class MyCollectionAssert
{
  public void CollectionAssert(IEnumerable source, Predicate<object> assertion)
  {
    foreach(var item in source)
    {
       Assert.IsTrue(assertion(item));
    }
  }

  public void AllAreInstancesOfType(IEnumerable source, Type type)
  {
    return CollectionAssert(source, o => o.GetType() == type);
  }
}

나는 당신이 실제로 ienumerable을 의미한다고 생각합니다 IEnumerable<SomeClass> 컴파일러가 유형 안전을 시행합니다. 이 확장 방법을 사용하려면 다음과 같이 호출합니다.

MyCollectionAssert.AllAreInstancesOfType(myList, typeof(SomeClass));

다른 팁

제프 브라운, Gallio 프로젝트의 수석 개발자가 문제 그 요청을 위해. 우리는 몇 가지 전담 주장을 구현할 것입니다. Assert.ForAll 그리고 Assert.Exists. 다음은 Gallio/Mbunit (v3.1)의 다음 릴리스에서 사용할 수 있어야하지만 며칠 안에 매일 빌드를 다운로드하여 더 빨리 사용할 수 있습니다 (계속 지켜봐야합니다).

편집하다:시작 Gallio/Mbunit v3.1.213, 당신이 사용할 수있는 Assert.ForAll<T>(IEnumerable<T>, Predicate<T>).

[Test]
public void AllMyObjectsShouldBeStrings()
{
  var list = GetThemAll();
  Assert.ForAll(list, x => x.GetType() == typeof(string));
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top