How to use CreateClassProxyType method of Telerik.JustMock.Core.Castle.DynamicProxy.DefaultProxyBuilder class

Best JustMockLite code snippet using Telerik.JustMock.Core.Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxyType

ProxyGenerator.cs

Source:ProxyGenerator.cs Github

copy

Full Screen

...1112 throw new ArgumentException("'classToProxy' must be a class", "classToProxy");1113 }1114 CheckNotGenericTypeDefinition(classToProxy, "classToProxy");1115 CheckNotGenericTypeDefinitions(additionalInterfacesToProxy, "additionalInterfacesToProxy");1116 var proxyType = CreateClassProxyTypeWithTarget(classToProxy, additionalInterfacesToProxy, options);1117 // create constructor arguments (initialized with mixin implementations, interceptors and target type constructor arguments)1118 var arguments = BuildArgumentListForClassProxyWithTarget(target, options, interceptors);1119 if (constructorArguments != null && constructorArguments.Length != 0)1120 {1121 arguments.AddRange(constructorArguments);1122 }1123 return CreateClassProxyInstance(proxyType, arguments, classToProxy, constructorArguments);1124 }1125 /// <summary>1126 /// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref1127 /// name = "interceptors" />.1128 /// </summary>1129 /// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>1130 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1131 /// <returns>1132 /// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref1133 /// name = "TClass" /> type.1134 /// </returns>1135 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>1136 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <typeparamref name = "TClass" />.</exception>1137 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>1138 /// <remarks>1139 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1140 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1141 /// </remarks>1142 public TClass CreateClassProxy<TClass>(params IInterceptor[] interceptors) where TClass : class1143 {1144 return (TClass)CreateClassProxy(typeof(TClass), ProxyGenerationOptions.Default, interceptors);1145 }1146 /// <summary>1147 /// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref1148 /// name = "interceptors" />.1149 /// </summary>1150 /// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>1151 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1152 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1153 /// <returns>1154 /// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref1155 /// name = "TClass" /> type.1156 /// </returns>1157 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>1158 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <typeparamref name = "TClass" />.</exception>1159 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>1160 /// <remarks>1161 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1162 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1163 /// </remarks>1164 public TClass CreateClassProxy<TClass>(ProxyGenerationOptions options, params IInterceptor[] interceptors)1165 where TClass : class1166 {1167 return (TClass)CreateClassProxy(typeof(TClass), options, interceptors);1168 }1169 /// <summary>1170 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1171 /// name = "interceptors" />.1172 /// </summary>1173 /// <param name = "classToProxy">Type of class which will be proxied.</param>1174 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>1175 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1176 /// <returns>1177 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1178 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.1179 /// </returns>1180 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1181 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref1182 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>1183 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1184 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>1185 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1186 /// <remarks>1187 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1188 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1189 /// </remarks>1190 public object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy,1191 params IInterceptor[] interceptors)1192 {1193 return CreateClassProxy(classToProxy, additionalInterfacesToProxy, ProxyGenerationOptions.Default, interceptors);1194 }1195 /// <summary>1196 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1197 /// name = "interceptors" />.1198 /// </summary>1199 /// <param name = "classToProxy">Type of class which will be proxied.</param>1200 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1201 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>1202 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1203 /// <returns>1204 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1205 /// name = "classToProxy" /> type.1206 /// </returns>1207 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1208 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>1209 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1210 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref1211 /// name = "constructorArguments" />.</exception>1212 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1213 /// <remarks>1214 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1215 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1216 /// </remarks>1217 public object CreateClassProxy(Type classToProxy, ProxyGenerationOptions options, object[] constructorArguments,1218 params IInterceptor[] interceptors)1219 {1220 return CreateClassProxy(classToProxy, null, options, constructorArguments, interceptors);1221 }1222 /// <summary>1223 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1224 /// name = "interceptors" />.1225 /// </summary>1226 /// <param name = "classToProxy">Type of class which will be proxied.</param>1227 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>1228 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1229 /// <returns>1230 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1231 /// name = "classToProxy" /> type.1232 /// </returns>1233 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1234 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>1235 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1236 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref1237 /// name = "constructorArguments" />.</exception>1238 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1239 /// <remarks>1240 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1241 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1242 /// </remarks>1243 public object CreateClassProxy(Type classToProxy, object[] constructorArguments, params IInterceptor[] interceptors)1244 {1245 return CreateClassProxy(classToProxy, null, ProxyGenerationOptions.Default, constructorArguments, interceptors);1246 }1247 /// <summary>1248 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1249 /// name = "interceptors" />.1250 /// </summary>1251 /// <param name = "classToProxy">Type of class which will be proxied.</param>1252 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1253 /// <returns>1254 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1255 /// name = "classToProxy" /> type.1256 /// </returns>1257 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1258 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>1259 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1260 /// <exception cref = "ArgumentException">Thrown when no parameterless constructor exists on type <paramref1261 /// name = "classToProxy" />.</exception>1262 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1263 /// <remarks>1264 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1265 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1266 /// </remarks>1267 public object CreateClassProxy(Type classToProxy, params IInterceptor[] interceptors)1268 {1269 return CreateClassProxy(classToProxy, null, ProxyGenerationOptions.Default,1270 null, interceptors);1271 }1272 /// <summary>1273 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1274 /// name = "interceptors" />.1275 /// </summary>1276 /// <param name = "classToProxy">Type of class which will be proxied.</param>1277 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1278 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1279 /// <returns>1280 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1281 /// name = "classToProxy" /> type.1282 /// </returns>1283 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1284 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>1285 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>1286 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1287 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>1288 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1289 /// <remarks>1290 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1291 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1292 /// </remarks>1293 public object CreateClassProxy(Type classToProxy, ProxyGenerationOptions options, params IInterceptor[] interceptors)1294 {1295 return CreateClassProxy(classToProxy, null, options, interceptors);1296 }1297 /// <summary>1298 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1299 /// name = "interceptors" />.1300 /// </summary>1301 /// <param name = "classToProxy">Type of class which will be proxied.</param>1302 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>1303 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1304 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1305 /// <returns>1306 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1307 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.1308 /// </returns>1309 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1310 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>1311 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref1312 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>1313 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1314 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>1315 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1316 /// <remarks>1317 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1318 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1319 /// </remarks>1320 public object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options,1321 params IInterceptor[] interceptors)1322 {1323 return CreateClassProxy(classToProxy, additionalInterfacesToProxy, options, null, interceptors);1324 }1325 /// <summary>1326 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1327 /// name = "interceptors" />.1328 /// </summary>1329 /// <param name = "classToProxy">Type of class which will be proxied.</param>1330 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>1331 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1332 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>1333 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1334 /// <returns>1335 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1336 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.1337 /// </returns>1338 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1339 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>1340 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref1341 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>1342 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1343 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref1344 /// name = "constructorArguments" />.</exception>1345 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1346 /// <remarks>1347 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1348 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1349 /// </remarks>1350 public virtual object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy,1351 ProxyGenerationOptions options,1352 object[] constructorArguments, params IInterceptor[] interceptors)1353 {1354 if (classToProxy == null)1355 {1356 throw new ArgumentNullException("classToProxy");1357 }1358 if (options == null)1359 {1360 throw new ArgumentNullException("options");1361 }1362 if (!classToProxy.GetTypeInfo().IsClass)1363 {1364 throw new ArgumentException("'classToProxy' must be a class", "classToProxy");1365 }1366 CheckNotGenericTypeDefinition(classToProxy, "classToProxy");1367 CheckNotGenericTypeDefinitions(additionalInterfacesToProxy, "additionalInterfacesToProxy");1368 var proxyType = CreateClassProxyType(classToProxy, additionalInterfacesToProxy, options);1369 // create constructor arguments (initialized with mixin implementations, interceptors and target type constructor arguments)1370 var arguments = BuildArgumentListForClassProxy(options, interceptors);1371 if (constructorArguments != null && constructorArguments.Length != 0)1372 {1373 arguments.AddRange(constructorArguments);1374 }1375 return CreateClassProxyInstance(proxyType, arguments, classToProxy, constructorArguments);1376 }1377 protected object CreateClassProxyInstance(Type proxyType, List<object> proxyArguments, Type classToProxy,1378 object[] constructorArguments)1379 {1380 try1381 {1382 return proxyType.CreateObject(proxyArguments.ToArray());1383 }1384 catch (MissingMethodException)1385 {1386 var message = new StringBuilder();1387 message.AppendFormat("Can not instantiate proxy of class: {0}.", classToProxy.FullName);1388 message.AppendLine();1389 if (constructorArguments == null || constructorArguments.Length == 0)1390 {1391 message.Append("Could not find a parameterless constructor.");1392 }1393 else1394 {1395 message.AppendLine("Could not find a constructor that would match given arguments:");1396 foreach (var argument in constructorArguments)1397 {1398 var argumentText = argument == null ? "<null>" : argument.GetType().ToString();1399 message.AppendLine(argumentText);1400 }1401 }1402 throw new InvalidProxyConstructorArgumentsException(message.ToString(),proxyType,classToProxy);1403 }1404 }1405 protected void CheckNotGenericTypeDefinition(Type type, string argumentName)1406 {1407 if (type != null && type.GetTypeInfo().IsGenericTypeDefinition)1408 {1409 throw new GeneratorException(string.Format("Can not create proxy for type {0} because it is an open generic type.",1410 type.GetBestName()));1411 }1412 }1413 protected void CheckNotGenericTypeDefinitions(IEnumerable<Type> types, string argumentName)1414 {1415 if (types == null)1416 {1417 return;1418 }1419 foreach (var t in types)1420 {1421 CheckNotGenericTypeDefinition(t, argumentName);1422 }1423 }1424 protected List<object> BuildArgumentListForClassProxyWithTarget(object target, ProxyGenerationOptions options,1425 IInterceptor[] interceptors)1426 {1427 var arguments = new List<object>();1428 arguments.Add(target);1429 arguments.AddRange(options.MixinData.Mixins);1430 arguments.Add(interceptors);1431 if (options.Selector != null)1432 {1433 arguments.Add(options.Selector);1434 }1435 return arguments;1436 }1437 protected List<object> BuildArgumentListForClassProxy(ProxyGenerationOptions options, IInterceptor[] interceptors)1438 {1439 var arguments = new List<object>(options.MixinData.Mixins) { interceptors };1440 if (options.Selector != null)1441 {1442 arguments.Add(options.Selector);1443 }1444 return arguments;1445 }1446 /// <summary>1447 /// Creates the proxy type for class proxy with given <paramref name = "classToProxy" /> class, implementing given <paramref1448 /// name = "additionalInterfacesToProxy" /> and using provided <paramref name = "options" />.1449 /// </summary>1450 /// <param name = "classToProxy">The base class for proxy type.</param>1451 /// <param name = "additionalInterfacesToProxy">The interfaces that proxy type should implement.</param>1452 /// <param name = "options">The options for proxy generation process.</param>1453 /// <returns><see cref = "Type" /> of proxy.</returns>1454 protected Type CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy,1455 ProxyGenerationOptions options)1456 {1457 // create proxy1458 return ProxyBuilder.CreateClassProxyType(classToProxy, additionalInterfacesToProxy, options);1459 }1460 /// <summary>1461 /// Creates the proxy type for interface proxy with target for given <paramref name = "interfaceToProxy" /> interface, implementing given <paramref1462 /// name = "additionalInterfacesToProxy" /> on given <paramref name = "targetType" /> and using provided <paramref1463 /// name = "options" />.1464 /// </summary>1465 /// <param name = "interfaceToProxy">The interface proxy type should implement.</param>1466 /// <param name = "additionalInterfacesToProxy">The additional interfaces proxy type should implement.</param>1467 /// <param name = "targetType">Actual type that the proxy type will encompass.</param>1468 /// <param name = "options">The options for proxy generation process.</param>1469 /// <returns><see cref = "Type" /> of proxy.</returns>1470 protected Type CreateInterfaceProxyTypeWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy,1471 Type targetType,1472 ProxyGenerationOptions options)1473 {1474 // create proxy1475 return ProxyBuilder.CreateInterfaceProxyTypeWithTarget(interfaceToProxy, additionalInterfacesToProxy, targetType,1476 options);1477 }1478 /// <summary>1479 /// Creates the proxy type for interface proxy with target interface for given <paramref name = "interfaceToProxy" /> interface, implementing given <paramref1480 /// name = "additionalInterfacesToProxy" /> on given <paramref name = "interfaceToProxy" /> and using provided <paramref1481 /// name = "options" />.1482 /// </summary>1483 /// <param name = "interfaceToProxy">The interface proxy type should implement.</param>1484 /// <param name = "additionalInterfacesToProxy">The additional interfaces proxy type should implement.</param>1485 /// <param name = "options">The options for proxy generation process.</param>1486 /// <returns><see cref = "Type" /> of proxy.</returns>1487 protected Type CreateInterfaceProxyTypeWithTargetInterface(Type interfaceToProxy, Type[] additionalInterfacesToProxy,1488 ProxyGenerationOptions options)1489 {1490 // create proxy1491 return ProxyBuilder.CreateInterfaceProxyTypeWithTargetInterface(interfaceToProxy, additionalInterfacesToProxy,1492 options);1493 }1494 /// <summary>1495 /// Creates the proxy type for interface proxy without target for given <paramref name = "interfaceToProxy" /> interface, implementing given <paramref1496 /// name = "additionalInterfacesToProxy" /> and using provided <paramref name = "options" />.1497 /// </summary>1498 /// <param name = "interfaceToProxy">The interface proxy type should implement.</param>1499 /// <param name = "additionalInterfacesToProxy">The additional interfaces proxy type should implement.</param>1500 /// <param name = "options">The options for proxy generation process.</param>1501 /// <returns><see cref = "Type" /> of proxy.</returns>1502 protected Type CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy,1503 ProxyGenerationOptions options)1504 {1505 // create proxy1506 return ProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(interfaceToProxy, additionalInterfacesToProxy, options);1507 }1508 protected Type CreateClassProxyTypeWithTarget(Type classToProxy, Type[] additionalInterfacesToProxy,1509 ProxyGenerationOptions options)1510 {1511 // create proxy1512 return ProxyBuilder.CreateClassProxyTypeWithTarget(classToProxy, additionalInterfacesToProxy, options);1513 }1514 }1515}...

