public void EnumerateAssemblyShouldHandleExceptionsWhileEnumeratingAType() { var mockAssembly = CreateMockTestableAssembly(); var testableAssemblyEnumerator = new TestableAssemblyEnumerator(); var exception = new Exception("TypeEnumerationException"); // Setup mocks mockAssembly.Setup(a => a.DefinedTypes) .Returns(new List <TypeInfo>() { typeof(InternalTestClass).GetTypeInfo() }); this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("DummyAssembly", false)) .Returns(mockAssembly.Object); testableAssemblyEnumerator.MockTypeEnumerator.Setup(te => te.Enumerate(out this.warnings)).Throws(exception); testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings); CollectionAssert.Contains( this.warnings.ToList(), string.Format( CultureInfo.CurrentCulture, Resource.CouldNotInspectTypeDuringDiscovery, typeof(InternalTestClass), "DummyAssembly", exception.Message)); }
public void EnumerateAssemblyShouldLoadExeContainersInReflectionOnlyContext() { var mockAssembly = CreateMockTestableAssembly(); var testableAssemblyEnumerator = new TestableAssemblyEnumerator(); var unitTestElement = new UnitTestElement(new TestMethod("DummyMethod", "DummyClass", "DummyAssembly", false)); // Setup mocks mockAssembly.Setup(a => a.DefinedTypes) .Returns(new List <TypeInfo>() { typeof(DummyTestClass).GetTypeInfo() }); this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("DummyAssembly.exe", true)) .Returns(mockAssembly.Object); testableAssemblyEnumerator.MockTypeEnumerator.Setup(te => te.Enumerate(out this.warnings)) .Returns(new Collection <UnitTestElement> { unitTestElement }); var testElements = testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly.exe", out this.warnings); CollectionAssert.AreEqual(new Collection <UnitTestElement> { unitTestElement }, testElements.ToList()); }
public void EnumerateAssemblyShouldReturnMoreThanOneTestElementForMoreThanOneType() { var mockAssembly = CreateMockTestableAssembly(); var testableAssemblyEnumerator = new TestableAssemblyEnumerator(); var unitTestElement = new UnitTestElement(new TestMethod("DummyMethod", "DummyClass", "DummyAssembly", false)); var expectedTestElements = new Collection <UnitTestElement> { unitTestElement, unitTestElement }; // Setup mocks mockAssembly.Setup(a => a.DefinedTypes) .Returns(new List <TypeInfo>() { typeof(DummyTestClass).GetTypeInfo(), typeof(DummyTestClass).GetTypeInfo() }); this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("DummyAssembly", false)) .Returns(mockAssembly.Object); testableAssemblyEnumerator.MockTypeEnumerator.Setup(te => te.Enumerate(out this.warnings)) .Returns(expectedTestElements); var testElements = testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings); expectedTestElements.Add(unitTestElement); expectedTestElements.Add(unitTestElement); CollectionAssert.AreEqual(expectedTestElements, testElements.ToList()); }
public void EnumerateAssemblyShouldReturnEmptyListWhenNoTestElementsInAType() { var mockAssembly = CreateMockTestableAssembly(); var testableAssemblyEnumerator = new TestableAssemblyEnumerator(); // Setup mocks mockAssembly.Setup(a => a.DefinedTypes) .Returns(new List <TypeInfo>() { typeof(DummyTestClass).GetTypeInfo() }); this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("DummyAssembly", false)) .Returns(mockAssembly.Object); testableAssemblyEnumerator.MockTypeEnumerator.Setup(te => te.Enumerate(out this.warnings)) .Returns((ICollection <UnitTestElement>)null); Assert.AreEqual(0, this.assemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings).Count); }
public void EnumerateAssemblyShouldNotLogWarningsIfNonePresent() { var mockAssembly = CreateMockTestableAssembly(); var testableAssemblyEnumerator = new TestableAssemblyEnumerator(); ICollection <string> warningsFromTypeEnumerator = null; // Setup mocks mockAssembly.Setup(a => a.DefinedTypes) .Returns(new List <TypeInfo>() { typeof(InternalTestClass).GetTypeInfo() }); this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("DummyAssembly", false)) .Returns(mockAssembly.Object); testableAssemblyEnumerator.MockTypeEnumerator.Setup(te => te.Enumerate(out warningsFromTypeEnumerator)); testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings); Assert.AreEqual(0, this.warnings.Count); }