本文整理汇总了C#中Mock.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.Select方法的具体用法?C# Mock.Select怎么用?C# Mock.Select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.Select方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateWebHookFilterManager
internal static IWebHookFilterManager CreateWebHookFilterManager(int providerCount)
{
Mock<IWebHookFilterProvider>[] providerMocks = new Mock<IWebHookFilterProvider>[providerCount];
for (int cnt = 0; cnt < providerMocks.Length; cnt++)
{
providerMocks[cnt] = CreateFilterProvider(cnt);
}
WebHookFilterManager manager = new WebHookFilterManager(providerMocks.Select(p => p.Object));
return manager;
}
示例2: ThrowWhenNullIndexOutOfBounds
internal void ThrowWhenNullIndexOutOfBounds(
Mock<ParameterInfo>[] parameterMocks,
SpecimenProvider sut)
{
// Arrange
List<ParameterInfo> parameters = parameterMocks.Select(pm => pm.Object).ToList();
// Act/Assert
string actualParamName =
Assert.Throws<ArgumentException>(
() => ((ISpecimenProvider)sut).GetParameterSpecimens(parameters, parameters.Count))
.ParamName;
Assert.Equal("nullIndex", actualParamName);
}
示例3: CreateControllerWillReturnFirstControllerResultFromFactories
public void CreateControllerWillReturnFirstControllerResultFromFactories(
string controllerName,
RequestContext requestContext,
IController expectedResult,
Mock<IControllerFactory>[] factoryStubs)
{
// Fixture Setup
factoryStubs[0]
.Setup(x => x.CreateController(requestContext, controllerName))
.Returns((IController)null);
factoryStubs[1]
.Setup(x => x.CreateController(requestContext, controllerName))
.Returns(expectedResult);
factoryStubs[2]
.Setup(x => x.CreateController(requestContext, controllerName))
.Returns((IController)null);
var sut = new CompositeControllerFactory(factoryStubs.Select(x => x.Object));
// Exercise system
var result = sut.CreateController(requestContext, controllerName);
// Verify outcome
Assert.Equal(expectedResult, result);
// Teardown
}
开发者ID:moodmosaic-attic,项目名称:System.Web.Mvc.Composition,代码行数:24,代码来源:CompositeControllerFactoryFacts.cs
示例4: CreateTargetsFromParameters
protected override ITarget[] CreateTargetsFromParameters(MethodInfo method)
{
TargetMocks = method.GetParameters().Select(p => new Mock<ITarget>()).ToArray();
return TargetMocks.Select(m => m.Object).ToArray();
}
示例5: DefaultHttpControllerTypeResolverTracerTest
public DefaultHttpControllerTypeResolverTracerTest()
{
ExpectedTypes = new List<Type>
{
typeof(ValidController), typeof(UsersRpcController), typeof(UsersController),
};
Type[] fine1Types = new Type[]
{
typeof(DefaultHttpControllerTypeResolverTracerTest),
null,
typeof(ValidController),
};
Type[] poorTypes = new Type[]
{
typeof(string),
null,
typeof(Action),
null,
typeof(UsersRpcController),
};
Type[] fine2Types = new Type[]
{
typeof(DefaultHttpControllerTypeResolver),
null,
typeof(DefaultHttpControllerTypeResolverTracer),
null,
typeof(UsersController)
};
Exception worseException = new Exception(ExceptionMessage);
Exception poorException = new ReflectionTypeLoadException(poorTypes, new Exception[] { worseException });
ExpectedTraces = new List<TraceRecord>
{
new TraceRecord(null, TraceCategories.ControllersCategory, TraceLevel.Debug)
{
Kind = TraceKind.Begin,
Operator = "DefaultHttpControllerTypeResolverProxy", // Moq type name
Operation = "GetControllerTypes",
},
new TraceRecord(null, TraceCategories.ControllersCategory, TraceLevel.Warn)
{
Kind = TraceKind.Trace,
Exception = poorException,
Message = "Exception thrown while getting types from 'PoorAssembly'.",
},
new TraceRecord(null, TraceCategories.ControllersCategory, TraceLevel.Warn)
{
Kind = TraceKind.Trace,
Exception = worseException,
Message = "Exception thrown while getting types from 'WorseAssembly'.",
},
new TraceRecord(null, TraceCategories.ControllersCategory, TraceLevel.Debug)
{
Kind = TraceKind.End,
Operator = "DefaultHttpControllerTypeResolverProxy",
Operation = "GetControllerTypes",
},
};
Mock<MockableAssembly> fine1Assembly = new Mock<MockableAssembly>(MockBehavior.Strict);
fine1Assembly.Setup(assembly => assembly.GetTypes()).Returns(fine1Types);
fine1Assembly.SetupGet(assembly => assembly.IsDynamic).Returns(false);
Exception[] exceptions = new Exception[] { new Exception(ExceptionMessage), };
Mock<MockableAssembly> poorAssembly = new Mock<MockableAssembly>(MockBehavior.Strict);
poorAssembly.Setup(assembly => assembly.GetTypes()).Throws(poorException);
poorAssembly.SetupGet(assembly => assembly.IsDynamic).Returns(false);
poorAssembly.SetupGet(assembly => assembly.FullName).Returns("PoorAssembly");
Mock<MockableAssembly> worseAssembly = new Mock<MockableAssembly>(MockBehavior.Strict);
worseAssembly.Setup(assembly => assembly.GetTypes()).Throws(worseException);
worseAssembly.SetupGet(assembly => assembly.IsDynamic).Returns(false);
worseAssembly.SetupGet(assembly => assembly.FullName).Returns("WorseAssembly");
Mock<MockableAssembly> fine2Assembly = new Mock<MockableAssembly>(MockBehavior.Strict);
fine2Assembly.Setup(assembly => assembly.GetTypes()).Returns(fine2Types);
fine2Assembly.SetupGet(assembly => assembly.IsDynamic).Returns(false);
Mock<MockableAssembly> dynamicAssembly = new Mock<MockableAssembly>(MockBehavior.Strict);
dynamicAssembly.SetupGet(assembly => assembly.IsDynamic).Returns(true);
Assemblies = new Mock<MockableAssembly>[]
{
fine1Assembly,
poorAssembly,
worseAssembly,
fine2Assembly,
dynamicAssembly,
};
AssembliesResolver = new Mock<IAssembliesResolver>(MockBehavior.Strict);
AssembliesResolver.Setup(resolver => resolver.GetAssemblies()).Returns(
Assemblies.Select(assembly => (Assembly)assembly.Object).AsCollection());
HttpControllerTypeResolver =
new Mock<DefaultHttpControllerTypeResolver>() { CallBase = true, };
}
示例6: InitMocks
private void InitMocks(int numArrayElements)
{
mockBindingsFactory = new Mock<IBindingsFactory>();
testArray = Enumerable.Range(0, numArrayElements)
.Select(i => new TestClass())
.ToArray();
mockArrayItemBindings = Enumerable.Range(0, numArrayElements)
.Select(i =>
{
var mockBinding = new Mock<IArrayItemBinding>();
mockBinding
.Setup(m => m.ItemIndex)
.Returns(i);
return mockBinding;
})
.ToArray();
mockBindingsFactory
.Setup(m => m.CreateArrayBindings(testArray))
.Returns(mockArrayItemBindings.Select(m => m.Object).ToArray());
}
示例7: SetupGetAllDevices
public void SetupGetAllDevices(Mock<ITelldusDevice>[] telldusDevices)
{
TelldusCoreMock.Setup(m => m.GetAllDevices()).Returns(telldusDevices.Select(d => d.Object).ToArray());
}