当前位置: 首页>>代码示例>>C#>>正文


C# Mock.Visit方法代码示例

本文整理汇总了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);
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:12,代码来源:MemberReferenceCollectorTest.cs

示例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);
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:16,代码来源:ReferenceCollectorTest.cs

示例3: VisitThrowsOnNullResults

 public void VisitThrowsOnNullResults()
 {
     ParserVisitor target = new Mock<ParserVisitor>().Object;
     Assert.Throws<ArgumentNullException>("result", () => target.Visit(null));
 }
开发者ID:hamaky,项目名称:Razor,代码行数:5,代码来源:ParserVisitorExtensionsTest.cs

示例4: VisitThrowsOnNullResults

 public void VisitThrowsOnNullResults()
 {
     ParserVisitor target = new Mock<ParserVisitor>().Object;
     Assert.ThrowsArgumentNull(() => target.Visit(null), "result");
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:5,代码来源:ParserVisitorExtensionsTest.cs

示例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()));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:19,代码来源:ReferenceCollectorTest.cs

示例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()));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:23,代码来源:ReferenceCollectorTest.cs

示例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);
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:12,代码来源:ReferenceCollectorTest.cs

示例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()));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:18,代码来源:ReferenceCollectorTest.cs

示例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()));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:24,代码来源:MemberReferenceCollectorTest.cs

示例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()));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:18,代码来源:MemberReferenceCollectorTest.cs


注:本文中的Mock.Visit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。