public void AcceptCallsTheCorrectVisitorMethodAndReturnsTheCorrectInstance() { // Fixture setup var expected = new DelegatingReflectionVisitor<int>(); var sut = new MethodInfoElement(TypeWithMethods.Method); var visitor = new DelegatingReflectionVisitor<int> { OnVisitMethodInfoElement = e => e == sut ? expected : new DelegatingReflectionVisitor<int>() }; // Exercise system var actual = sut.Accept(visitor); // Verify outcome Assert.Same(expected, actual); // Teardown }
public void VisitConstructorInfoElementCollectsCorrectAssembliesForMethodBody() { var visitor = new DelegatingReflectionVisitor<IEnumerable<Assembly>>(); var sut = new Mock<ReferenceCollector> { CallBase = true }.Object; sut.ToMock().Setup(x => x.Visit(It.IsAny<ParameterInfoElement>())).Returns(visitor); sut.ToMock().Setup(x => x.Visit(It.IsAny<LocalVariableInfoElement>())).Returns(visitor); var expected = new[] { typeof(IDisposable).Assembly, GetType().Assembly, typeof(Fixture).Assembly }; var constructorInfoElement = Constructors.Select(() => new ClassForCollectingReference(0)).ToElement(); var actual = sut.Visit(constructorInfoElement); Assert.Equal(visitor, actual); Assert.Equal(expected.OrderBy(x => x.ToString()), sut.Value.OrderBy(x => x.ToString())); }
public void VisitPropertyInfoElementsCallsBaseMethod() { var sut = new Mock<ReferenceCollector> { CallBase = true }.Object; var visitor = new DelegatingReflectionVisitor<IEnumerable<Assembly>>(); sut.ToMock().Setup(x => x.Visit(It.IsAny<PropertyInfoElement>())).Returns(visitor); var propertyInfoElements = typeof(ClassWithMembers).GetProperties(Bindings) .Select(x => x.ToElement()).ToArray(); var actual = sut.Visit(propertyInfoElements); Assert.Equal(visitor, actual); }
public void VisitTypeElementCollectsCorrectAssemblies() { var type = typeof(List<ClassImplementingHierarchical>); var expected = new[] { typeof(ClassImplementingMultiple).Assembly, typeof(IDisposable).Assembly, typeof(IReflectionElement).Assembly, typeof(Fixture).Assembly }; var visitor = new DelegatingReflectionVisitor<IEnumerable<Assembly>>(); var sut = new Mock<ReferenceCollector> { CallBase = true }.Object; sut.ToMock().Setup(x => x.Visit(It.IsAny<FieldInfoElement>())).Returns(visitor); sut.ToMock().Setup(x => x.Visit(It.IsAny<ConstructorInfoElement>())).Returns(visitor); sut.ToMock().Setup(x => x.Visit(It.IsAny<PropertyInfoElement>())).Returns(visitor); sut.ToMock().Setup(x => x.Visit(It.IsAny<MethodInfoElement>())).Returns(visitor); sut.ToMock().Setup(x => x.Visit(It.IsAny<EventInfoElement>())).Returns(visitor); var actual = sut.Visit(type.ToElement()); Assert.Equal(visitor, actual); Assert.Equal(expected.OrderBy(x => x.ToString()), sut.Value.OrderBy(x => x.ToString())); }
public void VisitMethodInfoElementCollectsCorrectAssembliesForMethodCallInMethodBody() { var visitor = new DelegatingReflectionVisitor<IEnumerable<Assembly>>(); var sut = new Mock<ReferenceCollector> { CallBase = true }.Object; sut.ToMock().Setup(x => x.Visit(It.IsAny<ParameterInfoElement>())).Returns(visitor); sut.ToMock().Setup(x => x.Visit(It.IsAny<LocalVariableInfoElement>())).Returns(visitor); var expected = new[] { typeof(IDisposable).Assembly, typeof(Enumerable).Assembly }; var methodInfoElement = new Methods<ClassForCollectingReference>() .Select(x => x.MethodCallInMethodBody()).ToElement(); sut.Visit(methodInfoElement); Assert.Equal(expected.OrderBy(x => x.ToString()), sut.Value.OrderBy(x => x.ToString())); }