Full Screen

Full Screen

DynamicProxyMockFactory.cs

Source:DynamicProxyMockFactory.cs Github

copy

Full Screen

...158 options.AddMixinInstance(mixin);159 var compoundMockMixin = (IMockMixin)generator.CreateClassProxy(typeof(MocksRepository.ExternalMockMixin), options);160 return compoundMockMixin;161 }162 public ProxyTypeInfo CreateClassProxyType(Type classToProxy, MocksRepository repository, MockCreationSettings settings, MockMixin mockMixinImpl)163 {164 var pgo = CreateProxyGenerationOptions(classToProxy, settings, mockMixinImpl);165 var typeInfo = new ProxyTypeInfo166 {167 ProxyType = generator.ProxyBuilder.CreateClassProxyType(classToProxy, Type.EmptyTypes, pgo)168 };169 typeInfo.Mixins.Add(typeof(IInterceptor), repository.Interceptor);170 foreach (var mixin in pgo.MixinData.MixinInterfaces)171 {172 typeInfo.Mixins.Add(mixin, pgo.MixinData.GetMixinInstance(mixin));173 }174 return typeInfo;175 }176 private ProxyGenerationOptions CreateProxyGenerationOptions(Type type, MockCreationSettings settings, MockMixin mockMixinImpl = null)177 {178 var options = new ProxyGenerationOptions();179 if (mockMixinImpl != null)180 options.AddMixinInstance(mockMixinImpl);181 foreach (var mixin in settings.Mixins)...

Full Screen

Full Screen

DefaultProxyBuilder.cs

Source:DefaultProxyBuilder.cs Github

copy

Full Screen

...50 public ModuleScope ModuleScope51 {52 get { return scope; }53 }54 public Type CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)55 {56 AssertValidType(classToProxy);57 AssertValidTypes(additionalInterfacesToProxy);58 var generator = new ClassProxyGenerator(scope, classToProxy) { Logger = logger };59 return generator.GenerateCode(additionalInterfacesToProxy, options);60 }61 public Type CreateClassProxyTypeWithTarget(Type classToProxy, Type[] additionalInterfacesToProxy,62 ProxyGenerationOptions options)63 {64 AssertValidType(classToProxy);65 AssertValidTypes(additionalInterfacesToProxy);66 var generator = new ClassProxyWithTargetGenerator(scope, classToProxy, additionalInterfacesToProxy, options)67 { Logger = logger };68 return generator.GetGeneratedType();69 }70 public Type CreateInterfaceProxyTypeWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy,71 Type targetType,72 ProxyGenerationOptions options)73 {74 AssertValidType(interfaceToProxy);75 AssertValidTypes(additionalInterfacesToProxy);...

Full Screen

Full Screen

CreateClassProxyType

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using Telerik.JustMock.Core.Castle.DynamicProxy;6{7 {8 static void Main(string[] args)9 {10 DefaultProxyBuilder proxyBuilder = new DefaultProxyBuilder();11 Type classProxyType = proxyBuilder.CreateClassProxyType(typeof(Subject), new Type[] { typeof(ISubject) });12 ISubject subject = (ISubject)Activator.CreateInstance(classProxyType);13 Console.WriteLine(subject.DoSomething());14 Console.ReadLine();15 }16 }17 {18 string DoSomething();19 }20 {21 public string DoSomething()22 {23 return "Hello World!";24 }25 }26}

Full Screen

Full Screen

CreateClassProxyType

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Telerik.JustMock.Core.Castle.DynamicProxy;7{8 {9 {10 get;11 set;12 }13 }14 {15 {16 get;17 set;18 }19 }20 {21 static void Main(string[] args)22 {23 var proxyBuilder = new DefaultProxyBuilder();24 var proxyType = proxyBuilder.CreateClassProxyType(typeof(Class1), new Type[] { typeof(Class2) }, ProxyGenerationOptions.Default);25 var proxy = Activator.CreateInstance(proxyType);26 var proxyName = proxy.GetType().GetProperty("name");27 proxyName.SetValue(proxy, "Hello");28 Console.WriteLine(proxyName.GetValue(proxy));29 Console.ReadLine();30 }31 }32}33Hello,Thank you for writing.I am afraid that the current version of JustMock does not support the creation of proxy types with multiple interfaces. I have created a feature request in our feedback portal and logged it with ID: 1552. You can track its progress and vote for it here . You can also use the "Notify Me" option to receive an email when the feature is implemented.I have also prepared a sample project that demonstrates the creation of proxy types with multiple interfaces. You can find it attached to this post. Please note that the sample project is created for .NET Framework 4.5.2 and uses the latest version of JustMock (2018.3.1023.1).Kind regards,StefanTelerik

Full Screen

Full Screen

CreateClassProxyType

Using AI Code Generation

copy

Full Screen

1using System;2using Telerik.JustMock.Core.Castle.DynamicProxy;3{4 {5 static void Main(string[] args)6 {7 var proxyBuilder = new DefaultProxyBuilder();8 var proxyType = proxyBuilder.CreateClassProxyType(typeof(MyClass), null, null, null);9 Console.WriteLine(proxyType);10 }11 }12 {13 }14}15using System;16using Telerik.JustMock.Core.Castle.DynamicProxy;17{18 {19 static void Main(string[] args)20 {21 var proxyBuilder = new DefaultProxyBuilder();22 var proxyType = proxyBuilder.CreateClassProxyType(typeof(MyClass), new Type[] { typeof(IInterface) }, null, null);23 Console.WriteLine(proxyType);24 }25 }26 {27 }28 {29 }30}31using System;32using Telerik.JustMock.Core.Castle.DynamicProxy;33{34 {35 static void Main(string[] args)36 {37 var proxyBuilder = new DefaultProxyBuilder();38 var proxyType = proxyBuilder.CreateClassProxyType(typeof(MyClass), new Type[] { typeof(IInterface) }, ProxyGenerationOptions.Default, null);39 Console.WriteLine(proxyType);40 }41 }42 {43 }44 {45 }46}47using System;48using Telerik.JustMock.Core.Castle.DynamicProxy;49{50 {51 static void Main(string[] args)52 {53 var proxyBuilder = new DefaultProxyBuilder();54 var proxyType = proxyBuilder.CreateClassProxyType(typeof(MyClass), new Type[] { typeof(IInterface) }, ProxyGenerationOptions.Default, new object[] { "test" });55 Console.WriteLine(proxyType);56 }57 }58 {59 }

Full Screen

Full Screen

CreateClassProxyType

Using AI Code Generation

copy

Full Screen

1using System;2using Telerik.JustMock.Core.Castle.DynamicProxy;3using System.Reflection;4{5 {6 static void Main(string[] args)7 {8 var proxyBuilder = new DefaultProxyBuilder();9 var proxyType = proxyBuilder.CreateClassProxyType(typeof(ProxyClass), new Type[] { typeof(IProxyInterface) }, ProxyGenerationOptions.Default);10 var proxy = (IProxyInterface)Activator.CreateInstance(proxyType, new object[] { });11 proxy.Method();12 Console.ReadLine();13 }14 }15 {16 public void Method()17 {18 Console.WriteLine("Method");19 }20 }21 {22 void Method();23 }24}25using System;26using Telerik.JustMock.Core.Castle.DynamicProxy;27using System.Reflection;28{29 {30 static void Main(string[] args)31 {32 var proxyBuilder = new ProxyBuilder();33 var proxyType = proxyBuilder.CreateClassProxyType(typeof(ProxyClass), new Type[] { typeof(IProxyInterface) }, ProxyGenerationOptions.Default);34 var proxy = (IProxyInterface)Activator.CreateInstance(proxyType, new object[] { });35 proxy.Method();36 Console.ReadLine();37 }38 }39 {40 public void Method()41 {42 Console.WriteLine("Method");43 }44 }45 {46 void Method();47 }48}49using System;50using Telerik.JustMock.Core.Castle.DynamicProxy;51using System.Reflection;52{53 {54 static void Main(string[] args)55 {56 var proxyBuilder = new ProxyBuilder();57 var proxyType = proxyBuilder.CreateClassProxyType(typeof(ProxyClass), new Type[] { typeof(IProxyInterface) }, ProxyGenerationOptions.Default);58 var proxy = (IProxyInterface)Activator.CreateInstance(proxyType, new object[] { });59 proxy.Method();60 Console.ReadLine();61 }62 }

Full Screen

Full Screen

CreateClassProxyType

Using AI Code Generation

copy

Full Screen

1using Telerik.JustMock.Core.Castle.DynamicProxy;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 public void CreateClassProxyType()10 {11 var proxyBuilder = new DefaultProxyBuilder();12 var proxyType = proxyBuilder.CreateClassProxyType(typeof(Class1), new Type[] { typeof(IInterface1) });13 var proxy = Activator.CreateInstance(proxyType);14 var proxyInterface = proxy as IInterface1;15 proxyInterface.Method1();16 }17 }18}19using Telerik.JustMock.Core.Castle.DynamicProxy;20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using System.Threading.Tasks;25{26 {27 public void CreateClassProxyType()28 {29 var proxyBuilder = new DefaultProxyBuilder();30 var proxyType = proxyBuilder.CreateClassProxyType(typeof(Class2), new Type[] { typeof(IInterface2) });31 var proxy = Activator.CreateInstance(proxyType);32 var proxyInterface = proxy as IInterface2;33 proxyInterface.Method2();34 }35 }36}37using Telerik.JustMock.Core.Castle.DynamicProxy;38using System;39using System.Collections.Generic;40using System.Linq;41using System.Text;42using System.Threading.Tasks;43{44 {45 public void CreateClassProxyType()46 {47 var proxyBuilder = new DefaultProxyBuilder();48 var proxyType = proxyBuilder.CreateClassProxyType(typeof(Class3), new Type[] { typeof(IInterface3) });49 var proxy = Activator.CreateInstance(proxyType);50 var proxyInterface = proxy as IInterface3;51 proxyInterface.Method3();52 }53 }54}55using Telerik.JustMock.Core.Castle.DynamicProxy;56using System;57using System.Collections.Generic;58using System.Linq;59using System.Text;

Full Screen

Full Screen

CreateClassProxyType

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using Telerik.JustMock.Core.Castle.DynamicProxy;6using Telerik.JustMock.Core.Context;7{8 {9 public void CreateClassProxyType()10 {11 var proxyBuilder = new DefaultProxyBuilder();12 var proxyType = proxyBuilder.CreateClassProxyType(typeof(Test), null, null);13 }14 }15}16using System;17using System.Collections.Generic;18using System.Linq;19using System.Text;20using Telerik.JustMock.Core.Castle.DynamicProxy;21using Telerik.JustMock.Core.Context;22{23 {24 public void CreateClassProxyType()25 {26 var proxyBuilder = new DefaultProxyBuilder();27 var proxyType = proxyBuilder.CreateClassProxyType(typeof(Test), null, null);28 }29 }30}31using System;32using System.Collections.Generic;33using System.Linq;34using System.Text;35using Telerik.JustMock.Core.Castle.DynamicProxy;36using Telerik.JustMock.Core.Context;37{38 {39 public void CreateClassProxyType()40 {41 var proxyBuilder = new DefaultProxyBuilder();42 var proxyType = proxyBuilder.CreateClassProxyType(typeof(Test), null, null);43 }44 }45}46using System;47using System.Collections.Generic;48using System.Linq;49using System.Text;50using Telerik.JustMock.Core.Castle.DynamicProxy;51using Telerik.JustMock.Core.Context;52{53 {54 public void CreateClassProxyType()55 {56 var proxyBuilder = new DefaultProxyBuilder();57 var proxyType = proxyBuilder.CreateClassProxyType(typeof(Test), null, null);58 }59 }60}61using System;62using System.Collections.Generic;

Full Screen

Full Screen

CreateClassProxyType

Using AI Code Generation

copy

Full Screen

1using System;2using System.Reflection;3using Telerik.JustMock.Core.Castle.DynamicProxy;4using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST;5{6 {7 public static void Main()8 {9 var builder = new DefaultProxyBuilder();10 var type = builder.CreateClassProxyType(typeof(object), new Type[0], ProxyGenerationOptions.Default);11 Console.WriteLine(type);12 Console.ReadLine();13 }14 }15}

Full Screen

Full Screen

CreateClassProxyType

Using AI Code Generation

copy

Full Screen

1using Telerik.JustMock.Core.Castle.DynamicProxy;2{3 {4 public void CreateProxyType()5 {6 DefaultProxyBuilder proxyBuilder = new DefaultProxyBuilder();7 var proxyType = proxyBuilder.CreateClassProxyType(typeof(JustMockUnitTest.CreateClassProxyType), new Type[] { typeof(IInterceptor) });8 }9 }10}11using Telerik.JustMock.Core.Castle.DynamicProxy;12{13 {14 public void CreateProxyType()15 {16 DefaultProxyBuilder proxyBuilder = new DefaultProxyBuilder();17 var proxyType = proxyBuilder.CreateClassProxyType(typeof(JustMockUnitTest.CreateClassProxyType), new Type[] { typeof(IInterceptor) });18 }19 }20}

Full Screen

Full Screen

CreateClassProxyType

Using AI Code Generation

copy

Full Screen

1var proxyBuilder = new Telerik.JustMock.Core.Castle.DynamicProxy.DefaultProxyBuilder();2var proxyType = proxyBuilder.CreateClassProxyType(typeof(JustMockTest), new Type[] { typeof(IJustMockTest) });3var proxyGenerator = new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator();4var proxy = proxyGenerator.CreateClassProxy(typeof(JustMockTest), new Type[] { typeof(IJustMockTest) });5var proxyGenerator = new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator();6var proxy = proxyGenerator.CreateClassProxy(typeof(JustMockTest), new Type[] { typeof(IJustMockTest) }, new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerationOptions(), new object[] { "test" });7var proxyGenerator = new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator();8var proxy = proxyGenerator.CreateClassProxy(typeof(JustMockTest), new Type[] { typeof(IJustMockTest) }, new object[] { "test" });9var proxyGenerator = new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator();10var proxy = proxyGenerator.CreateClassProxy(typeof(JustMockTest), new Type[] { typeof(IJustMockTest) }, new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerationOptions(), new object[] { "test" }, new Telerik.JustMock.Core.Castle.DynamicProxy.IInterceptor[] { new Telerik.JustMock.Core.Castle.DynamicProxy.IInterceptor() });11var proxyGenerator = new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator();12var proxy = proxyGenerator.CreateClassProxy(typeof(JustMockTest), new Type[] { typeof(IJustMockTest) }, new Telerik.JustMock.Core.Castle.DynamicProxy.IInterceptor[] { new Telerik.JustMock.Core.Castle.DynamicProxy.IInterceptor() });

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful