本文整理汇总了C#中Mock.Visit方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.Visit方法的具体用法?C# Mock.Visit怎么用?C# Mock.Visit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.Visit方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitLocalVariableInfoElementsReturnsItself
public void VisitLocalVariableInfoElementsReturnsItself()
{
var sut = new Mock<MemberReferenceCollector> { CallBase = true }.Object;
sut.ToMock().Setup(x => x.Visit(It.IsAny<LocalVariableInfoElement>())).Throws<InvalidOperationException>();
var localVariableInfoElement = new Methods<ClassForCollectingReference>()
.Select(x => x.ReturnMethod()).GetMethodBody()
.LocalVariables.First().ToElement();
var actual = sut.Visit(new[] { localVariableInfoElement });
Assert.Same(sut, actual);
}
示例2: VisitAssemblyElementCallsBaseMethod
public void VisitAssemblyElementCallsBaseMethod()
{
var assembly = new DelegatingAssembly
{
OnGetTypes = () => new[] { typeof(object), typeof(int) }
};
var sut = new Mock<ReferenceCollector> { CallBase = true }.Object;
var visitor1 = new Mock<ReferenceCollector>().Object;
var visitor2 = new Mock<ReferenceCollector>().Object;
sut.ToMock().Setup(x => x.Visit(typeof(object).ToElement())).Returns(visitor1);
visitor1.ToMock().Setup(x => x.Visit(typeof(int).ToElement())).Returns(visitor2);
var actual = sut.Visit(assembly.ToElement());
Assert.Equal(visitor2, actual);
}
示例3: VisitThrowsOnNullResults
public void VisitThrowsOnNullResults()
{
ParserVisitor target = new Mock<ParserVisitor>().Object;
Assert.Throws<ArgumentNullException>("result", () => target.Visit(null));
}
示例4: VisitThrowsOnNullResults
public void VisitThrowsOnNullResults()
{
ParserVisitor target = new Mock<ParserVisitor>().Object;
Assert.ThrowsArgumentNull(() => target.Visit(null), "result");
}
示例5: VisitConstructorInfoElementCollectsCorrectAssembliesForMethodBody
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()));
}
示例6: VisitTypeElementCollectsCorrectAssemblies
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()));
}
示例7: VisitPropertyInfoElementsCallsBaseMethod
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);
}
示例8: VisitMethodInfoElementCollectsCorrectAssembliesForMethodCallInMethodBody
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()));
}
示例9: VisitMethodInfoElementCollectsAssembliesFromBaseMethod
public void VisitMethodInfoElementCollectsAssembliesFromBaseMethod()
{
var references = new[] { typeof(ISet<>).Assembly };
var sut = new Mock<MemberReferenceCollector> { CallBase = true }.Object;
sut.ToMock().Setup(x => x.Visit(It.IsAny<ParameterInfoElement[]>())).Returns(sut);
sut.ToMock().Setup(x => x.Visit(It.IsAny<LocalVariableInfoElement[]>()))
.Returns(new MemberReferenceCollector(references));
var expected = new[]
{
typeof(ClassImplementingMultiple).Assembly,
typeof(IDisposable).Assembly,
typeof(ISpecimenContext).Assembly,
references[0]
};
var dummyMethodInfoElement = new Methods<ClassForCollectingReference>()
.Select(x => x.ReturnMethod()).ToElement();
var actual = sut.Visit(dummyMethodInfoElement);
sut.ToMock().VerifyAll();
Assert.Equal(
expected.OrderBy(x => x.ToString()),
actual.Value.OrderBy(x => x.ToString()));
}
示例10: VisitTypeElementCollectsCorrectAssemblies
public void VisitTypeElementCollectsCorrectAssemblies(
Type type, Assembly[] expected)
{
var refereces = new[] { typeof(ISet<>).Assembly };
var sut = new Mock<MemberReferenceCollector>(new object[] { refereces }) { CallBase = true }.Object;
sut.ToMock().Setup(x => x.Visit(It.IsAny<FieldInfoElement>())).Throws<InvalidOperationException>();
sut.ToMock().Setup(x => x.Visit(It.IsAny<ConstructorInfoElement>())).Throws<InvalidOperationException>();
sut.ToMock().Setup(x => x.Visit(It.IsAny<PropertyInfoElement>())).Throws<InvalidOperationException>();
sut.ToMock().Setup(x => x.Visit(It.IsAny<MethodInfoElement>())).Throws<InvalidOperationException>();
sut.ToMock().Setup(x => x.Visit(It.IsAny<EventInfoElement>())).Throws<InvalidOperationException>();
var actual = sut.Visit(type.ToElement());
Assert.NotSame(sut, actual);
Assert.Equal(
refereces.Concat(expected).OrderBy(x => x.ToString()),
actual.Value.OrderBy(x => x.ToString()));
}