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


C# Mock.ToMock方法代码示例

本文整理汇总了C#中Mock.ToMock方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.ToMock方法的具体用法?C# Mock.ToMock怎么用?C# Mock.ToMock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.ToMock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VerifyGetSetPropertyCallsVerifyGetMethodAndSetMethod

        public void VerifyGetSetPropertyCallsVerifyGetMethodAndSetMethod()
        {
            var sut = new Mock<ObjectDisposalAssertion>(new Fixture()) { CallBase = true }.Object;
            var property = new Properties<ClassWithMembers>().Select(x => x.PublicProperty);
            sut.ToMock().Setup(x => x.Verify(It.IsAny<MethodInfo>()));

            sut.Verify(property);

            sut.ToMock().Verify(x => x.Verify(property.GetGetMethod()));
            sut.ToMock().Verify(x => x.Verify(property.GetSetMethod()));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:11,代码来源:ObjectDisposalAssertionTest.cs

示例2: VerifyEventMemberCallsVerifyEvent

        public void VerifyEventMemberCallsVerifyEvent()
        {
            var sut = new Mock<IdiomaticAssertion> { CallBase = true }.Object;
            var @event = typeof(ClassWithMembers).GetEvents().First();

            sut.Verify((MemberInfo)@event);

            sut.ToMock().Verify(x => x.Verify(@event));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:9,代码来源:IdiomaticAssertionTest.cs

示例3: VerifyFieldMemberCallsVerifyField

        public void VerifyFieldMemberCallsVerifyField()
        {
            var sut = new Mock<IdiomaticAssertion> { CallBase = true }.Object;
            var field = new Fields<ClassWithMembers>().Select(x => x.PublicField);

            sut.Verify((MemberInfo)field);

            sut.ToMock().Verify(x => x.Verify(field));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:9,代码来源:IdiomaticAssertionTest.cs

示例4: VerifyMethodMemberCallsVerifyMethod

        public void VerifyMethodMemberCallsVerifyMethod()
        {
            var sut = new Mock<IdiomaticAssertion> { CallBase = true }.Object;
            var method = new Methods<ClassWithMembers>().Select(x => x.PublicMethod());

            sut.Verify((MemberInfo)method);

            sut.ToMock().Verify(x => x.Verify(method));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:9,代码来源:IdiomaticAssertionTest.cs

示例5: VerifyConstructorMemberCallsVerifyConstructor

        public void VerifyConstructorMemberCallsVerifyConstructor()
        {
            var sut = new Mock<IdiomaticAssertion> { CallBase = true }.Object;
            var constructor = Constructors.Select(() => new ClassWithMembers());

            sut.Verify((MemberInfo)constructor);

            sut.ToMock().Verify(x => x.Verify(constructor));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:9,代码来源:IdiomaticAssertionTest.cs

示例6: 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

示例7: 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

示例8: VerifyAssemblyCorrectlyVerifies

        public void VerifyAssemblyCorrectlyVerifies()
        {
            var sut = new Mock<IdiomaticAssertion> { CallBase = true }.Object;
            var types = new List<MemberInfo>();
            sut.ToMock().Setup(x => x.Verify(It.IsAny<Type>())).Callback<Type>(types.Add);
            var assembly = typeof(TestBaseAttribute).Assembly;
            var expected = assembly.GetExportedTypes();

            sut.Verify(assembly);

            Assert.Equal(expected, types);
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:12,代码来源:IdiomaticAssertionTest.cs

示例9: 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

示例10: VerifyTypeCorrectlyVerifies

        public void VerifyTypeCorrectlyVerifies()
        {
            // Fixture setup
            var arguments = new object[] { new Assembly[0] };
            var sut = new Mock<NotExposedReferenceAssertion>(arguments) { CallBase = true }.Object;

            var members = new List<MemberInfo>();
            sut.ToMock().Setup(x => x.Verify(It.IsAny<MemberInfo>())).Callback<MemberInfo>(members.Add);

            var type = typeof(ClassWithMembers);
            var expected = type.GetIdiomaticMembers();

            // Exercise system
            sut.Verify(type);

            // Verify outcome
            Assert.Equal(expected.OrderBy(m => m.Name), members.OrderBy(m => m.Name));
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:18,代码来源:NotExposedReferenceAssertionTest.cs

示例11: VerifyAssemblyCorrectlyVerifies

        public void VerifyAssemblyCorrectlyVerifies()
        {
            // Fixture setup
            var arguments = new object[] { new Assembly[0] };
            var sut = new Mock<NotExposedReferenceAssertion>(arguments) { CallBase = true }.Object;
            
            var types = new List<Type>();
            sut.ToMock().Setup(x => x.Verify(It.IsAny<Type>())).Callback<Type>(types.Add);

            var assembly = typeof(object).Assembly;
            var expected = assembly.GetTypes().ToArray();

            // Exercise system
            sut.Verify(assembly);

            // Verify outcome
            Assert.Equal(expected, types);
        }
开发者ID:jwChung,项目名称:Experimentalism,代码行数:18,代码来源:NotExposedReferenceAssertionTest.cs

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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