How to use TypeInfo method of Xunit.v3.Mocks class

Best Xunit code snippet using Xunit.v3.Mocks.TypeInfo

Mocks.cs

Source:Mocks.cs Github

copy

Full Screen

...13using TestMethodDisplayOptions = Xunit.Sdk.TestMethodDisplayOptions;14public static class Mocks15{16 public static IAssemblyInfo AssemblyInfo(17 ITypeInfo[]? types = null,18 IReflectionAttributeInfo[]? attributes = null,19 string? assemblyFileName = null)20 {21 attributes = attributes ?? new IReflectionAttributeInfo[0];22 var result = Substitute.For<IAssemblyInfo, InterfaceProxy<IAssemblyInfo>>();23 result.Name.Returns(assemblyFileName == null ? "assembly:" + Guid.NewGuid().ToString("n") : Path.GetFileNameWithoutExtension(assemblyFileName));24 result.AssemblyPath.Returns(assemblyFileName);25 result.GetType("").ReturnsForAnyArgs(types?.FirstOrDefault());26 result.GetTypes(true).ReturnsForAnyArgs(types ?? new ITypeInfo[0]);27 result.GetCustomAttributes("").ReturnsForAnyArgs(callInfo => LookupAttribute(callInfo.Arg<string>(), attributes));28 return result;29 }30 public static IReflectionAttributeInfo CollectionAttribute(string collectionName)31 {32 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();33 result.Attribute.Returns(new CollectionAttribute(collectionName));34 result.GetConstructorArguments().Returns(new[] { collectionName });35 return result;36 }37 public static IReflectionAttributeInfo CollectionBehaviorAttribute(38 CollectionBehavior? collectionBehavior = null,39 bool disableTestParallelization = false,40 int maxParallelThreads = 0)41 {42 CollectionBehaviorAttribute attribute;43 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();44 if (collectionBehavior.HasValue)45 {46 attribute = new CollectionBehaviorAttribute(collectionBehavior.GetValueOrDefault());47 result.GetConstructorArguments().Returns(new object[] { collectionBehavior });48 }49 else50 {51 attribute = new CollectionBehaviorAttribute();52 result.GetConstructorArguments().Returns(new object[0]);53 }54 attribute.DisableTestParallelization = disableTestParallelization;55 attribute.MaxParallelThreads = maxParallelThreads;56 result.Attribute.Returns(attribute);57 result.GetNamedArgument<bool>("DisableTestParallelization").Returns(disableTestParallelization);58 result.GetNamedArgument<int>("MaxParallelThreads").Returns(maxParallelThreads);59 return result;60 }61 public static IReflectionAttributeInfo CollectionBehaviorAttribute(62 Type factoryType,63 bool disableTestParallelization = false,64 int maxParallelThreads = 0)65 {66 var attribute = new CollectionBehaviorAttribute(factoryType)67 {68 DisableTestParallelization = disableTestParallelization,69 MaxParallelThreads = maxParallelThreads70 };71 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();72 result.Attribute.Returns(attribute);73 result.GetNamedArgument<bool>("DisableTestParallelization").Returns(disableTestParallelization);74 result.GetNamedArgument<int>("MaxParallelThreads").Returns(maxParallelThreads);75 result.GetConstructorArguments().Returns(new object[] { factoryType });76 return result;77 }78 public static IReflectionAttributeInfo CollectionBehaviorAttribute(79 string factoryTypeName,80 string factoryAssemblyName,81 bool disableTestParallelization = false,82 int maxParallelThreads = 0)83 {84 var attribute = new CollectionBehaviorAttribute(factoryTypeName, factoryAssemblyName)85 {86 DisableTestParallelization = disableTestParallelization,87 MaxParallelThreads = maxParallelThreads88 };89 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();90 result.Attribute.Returns(attribute);91 result.GetNamedArgument<bool>("DisableTestParallelization").Returns(disableTestParallelization);92 result.GetNamedArgument<int>("MaxParallelThreads").Returns(maxParallelThreads);93 result.GetConstructorArguments().Returns(new object[] { factoryTypeName, factoryAssemblyName });94 return result;95 }96 public static IReflectionAttributeInfo CollectionDefinitionAttribute(string collectionName)97 {98 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();99 result.Attribute.Returns(new CollectionDefinitionAttribute(collectionName));100 result.GetConstructorArguments().Returns(new[] { collectionName });101 return result;102 }103 public static IReflectionAttributeInfo DataAttribute(IEnumerable<object[]>? data = null)104 {105 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();106 var dataAttribute = Substitute.For<DataAttribute>();107 dataAttribute.GetData(null!).ReturnsForAnyArgs(data);108 result.Attribute.Returns(dataAttribute);109 return result;110 }111 public static ExecutionErrorTestCase ExecutionErrorTestCase(112 string message,113 IMessageSink? diagnosticMessageSink = null)114 {115 var testMethod = TestMethod();116 return new ExecutionErrorTestCase(117 diagnosticMessageSink ?? new NullMessageSink(),118 TestMethodDisplay.ClassAndMethod,119 TestMethodDisplayOptions.None,120 testMethod,121 message122 );123 }124 public static IReflectionAttributeInfo FactAttribute(125 string? displayName = null,126 string? skip = null,127 int timeout = 0)128 {129 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();130 result.Attribute.Returns(new FactAttribute { DisplayName = displayName, Skip = skip, Timeout = timeout });131 result.GetNamedArgument<string>("DisplayName").Returns(displayName);132 result.GetNamedArgument<string>("Skip").Returns(skip);133 result.GetNamedArgument<int>("Timeout").Returns(timeout);134 return result;135 }136 static IEnumerable<IAttributeInfo> LookupAttribute(137 string fullyQualifiedTypeName,138 IReflectionAttributeInfo[]? attributes)139 {140 if (attributes == null)141 return Enumerable.Empty<IAttributeInfo>();142 var attributeType = Type.GetType(fullyQualifiedTypeName);143 if (attributeType == null)144 return Enumerable.Empty<IAttributeInfo>();145 return attributes.Where(attribute => attributeType.IsAssignableFrom(attribute.Attribute.GetType())).ToList();146 }147 public static IMethodInfo MethodInfo(148 string? methodName = null,149 IReflectionAttributeInfo[]? attributes = null,150 IParameterInfo[]? parameters = null,151 ITypeInfo? type = null,152 ITypeInfo? returnType = null,153 bool isAbstract = false,154 bool isPublic = true,155 bool isStatic = false)156 {157 var result = Substitute.For<IMethodInfo, InterfaceProxy<IMethodInfo>>();158 attributes ??= new IReflectionAttributeInfo[0];159 parameters ??= new IParameterInfo[0];160 result.IsAbstract.Returns(isAbstract);161 result.IsPublic.Returns(isPublic);162 result.IsStatic.Returns(isStatic);163 result.Name.Returns(methodName ?? "method:" + Guid.NewGuid().ToString("n"));164 result.ReturnType.Returns(returnType);165 result.Type.Returns(type);166 result.GetCustomAttributes("").ReturnsForAnyArgs(callInfo => LookupAttribute(callInfo.Arg<string>(), attributes));167 result.GetParameters().Returns(parameters);168 return result;169 }170 public static IParameterInfo ParameterInfo(string name)171 {172 var result = Substitute.For<IParameterInfo, InterfaceProxy<IParameterInfo>>();173 result.Name.Returns(name);174 return result;175 }176 public static IReflectionMethodInfo ReflectionMethodInfo<TClass>(string methodName)177 {178 return Reflector.Wrap(typeof(TClass).GetMethod(methodName)!);179 }180 public static IReflectionTypeInfo ReflectionTypeInfo<TClass>()181 {182 return Reflector.Wrap(typeof(TClass));183 }184 public static IRunnerReporter RunnerReporter(185 string? runnerSwitch = null,186 string? description = null,187 bool isEnvironmentallyEnabled = false,188 IMessageSinkWithTypes? messageSink = null)189 {190 var result = Substitute.For<IRunnerReporter, InterfaceProxy<IRunnerReporter>>();191 result.Description.Returns(description ?? "The runner reporter description");192 result.IsEnvironmentallyEnabled.ReturnsForAnyArgs(isEnvironmentallyEnabled);193 result.RunnerSwitch.Returns(runnerSwitch);194 var dualSink = MessageSinkAdapter.Wrap(messageSink ?? Substitute.For<IMessageSinkWithTypes, InterfaceProxy<IMessageSinkWithTypes>>());195 result.CreateMessageHandler(null!).ReturnsForAnyArgs(dualSink);196 return result;197 }198 public static ITest Test(199 ITestCase testCase,200 string displayName)201 {202 var result = Substitute.For<ITest, InterfaceProxy<ITest>>();203 result.DisplayName.Returns(displayName);204 result.TestCase.Returns(testCase);205 return result;206 }207 public static ITestAssembly TestAssembly(IReflectionAttributeInfo[] attributes)208 {209 var assemblyInfo = AssemblyInfo(attributes: attributes);210 var result = Substitute.For<ITestAssembly, InterfaceProxy<ITestAssembly>>();211 result.Assembly.Returns(assemblyInfo);212 return result;213 }214 public static ITestAssembly TestAssembly(215 string assemblyFileName,216 string? configFileName = null,217 ITypeInfo[]? types = null,218 IReflectionAttributeInfo[]? attributes = null)219 {220 var assemblyInfo = AssemblyInfo(types, attributes, assemblyFileName);221 var result = Substitute.For<ITestAssembly, InterfaceProxy<ITestAssembly>>();222 result.Assembly.Returns(assemblyInfo);223 result.ConfigFileName.Returns(configFileName);224 return result;225 }226 public static TestAssembly TestAssembly(227 Assembly? assembly = null,228 string? configFileName = null)229 {230#if NETFRAMEWORK231 if (configFileName == null)232 configFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;233#endif234 return new TestAssembly(Reflector.Wrap(assembly ?? typeof(Mocks).Assembly), configFileName);235 }236 public static ITestAssemblyDiscoveryFinished TestAssemblyDiscoveryFinished(237 bool diagnosticMessages = false,238 int toRun = 42,239 int discovered = 2112)240 {241 var assembly = new XunitProjectAssembly { AssemblyFilename = "testAssembly.dll", ConfigFilename = "testAssembly.dll.config" };242 var config = new TestAssemblyConfiguration { DiagnosticMessages = diagnosticMessages, ShadowCopy = true };243 var result = Substitute.For<ITestAssemblyDiscoveryFinished, InterfaceProxy<ITestAssemblyDiscoveryFinished>>();244 result.Assembly.Returns(assembly);245 result.DiscoveryOptions.Returns(TestFrameworkOptions.ForDiscovery(config));246 result.TestCasesDiscovered.Returns(discovered);247 result.TestCasesToRun.Returns(toRun);248 return result;249 }250 public static ITestAssemblyDiscoveryStarting TestAssemblyDiscoveryStarting(251 bool diagnosticMessages = false,252 AppDomainOption appDomain = AppDomainOption.Disabled,253 bool shadowCopy = false)254 {255 var assembly = new XunitProjectAssembly { AssemblyFilename = "testAssembly.dll", ConfigFilename = "testAssembly.dll.config" };256 var config = new TestAssemblyConfiguration { DiagnosticMessages = diagnosticMessages, MethodDisplay = Xunit.TestMethodDisplay.ClassAndMethod, MaxParallelThreads = 42, ParallelizeTestCollections = true, ShadowCopy = shadowCopy };257 var result = Substitute.For<ITestAssemblyDiscoveryStarting, InterfaceProxy<ITestAssemblyDiscoveryStarting>>();258 result.AppDomain.Returns(appDomain);259 result.Assembly.Returns(assembly);260 result.DiscoveryOptions.Returns(TestFrameworkOptions.ForDiscovery(config));261 result.ShadowCopy.Returns(shadowCopy);262 return result;263 }264 public static ITestAssemblyExecutionFinished TestAssemblyExecutionFinished(265 bool diagnosticMessages = false,266 int total = 2112,267 int failed = 42,268 int skipped = 8,269 int errors = 6,270 decimal time = 123.456M)271 {272 var assembly = new XunitProjectAssembly { AssemblyFilename = "testAssembly.dll", ConfigFilename = "testAssembly.dll.config" };273 var config = new TestAssemblyConfiguration { DiagnosticMessages = diagnosticMessages, ShadowCopy = true };274 var summary = new ExecutionSummary { Total = total, Failed = failed, Skipped = skipped, Errors = errors, Time = time };275 var result = Substitute.For<ITestAssemblyExecutionFinished, InterfaceProxy<ITestAssemblyExecutionFinished>>();276 result.Assembly.Returns(assembly);277 result.ExecutionOptions.Returns(TestFrameworkOptions.ForExecution(config));278 result.ExecutionSummary.Returns(summary);279 return result;280 }281 public static ITestAssemblyExecutionStarting TestAssemblyExecutionStarting(282 bool diagnosticMessages = false,283 string? assemblyFilename = null)284 {285 var assembly = new XunitProjectAssembly { AssemblyFilename = assemblyFilename ?? "testAssembly.dll", ConfigFilename = "testAssembly.dll.config" };286 var config = new TestAssemblyConfiguration { DiagnosticMessages = diagnosticMessages, MethodDisplay = Xunit.TestMethodDisplay.ClassAndMethod, MaxParallelThreads = 42, ParallelizeTestCollections = true, ShadowCopy = true };287 var result = Substitute.For<ITestAssemblyExecutionStarting, InterfaceProxy<ITestAssemblyExecutionStarting>>();288 result.Assembly.Returns(assembly);289 result.ExecutionOptions.Returns(TestFrameworkOptions.ForExecution(config));290 return result;291 }292 public static ITestAssemblyFinished TestAssemblyFinished(293 int testsRun = 2112,294 int testsFailed = 42,295 int testsSkipped = 6,296 decimal executionTime = 123.4567M)297 {298 var testAssembly = TestAssembly("testAssembly.dll");299 var result = Substitute.For<ITestAssemblyFinished, InterfaceProxy<ITestAssemblyFinished>>();300 result.TestAssembly.Returns(testAssembly);301 result.TestsRun.Returns(testsRun);302 result.TestsFailed.Returns(testsFailed);303 result.TestsSkipped.Returns(testsSkipped);304 result.ExecutionTime.Returns(executionTime);305 return result;306 }307 public static ITestAssemblyStarting TestAssemblyStarting()308 {309 var testAssembly = TestAssembly("testAssembly.dll");310 var result = Substitute.For<ITestAssemblyStarting, InterfaceProxy<ITestAssemblyStarting>>();311 result.TestAssembly.Returns(testAssembly);312 return result;313 }314 public static ITestCase TestCase(ITestCollection? collection = null)315 {316 if (collection == null)317 collection = TestCollection();318 var result = Substitute.For<ITestCase, InterfaceProxy<ITestCase>>();319 result.TestMethod.TestClass.TestCollection.Returns(collection);320 return result;321 }322 public static ITestCase TestCase(ITestMethod testMethod)323 {324 var result = Substitute.For<ITestCase, InterfaceProxy<ITestCase>>();325 result.TestMethod.Returns(testMethod);326 return result;327 }328 public static ITestCase TestCase<TClassUnderTest>(329 string methodName,330 string? displayName = null,331 string? skipReason = null,332 string? uniqueID = null,333 string? fileName = null,334 int? lineNumber = null)335 {336 return TestCase(typeof(TClassUnderTest), methodName, displayName, skipReason, uniqueID, fileName, lineNumber);337 }338 public static ITestCase TestCase(339 Type type,340 string methodName,341 string? displayName = null,342 string? skipReason = null,343 string? uniqueID = null,344 string? fileName = null,345 int? lineNumber = null)346 {347 var testMethod = TestMethod(type, methodName);348 var traits = GetTraits(testMethod.Method);349 var result = Substitute.For<ITestCase, InterfaceProxy<ITestCase>>();350 result.DisplayName.Returns(displayName ?? $"{type}.{methodName}");351 result.SkipReason.Returns(skipReason);352 result.TestMethod.Returns(testMethod);353 result.Traits.Returns(traits);354 result.UniqueID.Returns(uniqueID ?? Guid.NewGuid().ToString());355 if (fileName != null && lineNumber != null)356 {357 var sourceInfo = new Xunit.SourceInformation { FileName = fileName, LineNumber = lineNumber };358 result.SourceInformation.Returns(sourceInfo);359 }360 return result;361 }362 public static IReflectionAttributeInfo TestCaseOrdererAttribute(string typeName, string assemblyName)363 {364 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();365 result.Attribute.Returns(new TestCaseOrdererAttribute(typeName, assemblyName));366 result.GetConstructorArguments().Returns(new object[] { typeName, assemblyName });367 return result;368 }369 public static IReflectionAttributeInfo TestCaseOrdererAttribute(Type type)370 {371 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();372 result.Attribute.Returns(new TestCaseOrdererAttribute(type));373 result.GetConstructorArguments().Returns(new object[] { type });374 return result;375 }376 public static IReflectionAttributeInfo TestCaseOrdererAttribute<TOrderer>() =>377 TestCaseOrdererAttribute(typeof(TOrderer));378 public static ITestClass TestClass(379 string? typeName = null,380 IReflectionAttributeInfo[]? attributes = null)381 {382 var testCollection = TestCollection();383 var typeInfo = TypeInfo(typeName, attributes: attributes);384 var result = Substitute.For<ITestClass, InterfaceProxy<ITestClass>>();385 result.Class.Returns(typeInfo);386 result.TestCollection.Returns(testCollection);387 return result;388 }389 public static TestClass TestClass(390 Type type,391 ITestCollection? collection = null)392 {393 if (collection == null)394 collection = TestCollection(type.Assembly);395 return new TestClass(collection, Reflector.Wrap(type));396 }397 public static TestCollection TestCollection(398 Assembly? assembly = null,399 ITypeInfo? definition = null,400 string? displayName = null)401 {402 if (assembly == null)403 assembly = typeof(Mocks).Assembly;404 if (displayName == null)405 displayName = "Mock test collection for " + assembly.CodeBase;406 return new TestCollection(TestAssembly(assembly), definition, displayName);407 }408 public static ITestCollectionFinished TestCollectionFinished(409 string displayName = "Display Name",410 int testsRun = 2112,411 int testsFailed = 42,412 int testsSkipped = 6,413 decimal executionTime = 123.4567M)414 {415 var result = Substitute.For<ITestCollectionFinished, InterfaceProxy<ITestCollectionFinished>>();416 result.TestsRun.Returns(testsRun);417 result.TestsFailed.Returns(testsFailed);418 result.TestsSkipped.Returns(testsSkipped);419 result.ExecutionTime.Returns(executionTime);420 result.TestCollection.DisplayName.Returns(displayName);421 return result;422 }423 public static ITestCollectionStarting TestCollectionStarting()424 {425 var result = Substitute.For<ITestCollectionStarting, InterfaceProxy<ITestCollectionStarting>>();426 result.TestCollection.DisplayName.Returns("Display Name");427 return result;428 }429 public static IReflectionAttributeInfo TestCollectionOrdererAttribute(string typeName, string assemblyName)430 {431 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();432 result.Attribute.Returns(new TestCollectionOrdererAttribute(typeName, assemblyName));433 result.GetConstructorArguments().Returns(new object[] { typeName, assemblyName });434 return result;435 }436 public static IReflectionAttributeInfo TestCollectionOrdererAttribute(Type type)437 {438 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();439 result.Attribute.Returns(new TestCollectionOrdererAttribute(type));440 result.GetConstructorArguments().Returns(new object[] { type });441 return result;442 }443 public static IReflectionAttributeInfo TestCollectionOrdererAttribute<TOrderer>() =>444 TestCollectionOrdererAttribute(typeof(TOrderer));445 public static ITestFailed TestFailed(446 Type type,447 string methodName,448 string? displayName = null,449 string? output = null,450 decimal executionTime = 0M,451 Exception? ex = null)452 {453 var testCase = TestCase(type, methodName);454 var test = Test(testCase, displayName ?? "NO DISPLAY NAME");455 var failureInfo = Xunit.Sdk.ExceptionUtility.ConvertExceptionToFailureInformation(ex ?? new Exception());456 var result = Substitute.For<ITestFailed, InterfaceProxy<ITestFailed>>();457 result.ExceptionParentIndices.Returns(failureInfo.ExceptionParentIndices);458 result.ExceptionTypes.Returns(failureInfo.ExceptionTypes);459 result.ExecutionTime.Returns(executionTime);460 result.Messages.Returns(failureInfo.Messages);461 result.Output.Returns(output);462 result.StackTraces.Returns(failureInfo.StackTraces);463 result.TestCase.Returns(testCase);464 result.Test.Returns(test);465 return result;466 }467 public static ITestFailed TestFailed(468 string displayName,469 decimal executionTime,470 string? exceptionType = null,471 string? exceptionMessage = null,472 string? stackTrace = null,473 string? output = null)474 {475 var testCase = TestCase();476 var test = Test(testCase, displayName);477 var result = Substitute.For<ITestFailed, InterfaceProxy<ITestFailed>>();478 result.ExceptionParentIndices.Returns(new[] { -1 });479 result.ExceptionTypes.Returns(new[] { exceptionType });480 result.ExecutionTime.Returns(executionTime);481 result.Messages.Returns(new[] { exceptionMessage });482 result.Output.Returns(output);483 result.StackTraces.Returns(new[] { stackTrace });484 result.TestCase.Returns(testCase);485 result.Test.Returns(test);486 return result;487 }488 public static IReflectionAttributeInfo TestFrameworkAttribute(Type type)489 {490 var attribute = Activator.CreateInstance(type);491 if (attribute == null)492 throw new InvalidOperationException($"Unable to create attribute instance: '{type.FullName}'");493 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();494 result.Attribute.Returns(attribute);495 result.GetCustomAttributes(null).ReturnsForAnyArgs(496 callInfo => LookupAttribute(497 callInfo.Arg<string>(),498 CustomAttributeData.GetCustomAttributes(attribute.GetType()).Select(x => Reflector.Wrap(x)).ToArray()499 )500 );501 return result;502 }503 public static ITestMethod TestMethod(504 string? typeName = null,505 string? methodName = null,506 string? displayName = null,507 string? skip = null,508 int timeout = 0,509 IEnumerable<IParameterInfo>? parameters = null,510 IEnumerable<IReflectionAttributeInfo>? classAttributes = null,511 IEnumerable<IReflectionAttributeInfo>? methodAttributes = null)512 {513 if (classAttributes == null)514 classAttributes = Enumerable.Empty<IReflectionAttributeInfo>();515 if (methodAttributes == null)516 methodAttributes = Enumerable.Empty<IReflectionAttributeInfo>();517 if (parameters == null)518 parameters = Enumerable.Empty<IParameterInfo>();519 var factAttribute = methodAttributes.FirstOrDefault(attr => typeof(FactAttribute).IsAssignableFrom(attr.Attribute.GetType()));520 if (factAttribute == null)521 {522 factAttribute = FactAttribute(displayName, skip, timeout);523 methodAttributes = methodAttributes.Concat(new[] { factAttribute });524 }525 var testClass = TestClass(typeName, attributes: classAttributes.ToArray());526 var methodInfo = MethodInfo(methodName, methodAttributes.ToArray(), parameters.ToArray(), testClass.Class);527 var result = Substitute.For<ITestMethod, InterfaceProxy<ITestMethod>>();528 result.Method.Returns(methodInfo);529 result.TestClass.Returns(testClass);530 return result;531 }532 public static TestMethod TestMethod(533 Type type,534 string methodName,535 ITestCollection? collection = null)536 {537 var @class = TestClass(type, collection);538 var methodInfo = type.GetMethod(methodName);539 if (methodInfo == null)540 throw new Exception($"Unknown method: {type.FullName}.{methodName}");541 return new TestMethod(@class, Reflector.Wrap(methodInfo));542 }543 public static ITestPassed TestPassed(544 Type type,545 string methodName,546 string? displayName = null,547 string? output = null,548 decimal executionTime = 0M)549 {550 var testCase = TestCase(type, methodName);551 var test = Test(testCase, displayName ?? "NO DISPLAY NAME");552 var result = Substitute.For<ITestPassed, InterfaceProxy<ITestPassed>>();553 result.ExecutionTime.Returns(executionTime);554 result.Output.Returns(output);555 result.TestCase.Returns(testCase);556 result.Test.Returns(test);557 return result;558 }559 public static ITestPassed TestPassed(560 string displayName,561 string? output = null)562 {563 var testCase = TestCase();564 var test = Test(testCase, displayName);565 var result = Substitute.For<ITestPassed, InterfaceProxy<ITestPassed>>();566 result.Test.Returns(test);567 result.ExecutionTime.Returns(1.2345M);568 result.Output.Returns(output);569 return result;570 }571 public static ITestResultMessage TestResult<TClassUnderTest>(572 string methodName,573 string displayName,574 decimal executionTime)575 {576 var testCase = TestCase<TClassUnderTest>(methodName);577 var test = Test(testCase, displayName);578 var result = Substitute.For<ITestResultMessage, InterfaceProxy<ITestResultMessage>>();579 result.TestCase.Returns(testCase);580 result.Test.Returns(test);581 result.ExecutionTime.Returns(executionTime);582 return result;583 }584 public static ITestSkipped TestSkipped(585 Type type,586 string methodName,587 string? displayName = null,588 string? output = null,589 decimal executionTime = 0M,590 string? skipReason = null)591 {592 var testCase = TestCase(type, methodName);593 var test = Test(testCase, displayName ?? "NO DISPLAY NAME");594 var result = Substitute.For<ITestSkipped, InterfaceProxy<ITestSkipped>>();595 result.ExecutionTime.Returns(executionTime);596 result.Output.Returns(output);597 result.Reason.Returns(skipReason);598 result.TestCase.Returns(testCase);599 result.Test.Returns(test);600 return result;601 }602 public static ITestSkipped TestSkipped(603 string displayName,604 string? skipReason = null)605 {606 var testCase = TestCase();607 var test = Test(testCase, displayName);608 var result = Substitute.For<ITestSkipped, InterfaceProxy<ITestSkipped>>();609 result.Reason.Returns(skipReason);610 result.TestCase.Returns(testCase);611 result.Test.Returns(test);612 return result;613 }614 public static ITestStarting TestStarting(string displayName)615 {616 var testCase = TestCase();617 var test = Test(testCase, displayName);618 var result = Substitute.For<ITestStarting, InterfaceProxy<ITestStarting>>();619 result.Test.Returns(test);620 return result;621 }622 public static IReflectionAttributeInfo TheoryAttribute(623 string? displayName = null,624 string? skip = null,625 int timeout = 0)626 {627 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();628 result.Attribute.Returns(new TheoryAttribute { DisplayName = displayName, Skip = skip });629 result.GetNamedArgument<string>("DisplayName").Returns(displayName);630 result.GetNamedArgument<string>("Skip").Returns(skip);631 result.GetNamedArgument<int>("Timeout").Returns(timeout);632 return result;633 }634 public static IReflectionAttributeInfo TraitAttribute<T>()635 where T : Attribute, new()636 {637 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();638 result.Attribute.Returns(new T());639 return result;640 }641 public static IReflectionAttributeInfo TraitAttribute(642 string name,643 string value)644 {645 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();646 var traitDiscovererAttributes = new[] { TraitDiscovererAttribute() };647 result.GetCustomAttributes(typeof(TraitDiscovererAttribute)).Returns(traitDiscovererAttributes);648 result.Attribute.Returns(new TraitAttribute(name, value));649 result.GetConstructorArguments().Returns(new object[] { name, value });650 return result;651 }652 public static IAttributeInfo TraitDiscovererAttribute(653 string typeName = "Xunit.Sdk.TraitDiscoverer",654 string assemblyName = "xunit.v3.core")655 {656 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();657 result.Attribute.Returns(new TraitDiscovererAttribute(typeName, assemblyName));658 result.GetConstructorArguments().Returns(new object[] { typeName, assemblyName });659 return result;660 }661 public static IAttributeInfo TraitDiscovererAttribute(Type discovererType)662 {663 var result = Substitute.For<IReflectionAttributeInfo, InterfaceProxy<IReflectionAttributeInfo>>();664 result.Attribute.Returns(new TraitDiscovererAttribute(discovererType));665 result.GetConstructorArguments().Returns(new object[] { discovererType });666 return result;667 }668 public static IAttributeInfo TraitDiscovererAttribute<TDiscoverer>() =>669 TraitDiscovererAttribute(typeof(TDiscoverer));670 public static ITypeInfo TypeInfo(671 string? typeName = null,672 IMethodInfo[]? methods = null,673 IReflectionAttributeInfo[]? attributes = null,674 string? assemblyFileName = null)675 {676 var result = Substitute.For<ITypeInfo, InterfaceProxy<ITypeInfo>>();677 result.Name.Returns(typeName ?? "type:" + Guid.NewGuid().ToString("n"));678 result.GetMethods(false).ReturnsForAnyArgs(methods ?? new IMethodInfo[0]);679 var assemblyInfo = AssemblyInfo(assemblyFileName: assemblyFileName);680 result.Assembly.Returns(assemblyInfo);681 result.GetCustomAttributes("").ReturnsForAnyArgs(callInfo => LookupAttribute(callInfo.Arg<string>(), attributes));682 return result;683 }684 public static XunitTestCase XunitTestCase<TClassUnderTest>(685 string methodName,686 ITestCollection? collection = null,687 object[]? testMethodArguments = null,688 IMessageSink? diagnosticMessageSink = null)689 {690 var method = TestMethod(typeof(TClassUnderTest), methodName, collection);...

Full Screen

Full Screen

XunitTestFrameworkDiscovererTests.cs

Source:XunitTestFrameworkDiscovererTests.cs Github

copy

Full Screen

...74 {75 [Fact]76 public static async ValueTask RequestsPublicAndPrivateMethodsFromType()77 {78 var typeInfo = Mocks.TypeInfo();79 var testClass = Mocks.TestClass(typeInfo);80 var discoverer = TestableXunitTestFrameworkDiscoverer.Create();81 await discoverer.FindTestsForType(testClass);82 typeInfo.Received(1).GetMethods(includePrivateMethods: true);83 }84 [Fact]85 public static async ValueTask TestMethodWithTooManyFactAttributes_ReturnsExecutionErrorTestCase()86 {87 var testClass = Mocks.TestClass<ClassWithTooManyFactAttributesOnTestMethod>();88 var discoverer = TestableXunitTestFrameworkDiscoverer.Create();89 await discoverer.FindTestsForType(testClass);90 var testCase = Assert.Single(discoverer.FindTestsForType_TestCases);91 var errorTestCase = Assert.IsType<ExecutionErrorTestCase>(testCase);92 Assert.Equal($"Test method '{typeof(ClassWithTooManyFactAttributesOnTestMethod).FullName}.{nameof(ClassWithTooManyFactAttributesOnTestMethod.TestMethod)}' has multiple [Fact]-derived attributes", errorTestCase.ErrorMessage);93 }94 class ClassWithTooManyFactAttributesOnTestMethod95 {96 [Fact]97 [Theory]98 public void TestMethod() { }99 }100 [Fact]101 public static async ValueTask DoesNotDiscoverNonFactDecoratedTestMethod()102 {103 var testClass = Mocks.TestClass<ClassWithNoTests>();104 var discoverer = TestableXunitTestFrameworkDiscoverer.Create();105 await discoverer.FindTestsForType(testClass);106 Assert.Empty(discoverer.FindTestsForType_TestCases);107 }108 class ClassWithNoTests109 {110 public void TestMethod() { }111 }112 [Fact]113 public static async ValueTask DiscoversFactDecoratedTestMethod()114 {115 var testClass = Mocks.TestClass<ClassWithOneTest>();116 var discoverer = TestableXunitTestFrameworkDiscoverer.Create();117 await discoverer.FindTestsForType(testClass);118 var testCase = Assert.Single(discoverer.FindTestsForType_TestCases);119 Assert.IsType<XunitTestCase>(testCase);120 Assert.Equal($"{typeof(ClassWithOneTest).FullName}.{nameof(ClassWithOneTest.TestMethod)}", testCase.TestCaseDisplayName);121 }122 class ClassWithOneTest123 {124 [Fact]125 public void TestMethod() { }126 }127 [Fact]128 public static async void Theory_WithPreEnumeration_ReturnsOneTestCasePerDataRecord()129 {130 var testClass = Mocks.TestClass<TheoryWithInlineData>();131 var discoverer = TestableXunitTestFrameworkDiscoverer.Create();132 var discoveryOptions = _TestFrameworkOptions.ForDiscovery(preEnumerateTheories: true);133 await discoverer.FindTestsForType(testClass, discoveryOptions);134 Assert.Collection(135 discoverer.FindTestsForType_TestCases.Select(t => t.TestCaseDisplayName).OrderBy(x => x),136 displayName => Assert.Equal($"{typeof(TheoryWithInlineData).FullName}.{nameof(TheoryWithInlineData.TheoryMethod)}(value: \"Hello world\")", displayName),137 displayName => Assert.Equal($"{typeof(TheoryWithInlineData).FullName}.{nameof(TheoryWithInlineData.TheoryMethod)}(value: 42)", displayName)138 );139 }140 [Fact]141 public static async void Theory_WithoutPreEnumeration_ReturnsOneTestCase()142 {143 var testClass = Mocks.TestClass<TheoryWithInlineData>();144 var discoverer = TestableXunitTestFrameworkDiscoverer.Create();145 var discoveryOptions = _TestFrameworkOptions.ForDiscovery(preEnumerateTheories: false);146 await discoverer.FindTestsForType(testClass, discoveryOptions);147 var testCase = Assert.Single(discoverer.FindTestsForType_TestCases);148 Assert.Equal($"{typeof(TheoryWithInlineData).FullName}.{nameof(TheoryWithInlineData.TheoryMethod)}", testCase.TestCaseDisplayName);149 }150 class TheoryWithInlineData151 {152 [Theory]153 [InlineData("Hello world")]154 [InlineData(42)]155 public static void TheoryMethod(object value) { }156 }157 [Fact]158 public static async void AssemblyWithMultiLevelHierarchyWithFactOverridenInNonImmediateDerivedClass_ReturnsOneTestCase()159 {160 var testClass = Mocks.TestClass<Child>();161 var discoverer = TestableXunitTestFrameworkDiscoverer.Create();162 await discoverer.FindTestsForType(testClass);163 var testCase = Assert.Single(discoverer.FindTestsForType_TestCases);164 Assert.Equal($"{typeof(Child).FullName}.{nameof(GrandParent.FactOverridenInNonImmediateDerivedClass)}", testCase.TestCaseDisplayName);165 }166 public abstract class GrandParent167 {168 [Fact]169 public virtual void FactOverridenInNonImmediateDerivedClass()170 {171 Assert.True(true);172 }173 }174 public abstract class Parent : GrandParent { }175 public class Child : Parent176 {177 public override void FactOverridenInNonImmediateDerivedClass()178 {179 base.FactOverridenInNonImmediateDerivedClass();180 Assert.False(false);181 }182 }183 }184 public static class TestCollectionFactory185 {186 [Fact]187 public static void DefaultTestCollectionFactory()188 {189 var discoverer = TestableXunitTestFrameworkDiscoverer.Create();190 Assert.IsType<CollectionPerClassTestCollectionFactory>(discoverer.TestCollectionFactory);191 }192 [Theory(DisableDiscoveryEnumeration = true)]193 [InlineData(CollectionBehavior.CollectionPerAssembly, typeof(CollectionPerAssemblyTestCollectionFactory))]194 [InlineData(CollectionBehavior.CollectionPerClass, typeof(CollectionPerClassTestCollectionFactory))]195 public static void AssemblyAttributeOverride(196 CollectionBehavior behavior,197 Type expectedFactoryType)198 {199 var behaviorAttribute = Mocks.CollectionBehaviorAttribute(behavior);200 var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute });201 var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly);202 Assert.IsType(expectedFactoryType, discoverer.TestCollectionFactory);203 }204 [Fact]205 public static void ValidCustomFactory()206 {207 var behaviorAttribute = Mocks.CollectionBehaviorAttribute<CustomTestCollectionFactory>();208 var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute });209 var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly);210 Assert.IsType<CustomTestCollectionFactory>(discoverer.TestCollectionFactory);211 }212 [Fact]213 public static void InvalidCustomFactoryFallsBackToDefault()214 {215 var spyMessageSink = SpyMessageSink.Capture();216 TestContext.Current!.DiagnosticMessageSink = spyMessageSink;217 var behaviorAttribute = Mocks.CollectionBehaviorAttribute<object>();218 var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute });219 var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly);220 Assert.IsType<CollectionPerClassTestCollectionFactory>(discoverer.TestCollectionFactory);221 var message = Assert.Single(spyMessageSink.Messages);222 var diagMessage = Assert.IsType<_DiagnosticMessage>(message);223 Assert.Equal("Test collection factory type 'System.Object' does not implement IXunitTestCollectionFactory", diagMessage.Message);224 }225 }226 public static class TestFrameworkDisplayName227 {228 [Fact]229 public static void Defaults()230 {231 var discoverer = TestableXunitTestFrameworkDiscoverer.Create();232 Assert.Matches(@"xUnit.net v3 \d+\.\d+\.\d+(-pre\.\d+(-dev)?(\+[0-9a-f]+)?)? \[collection-per-class, parallel\]", discoverer.TestFrameworkDisplayName);233 }234 [Fact]235 public static void CollectionPerAssembly()236 {237 var behaviorAttribute = Mocks.CollectionBehaviorAttribute(CollectionBehavior.CollectionPerAssembly);238 var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute });239 var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly);240 Assert.Matches(@"xUnit.net v3 \d+\.\d+\.\d+(-pre\.\d+(-dev)?(\+[0-9a-f]+)?)? \[collection-per-assembly, parallel\]", discoverer.TestFrameworkDisplayName);241 }242 [Fact]243 public static void CustomCollectionFactory()244 {245 var behaviorAttribute = Mocks.CollectionBehaviorAttribute<CustomTestCollectionFactory>();246 var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute });247 var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly);248 Assert.Matches(@"xUnit.net v3 \d+\.\d+\.\d+(-pre\.\d+(-dev)?(\+[0-9a-f]+)?)? \[my-custom-test-collection-factory, parallel\]", discoverer.TestFrameworkDisplayName);249 }250 [Fact]251 public static void NonParallel()252 {253 var behaviorAttribute = Mocks.CollectionBehaviorAttribute(disableTestParallelization: true);254 var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute });255 var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly);256 Assert.Matches(@"xUnit.net v3 \d+\.\d+\.\d+(-pre\.\d+(-dev)?(\+[0-9a-f]+)?)? \[collection-per-class, non-parallel\]", discoverer.TestFrameworkDisplayName);257 }258 }259 class ClassWithSingleTest260 {261 [Fact]262 public static void TestMethod() { }263 }264 class CustomTestCollectionFactory : IXunitTestCollectionFactory265 {266 public CustomTestCollectionFactory(_ITestAssembly testAssembly)267 { }268 public string DisplayName => "my-custom-test-collection-factory";269 public _ITestCollection Get(_ITypeInfo testClass) => throw new NotImplementedException();270 }271 class TestableXunitTestFrameworkDiscoverer : XunitTestFrameworkDiscoverer272 {273 public List<_ITestCaseMetadata> FindTestsForType_TestCases = new();274 TestableXunitTestFrameworkDiscoverer(275 _IAssemblyInfo assemblyInfo,276 IXunitTestCollectionFactory? collectionFactory)277 : base(assemblyInfo, configFileName: null, collectionFactory)278 {279 TestAssembly = Mocks.TestAssembly(assemblyInfo.AssemblyPath, uniqueID: "asm-id");280 }281 public new _IAssemblyInfo AssemblyInfo => base.AssemblyInfo;282 public override _ITestAssembly TestAssembly { get; }283 public new ValueTask<_ITestClass> CreateTestClass(_ITypeInfo @class) =>284 base.CreateTestClass(@class);285 public ValueTask<bool> FindTestsForType(286 _ITestClass testClass,287 _ITestFrameworkDiscoveryOptions? discoveryOptions = null) =>288 base.FindTestsForType(289 testClass,290 discoveryOptions ?? _TestFrameworkOptions.ForDiscovery(preEnumerateTheories: true),291 testCase =>292 {293 FindTestsForType_TestCases.Add(testCase);294 return new(true);295 }296 );297 protected sealed override bool IsValidTestClass(_ITypeInfo type) =>298 base.IsValidTestClass(type);299 public static TestableXunitTestFrameworkDiscoverer Create(300 _IAssemblyInfo? assembly = null,301 IXunitTestCollectionFactory? collectionFactory = null) =>302 new(assembly ?? Mocks.AssemblyInfo(), collectionFactory);303 }304}...

Full Screen

Full Screen

Mocks.TestCases.cs

Source:Mocks.TestCases.cs Github

copy

Full Screen

...24 return result;25 }26 public static _ITestAssembly TestAssembly(27 string? assemblyFileName,28 _ITypeInfo[]? types = null,29 _IReflectionAttributeInfo[]? assemblyAttributes = null,30 string? configFileName = null,31 Version? version = null,32 string? uniqueID = null) =>33 TestAssembly(AssemblyInfo(types, assemblyAttributes, assemblyFileName), configFileName, version, uniqueID);34 public static _ITestAssembly TestAssembly(35 Assembly assembly,36 string? configFileName = null,37 Version? version = null,38 string? uniqueID = null) =>39 TestAssembly(Reflector.Wrap(assembly), configFileName, version, uniqueID);40 public static _ITestAssembly TestAssembly(41 _IAssemblyInfo? assemblyInfo = null,42 string? configFileName = null,43 Version? version = null,44 string? uniqueID = null)45 {46 assemblyInfo ??= AssemblyInfo();47 uniqueID ??= "assembly-id";48 version ??= new Version(2112, 42, 2600);49 var result = Substitute.For<_ITestAssembly, InterfaceProxy<_ITestAssembly>>();50 result.Assembly.Returns(assemblyInfo);51 result.ConfigFileName.Returns(configFileName);52 result.UniqueID.Returns(uniqueID);53 result.Version.Returns(version);54 return result;55 }56 public static _ITestCase TestCase<TClassUnderTest>(57 string methodName,58 string? displayName = null,59 string? skipReason = null,60 IReadOnlyDictionary<string, IReadOnlyList<string>>? traits = null,61 string? fileName = null,62 int? lineNumber = null,63 string? uniqueID = null) =>64 TestCase(TestMethod<TClassUnderTest>(methodName), displayName, skipReason, traits, fileName, lineNumber, uniqueID);65 public static _ITestCase TestCase(66 string typeName,67 string methodName,68 string? displayName = null,69 string? skipReason = null,70 IReadOnlyDictionary<string, IReadOnlyList<string>>? traits = null,71 string? fileName = null,72 int? lineNumber = null,73 string? uniqueID = null) =>74 TestCase(TestMethod(typeName, methodName), displayName, skipReason, traits, fileName, lineNumber, uniqueID);75 public static _ITestCase TestCase(76 _ITestMethod? testMethod = null,77 string? displayName = null,78 string? skipReason = null,79 IReadOnlyDictionary<string, IReadOnlyList<string>>? traits = null,80 string? fileName = null,81 int? lineNumber = null,82 string? uniqueID = null)83 {84 testMethod ??= TestMethod();85 displayName ??= $"{testMethod.TestClass.Class.Name}.{testMethod.Method.Name}";86 traits ??= GetTraits(testMethod.Method);87 uniqueID ??= "case-id";88 var testCollection = testMethod.TestClass.TestCollection;89 var testClass = testMethod.TestClass;90 var result = Substitute.For<_ITestCase, InterfaceProxy<_ITestCase>>();91 result.TestCaseDisplayName.Returns(displayName);92 result.SkipReason.Returns(skipReason);93 result.SourceFilePath.Returns(fileName);94 result.SourceLineNumber.Returns(lineNumber);95 result.TestCollection.Returns(testCollection);96 result.TestClass.Returns(testClass);97 result.TestMethod.Returns(testMethod);98 result.Traits.Returns(traits);99 result.UniqueID.Returns(uniqueID);100 return result;101 }102 public static _ITestClass TestClass<TClassUnderTest>(103 _ITestCollection? collection = null,104 string? uniqueID = null) =>105 TestClass(106 TypeInfo<TClassUnderTest>(),107 collection,108 uniqueID109 );110 public static _ITestClass TestClass(111 string? typeName,112 _IMethodInfo[]? methods = null,113 _IReflectionAttributeInfo[]? attributes = null,114 _ITypeInfo? baseType = null,115 _ITestCollection? collection = null,116 string? uniqueID = null) =>117 TestClass(TypeInfo(typeName, methods, attributes, baseType), collection, uniqueID);118 public static _ITestClass TestClass(119 _ITypeInfo? typeInfo = null,120 _ITestCollection? collection = null,121 string? uniqueID = null)122 {123 typeInfo ??= TypeInfo();124 collection ??= TestCollection();125 uniqueID ??= "class-id";126 var result = Substitute.For<_ITestClass, InterfaceProxy<_ITestClass>>();127 result.Class.Returns(typeInfo);128 result.TestCollection.Returns(collection);129 result.UniqueID.Returns(uniqueID);130 return result;131 }132 public static _ITestCollection TestCollection(133 Assembly assembly,134 _ITypeInfo? definition = null,135 string? displayName = null,136 string? uniqueID = null) =>137 TestCollection(TestAssembly(assembly), definition, displayName, uniqueID);138 public static _ITestCollection TestCollection(139 _ITestAssembly? assembly = null,140 _ITypeInfo? definition = null,141 string? displayName = null,142 string? uniqueID = null)143 {144 assembly ??= TestAssembly();145 displayName ??= "Mock test collection";146 uniqueID ??= "collection-id";147 var result = Substitute.For<_ITestCollection, InterfaceProxy<_ITestCollection>>();148 result.CollectionDefinition.Returns(definition);149 result.DisplayName.Returns(displayName);150 result.TestAssembly.Returns(assembly);151 result.UniqueID.Returns(uniqueID);152 return result;153 }154 public static _ITestMethod TestMethod(...

Full Screen

Full Screen

TestFrameworkDiscovererTests.cs

Source:TestFrameworkDiscovererTests.cs Github

copy

Full Screen

...23 public async ValueTask ExceptionDuringFindTestsForType_ReportsExceptionAsDiagnosticMessage()24 {25 var spy = SpyMessageSink.Capture();26 TestContext.Current!.DiagnosticMessageSink = spy;27 var mockType = Mocks.TypeInfo("MockType");28 var discoverer = TestableTestFrameworkDiscoverer.Create(mockType);29 discoverer.FindTestsForType_Exception = new DivideByZeroException();30 await discoverer.Find();31 var message = Assert.Single(spy.Messages.OfType<_DiagnosticMessage>());32 Assert.StartsWith($"Exception during discovery:{Environment.NewLine}System.DivideByZeroException: Attempted to divide by zero.", message.Message);33 }34 [Fact]35 public async void TestContextVisibility()36 {37 var mockType = Mocks.TypeInfo("MockType");38 var discoverer = TestableTestFrameworkDiscoverer.Create(mockType);39 await discoverer.Find();40 var context = discoverer.FindTestsForType_Context;41 Assert.NotNull(context);42 Assert.Equal(TestEngineStatus.Discovering, context.TestAssemblyStatus);43 Assert.Equal(TestPipelineStage.Discovery, context.PipelineStage);44 }45 public class ByAssembly46 {47 [Fact]48 public static async ValueTask NoTypes()49 {50 var discoverer = TestableTestFrameworkDiscoverer.Create();51 await discoverer.Find();52 Assert.Empty(discoverer.FindTestsForType_TestClasses);53 }54 [Fact]55 public static async ValueTask RequestsPublicTypesFromAssembly()56 {57 var framework = TestableTestFrameworkDiscoverer.Create();58 await framework.Find();59 framework.AssemblyInfo.Received(1).GetTypes(includePrivateTypes: false);60 }61 [Fact]62 public static async ValueTask IncludesNonAbstractTypes()63 {64 var objectTypeInfo = Reflector.Wrap(typeof(object));65 var intTypeInfo = Reflector.Wrap(typeof(int));66 var discoverer = TestableTestFrameworkDiscoverer.Create(objectTypeInfo, intTypeInfo);67 await discoverer.Find();68 Assert.Collection(69 discoverer.FindTestsForType_TestClasses.Select(c => c.Class.Name).OrderBy(x => x),70 typeName => Assert.Equal(typeof(int).FullName, typeName), // System.Int3271 typeName => Assert.Equal(typeof(object).FullName, typeName) // System.Object72 );73 }74 [Fact]75 public static async ValueTask ExcludesAbstractTypes()76 {77 var abstractClassTypeInfo = Reflector.Wrap(typeof(AbstractClass));78 var discoverer = TestableTestFrameworkDiscoverer.Create(abstractClassTypeInfo);79 await discoverer.Find();80 Assert.Empty(discoverer.FindTestsForType_TestClasses);81 }82 }83 public class ByTypes84 {85 [Fact]86 public static async ValueTask IncludesNonAbstractTypes()87 {88 var discoverer = TestableTestFrameworkDiscoverer.Create();89 await discoverer.Find(types: new[] { typeof(object) });90 var testClass = Assert.Single(discoverer.FindTestsForType_TestClasses);91 Assert.Equal(typeof(object).FullName, testClass.Class.Name);92 }93 [Fact]94 public static async ValueTask ExcludesAbstractTypes()95 {96 var discoverer = TestableTestFrameworkDiscoverer.Create();97 await discoverer.Find(types: new[] { typeof(AbstractClass) });98 Assert.Empty(discoverer.FindTestsForType_TestClasses);99 }100 }101 public class WithCulture102 {103 readonly _ITypeInfo mockType = Mocks.TypeInfo("MockType");104 [Fact]105 public async ValueTask DefaultCultureIsCurrentCulture()106 {107 CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US");108 var discoverer = TestableTestFrameworkDiscoverer.Create(mockType);109 var discoveryOptions = _TestFrameworkOptions.ForDiscovery(culture: null);110 await discoverer.Find(discoveryOptions);111 Assert.NotNull(discoverer.FindTestsForType_CurrentCulture);112 Assert.Equal("en-US", discoverer.FindTestsForType_CurrentCulture.Name);113 }114 [Fact]115 public async ValueTask EmptyStringIsInvariantCulture()116 {117 CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US");118 var discoverer = TestableTestFrameworkDiscoverer.Create(mockType);119 var discoveryOptions = _TestFrameworkOptions.ForDiscovery(culture: string.Empty);120 await discoverer.Find(discoveryOptions);121 Assert.NotNull(discoverer.FindTestsForType_CurrentCulture);122 Assert.Equal(string.Empty, discoverer.FindTestsForType_CurrentCulture.Name);123 }124 [Fact]125 public async ValueTask CustomCultureViaDiscoveryOptions()126 {127 CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US");128 var discoverer = TestableTestFrameworkDiscoverer.Create(mockType);129 var discoveryOptions = _TestFrameworkOptions.ForDiscovery(culture: "en-GB");130 await discoverer.Find(discoveryOptions);131 Assert.NotNull(discoverer.FindTestsForType_CurrentCulture);132 Assert.Equal("en-GB", discoverer.FindTestsForType_CurrentCulture.Name);133 }134 }135 abstract class AbstractClass136 {137 [Fact]138 public static void ATestNotToBeRun() { }139 }140 }141 class TestableTestFrameworkDiscoverer : TestFrameworkDiscoverer<_ITestCase>142 {143 public TestContext? FindTestsForType_Context;144 public CultureInfo? FindTestsForType_CurrentCulture;145 public Exception? FindTestsForType_Exception = null;146 public readonly List<_ITestClass> FindTestsForType_TestClasses = new();147 TestableTestFrameworkDiscoverer(_IAssemblyInfo assemblyInfo) :148 base(assemblyInfo)149 {150 TestAssembly = Mocks.TestAssembly(assemblyInfo.AssemblyPath, uniqueID: "asm-id");151 }152 public new _IAssemblyInfo AssemblyInfo => base.AssemblyInfo;153 public override _ITestAssembly TestAssembly { get; }154 public override string TestFrameworkDisplayName => "testable-test-framework";155 protected override ValueTask<_ITestClass> CreateTestClass(_ITypeInfo @class) =>156 new(Mocks.TestClass(@class));157 public ValueTask Find(158 _ITestFrameworkDiscoveryOptions? discoveryOptions = null,159 Type[]? types = null) =>160 Find(161 testCase => new(true),162 discoveryOptions ?? _TestFrameworkOptions.ForDiscovery(),163 types164 );165 protected override ValueTask<bool> FindTestsForType(166 _ITestClass testClass,167 _ITestFrameworkDiscoveryOptions discoveryOptions,168 Func<_ITestCase, ValueTask<bool>> discoveryCallback)169 {170 FindTestsForType_Context = TestContext.Current;171 FindTestsForType_CurrentCulture = CultureInfo.CurrentCulture;172 FindTestsForType_TestClasses.Add(testClass);173 if (FindTestsForType_Exception != null)174 throw FindTestsForType_Exception;175 return new(true);176 }177 public static TestableTestFrameworkDiscoverer Create(params _ITypeInfo[] types) =>178 new(Mocks.AssemblyInfo(types));179 }180}...

Full Screen

Full Screen

Mocks.Reflection.cs

Source:Mocks.Reflection.cs Github

copy

Full Screen

...11 // This file contains mocks of reflection abstractions.12 public static partial class Mocks13 {14 public static _IAssemblyInfo AssemblyInfo(15 _ITypeInfo[]? types = null,16 _IReflectionAttributeInfo[]? attributes = null,17 string? assemblyFileName = null)18 {19 attributes ??= EmptyAttributeInfos;20 assemblyFileName ??= $"assembly-{Guid.NewGuid():n}.dll";21 var result = Substitute.For<_IAssemblyInfo, InterfaceProxy<_IAssemblyInfo>>();22 result.AssemblyPath.Returns(assemblyFileName);23 result.Name.Returns(Path.GetFileNameWithoutExtension(assemblyFileName));24 result.GetCustomAttributes("").ReturnsForAnyArgs(callInfo => LookupAttribute(callInfo.Arg<string>(), attributes));25 result.GetType("").ReturnsForAnyArgs(types?.FirstOrDefault());26 result.GetTypes(true).ReturnsForAnyArgs(types ?? new _ITypeInfo[0]);27 return result;28 }29 public static _IReflectionAssemblyInfo AssemblyInfo(Assembly assembly) =>30 Reflector.Wrap(assembly);31 static IReadOnlyDictionary<string, IReadOnlyList<string>> GetTraits(_IMethodInfo method)32 {33 var result = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);34 foreach (var traitAttribute in method.GetCustomAttributes(typeof(TraitAttribute)))35 {36 var ctorArgs = traitAttribute.GetConstructorArguments().ToList();37 result.Add((string)ctorArgs[0]!, (string)ctorArgs[1]!);38 }39 return result.ToReadOnly();40 }41 public static _IReflectionMethodInfo MethodInfo<TClass>(string methodName) =>42 Guard.ArgumentNotNull(43 $"Could not find method '{methodName}' on '{typeof(TClass).FullName}'",44 Reflector.Wrap(typeof(TClass).GetMethod(methodName)),45 nameof(methodName)46 );47 public static _IMethodInfo MethodInfo(48 string? methodName = null,49 _IReflectionAttributeInfo[]? attributes = null,50 _IParameterInfo[]? parameters = null,51 _ITypeInfo? type = null,52 _ITypeInfo? returnType = null,53 _ITypeInfo[]? genericArguments = null,54 bool isAbstract = false,55 bool isGenericMethodDefinition = false,56 bool isPublic = true,57 bool isStatic = false)58 {59 methodName ??= $"method_{Guid.NewGuid():n}";60 attributes ??= EmptyAttributeInfos;61 parameters ??= EmptyParameterInfos;62 genericArguments ??= EmptyTypeInfos;63 var result = Substitute.For<_IMethodInfo, InterfaceProxy<_IMethodInfo>>();64 result.IsAbstract.Returns(isAbstract);65 result.IsGenericMethodDefinition.Returns(isGenericMethodDefinition);66 result.IsPublic.Returns(isPublic);67 result.IsStatic.Returns(isStatic);68 result.Name.Returns(methodName);69 result.ReturnType.Returns(returnType);70 result.Type.Returns(type);71 result.GetCustomAttributes("").ReturnsForAnyArgs(callInfo => LookupAttribute(callInfo.Arg<string>(), attributes));72 result.GetGenericArguments().Returns(genericArguments);73 result.GetParameters().Returns(parameters);74 // Difficult to simulate MakeGenericMethod here, so better to throw then just return null75 // and if any tests need this, then can override the substitution.76 result.MakeGenericMethod().WhenForAnyArgs(_ => throw new NotImplementedException());77 return result;78 }79 public static _IParameterInfo ParameterInfo(80 string name,81 _ITypeInfo? parameterType = null)82 {83 parameterType ??= TypeObject;84 var result = Substitute.For<_IParameterInfo, InterfaceProxy<_IParameterInfo>>();85 result.Name.Returns(name);86 result.ParameterType.Returns(parameterType);87 return result;88 }89 public static _IReflectionTypeInfo TypeInfo<TClass>() =>90 Reflector.Wrap(typeof(TClass));91 public static _ITypeInfo TypeInfo(92 string? name = null,93 _IMethodInfo[]? methods = null,94 _IReflectionAttributeInfo[]? attributes = null,95 _ITypeInfo? baseType = null,96 _ITypeInfo[]? interfaces = null,97 bool isAbstract = false,98 bool isGenericParameter = false,99 bool isGenericType = false,100 bool isValueType = false,101 _ITypeInfo[]? genericArguments = null,102 string? assemblyFileName = null)103 {104 baseType ??= TypeObject;105 name ??= $"type_{Guid.NewGuid():n}";106 methods ??= EmptyMethodInfos;107 interfaces ??= EmptyTypeInfos;108 genericArguments ??= EmptyTypeInfos;109 var assemblyInfo = AssemblyInfo(assemblyFileName: assemblyFileName);110 var result = Substitute.For<_ITypeInfo, InterfaceProxy<_ITypeInfo>>();111 result.Assembly.Returns(assemblyInfo);112 result.BaseType.Returns(baseType);113 result.IsAbstract.Returns(isAbstract);114 result.IsGenericParameter.Returns(isGenericParameter);115 result.IsGenericType.Returns(isGenericType);116 result.IsValueType.Returns(isValueType);117 result.Name.Returns(name);118 result.GetCustomAttributes("").ReturnsForAnyArgs(callInfo => LookupAttribute(callInfo.Arg<string>(), attributes));119 result.GetGenericArguments().Returns(genericArguments);120 result.GetMethod("", false).ReturnsForAnyArgs(callInfo => methods.FirstOrDefault(m => m.Name == callInfo.Arg<string>()));121 result.GetMethods(false).ReturnsForAnyArgs(methods);122 return result;123 }124 }...

Full Screen

Full Screen

CollectionPerClassTestCollectionFactoryTests.cs

Source:CollectionPerClassTestCollectionFactoryTests.cs Github

copy

Full Screen

...5{6 [Fact]7 public static void DefaultCollectionBehaviorIsCollectionPerClass()8 {9 var type1 = Mocks.TypeInfo("FullyQualified.Type.Number1");10 var type2 = Mocks.TypeInfo("FullyQualified.Type.Number2");11 var assembly = Mocks.TestAssembly(@"C:\Foo\bar.dll");12 var factory = new CollectionPerClassTestCollectionFactory(assembly);13 var result1 = factory.Get(type1);14 var result2 = factory.Get(type2);15 Assert.NotSame(result1, result2);16 Assert.Equal("Test collection for FullyQualified.Type.Number1", result1.DisplayName);17 Assert.Equal("Test collection for FullyQualified.Type.Number2", result2.DisplayName);18 Assert.Null(result1.CollectionDefinition);19 Assert.Null(result2.CollectionDefinition);20 }21 [Fact]22 public static void ClassesDecoratedWithSameCollectionNameAreInSameTestCollection()23 {24 var attr = Mocks.CollectionAttribute("My Collection");25 var type1 = Mocks.TypeInfo("type1", attributes: new[] { attr });26 var type2 = Mocks.TypeInfo("type2", attributes: new[] { attr });27 var assembly = Mocks.TestAssembly(@"C:\Foo\bar.dll");28 var factory = new CollectionPerClassTestCollectionFactory(assembly);29 var result1 = factory.Get(type1);30 var result2 = factory.Get(type2);31 Assert.Same(result1, result2);32 Assert.Equal("My Collection", result1.DisplayName);33 }34 [Fact]35 public static void ClassesWithDifferentCollectionNamesHaveDifferentCollectionObjects()36 {37 var type1 = Mocks.TypeInfo("type1", attributes: new[] { Mocks.CollectionAttribute("Collection 1") });38 var type2 = Mocks.TypeInfo("type2", attributes: new[] { Mocks.CollectionAttribute("Collection 2") });39 var assembly = Mocks.TestAssembly(@"C:\Foo\bar.dll");40 var factory = new CollectionPerClassTestCollectionFactory(assembly);41 var result1 = factory.Get(type1);42 var result2 = factory.Get(type2);43 Assert.NotSame(result1, result2);44 Assert.Equal("Collection 1", result1.DisplayName);45 Assert.Equal("Collection 2", result2.DisplayName);46 }47 [Fact]48 public static void ExplicitlySpecifyingACollectionWithTheSameNameAsAnImplicitWorks()49 {50 var type1 = Mocks.TypeInfo("type1");51 var type2 = Mocks.TypeInfo("type2", attributes: new[] { Mocks.CollectionAttribute("Test collection for type1") });52 var assembly = Mocks.TestAssembly(@"C:\Foo\bar.dll");53 var factory = new CollectionPerClassTestCollectionFactory(assembly);54 var result1 = factory.Get(type1);55 var result2 = factory.Get(type2);56 Assert.Same(result1, result2);57 Assert.Equal("Test collection for type1", result1.DisplayName);58 }59 [Fact]60 public static void UsingTestCollectionDefinitionSetsTypeInfo()61 {62 var testType = Mocks.TypeInfo("type", attributes: new[] { Mocks.CollectionAttribute("This is a test collection") });63 var collectionDefinitionType = Mocks.TypeInfo("collectionDefinition", attributes: new[] { Mocks.CollectionDefinitionAttribute("This is a test collection") });64 var assembly = Mocks.TestAssembly(@"C:\Foo\bar.dll", types: new[] { collectionDefinitionType });65 var factory = new CollectionPerClassTestCollectionFactory(assembly);66 var result = factory.Get(testType);67 Assert.Same(collectionDefinitionType, result.CollectionDefinition);68 }69 [Fact]70 public static void MultiplyDeclaredCollectionsRaisesEnvironmentalWarning()71 {72 var spy = SpyMessageSink.Capture();73 TestContext.Current!.DiagnosticMessageSink = spy;74 var testType = Mocks.TypeInfo("type", attributes: new[] { Mocks.CollectionAttribute("This is a test collection") });75 var collectionDefinition1 = Mocks.TypeInfo("collectionDefinition1", attributes: new[] { Mocks.CollectionDefinitionAttribute("This is a test collection") });76 var collectionDefinition2 = Mocks.TypeInfo("collectionDefinition2", attributes: new[] { Mocks.CollectionDefinitionAttribute("This is a test collection") });77 var assembly = Mocks.TestAssembly(@"C:\Foo\bar.dll", types: new[] { collectionDefinition1, collectionDefinition2 });78 var factory = new CollectionPerClassTestCollectionFactory(assembly);79 factory.Get(testType);80 var msg = Assert.Single(spy.Messages.OfType<_DiagnosticMessage>().Select(m => m.Message));81 Assert.Equal("Multiple test collections declared with name 'This is a test collection': collectionDefinition1, collectionDefinition2", msg);82 }83}...

Full Screen

Full Screen

CollectionPerAssemblyTestCollectionFactoryTests.cs

Source:CollectionPerAssemblyTestCollectionFactoryTests.cs Github

copy

Full Screen

...6{7 [Fact]8 public static void ReturnsDefaultTestCollectionForUndecoratedTestClass()9 {10 var type1 = Mocks.TypeInfo("type1");11 var type2 = Mocks.TypeInfo("type2");12 var assemblyFileName = Path.DirectorySeparatorChar == '/' ? "/foo/bar.dll" : @"C:\Foo\bar.dll";13 var assembly = Mocks.TestAssembly(assemblyFileName);14 var factory = new CollectionPerAssemblyTestCollectionFactory(assembly);15 var result1 = factory.Get(type1);16 var result2 = factory.Get(type2);17 Assert.Same(result1, result2);18 Assert.Equal("Test collection for bar.dll", result1.DisplayName);19 }20 [Fact]21 public static void ClassesDecoratedWithSameCollectionNameAreInSameTestCollection()22 {23 var attr = Mocks.CollectionAttribute("My Collection");24 var type1 = Mocks.TypeInfo("type1", attributes: new[] { attr });25 var type2 = Mocks.TypeInfo("type2", attributes: new[] { attr });26 var assembly = Mocks.TestAssembly(@"C:\Foo\bar.dll");27 var factory = new CollectionPerAssemblyTestCollectionFactory(assembly);28 var result1 = factory.Get(type1);29 var result2 = factory.Get(type2);30 Assert.Same(result1, result2);31 Assert.Equal("My Collection", result1.DisplayName);32 }33 [Fact]34 public static void ClassesWithDifferentCollectionNamesHaveDifferentCollectionObjects()35 {36 var type1 = Mocks.TypeInfo("type1", attributes: new[] { Mocks.CollectionAttribute("Collection 1") });37 var type2 = Mocks.TypeInfo("type2", attributes: new[] { Mocks.CollectionAttribute("Collection 2") });38 var assembly = Mocks.TestAssembly(@"C:\Foo\bar.dll");39 var factory = new CollectionPerAssemblyTestCollectionFactory(assembly);40 var result1 = factory.Get(type1);41 var result2 = factory.Get(type2);42 Assert.NotSame(result1, result2);43 Assert.Equal("Collection 1", result1.DisplayName);44 Assert.Equal("Collection 2", result2.DisplayName);45 }46 [Fact]47 public static void UsingTestCollectionDefinitionSetsTypeInfo()48 {49 var testType = Mocks.TypeInfo("type", attributes: new[] { Mocks.CollectionAttribute("This is a test collection") });50 var collectionDefinitionType = Mocks.TypeInfo("collectionDefinition", attributes: new[] { Mocks.CollectionDefinitionAttribute("This is a test collection") });51 var assembly = Mocks.TestAssembly(@"C:\Foo\bar.dll", types: new[] { collectionDefinitionType });52 var factory = new CollectionPerAssemblyTestCollectionFactory(assembly);53 var result = factory.Get(testType);54 Assert.Same(collectionDefinitionType, result.CollectionDefinition);55 }56 [Fact]57 public static void MultiplyDeclaredCollectionsRaisesEnvironmentalWarning()58 {59 var spy = SpyMessageSink.Capture();60 TestContext.Current!.DiagnosticMessageSink = spy;61 var testType = Mocks.TypeInfo("type", attributes: new[] { Mocks.CollectionAttribute("This is a test collection") });62 var collectionDefinition1 = Mocks.TypeInfo("collectionDefinition1", attributes: new[] { Mocks.CollectionDefinitionAttribute("This is a test collection") });63 var collectionDefinition2 = Mocks.TypeInfo("collectionDefinition2", attributes: new[] { Mocks.CollectionDefinitionAttribute("This is a test collection") });64 var assembly = Mocks.TestAssembly(@"C:\Foo\bar.dll", types: new[] { collectionDefinition1, collectionDefinition2 });65 var factory = new CollectionPerAssemblyTestCollectionFactory(assembly);66 factory.Get(testType);67 var msg = Assert.Single(spy.Messages.OfType<_DiagnosticMessage>().Select(m => m.Message));68 Assert.Equal("Multiple test collections declared with name 'This is a test collection': collectionDefinition1, collectionDefinition2", msg);69 }70}...

Full Screen

Full Screen

ReflectionAbstractionExtensionsTests.cs

Source:ReflectionAbstractionExtensionsTests.cs Github

copy

Full Screen

...15 [Fact]16 public static void WhenUsingNonReflectionMethodInfo_MethodExists_ReturnsMethodInfo()17 {18#if BUILD_X8619 var typeInfo = Mocks.TypeInfo("ReflectionAbstractionExtensionsTests+ToRuntimeMethod", assemblyFileName: "xunit.v3.core.tests.x86.exe");20#else21 var typeInfo = Mocks.TypeInfo("ReflectionAbstractionExtensionsTests+ToRuntimeMethod", assemblyFileName: "xunit.v3.core.tests.exe");22#endif23 var methodInfo = Mocks.MethodInfo("WhenUsingNonReflectionMethodInfo_MethodExists_ReturnsMethodInfo", isStatic: true, type: typeInfo);24 var result = methodInfo.ToRuntimeMethod();25 Assert.NotNull(result);26 Assert.Same(typeof(ToRuntimeMethod).GetMethod("WhenUsingNonReflectionMethodInfo_MethodExists_ReturnsMethodInfo"), result);27 }28 [Fact]29 public static void WhenUsingNonReflectionMethodInfo_MethodDoesNotExist_ReturnsNull()30 {31 var typeInfo = Mocks.TypeInfo("ReflectionAbstractionExtensionsTests+ToRuntimeMethod", assemblyFileName: "xunit.v3.core.tests.exe");32 var methodInfo = Mocks.MethodInfo("UnknownMethod", isStatic: true, type: typeInfo);33 var result = methodInfo.ToRuntimeMethod();34 Assert.Null(result);35 }36 }37 public class ToRuntimeType38 {39 [Fact]40 public static void WhenUsingReflectionTypeInfo_ReturnsExistingType()41 {42 var typeInfo = Mocks.TypeInfo<ToRuntimeType>();43 var result = typeInfo.ToRuntimeType();44 Assert.NotNull(result);45 Assert.Same(typeInfo.Type, result);46 }47 [Fact]48 public static void WhenUsingNonReflectionTypeInfo_TypeExists_ReturnsType()49 {50#if BUILD_X8651 var typeInfo = Mocks.TypeInfo("ReflectionAbstractionExtensionsTests+ToRuntimeType", assemblyFileName: "xunit.v3.core.tests.x86.exe");52#else53 var typeInfo = Mocks.TypeInfo("ReflectionAbstractionExtensionsTests+ToRuntimeType", assemblyFileName: "xunit.v3.core.tests.exe");54#endif55 var result = typeInfo.ToRuntimeType();56 Assert.NotNull(result);57 Assert.Same(typeof(ToRuntimeType), result);58 }59 [Fact]60 public static void WhenUsingNonReflectionTypeInfo_TypeDoesNotExist_ReturnsNull()61 {62 var typeInfo = Mocks.TypeInfo("UnknownType", assemblyFileName: "xunit.v3.core.tests.exe");63 var result = typeInfo.ToRuntimeType();64 Assert.Null(result);65 }66 }67}...

Full Screen

Full Screen

TypeInfo

Using AI Code Generation

copy

Full Screen

1using Xunit.v3;2{3 {4 public void TestMethod()5 {6 var mock = Mocks.TypeInfo("MyType");7 Assert.Equal("MyType", mock.Name);8 }9 }10}11using Xunit.v3;12{13 {14 public void TestMethod()15 {16 var mock = Mocks.TypeInfo("MyType");17 Assert.Equal("MyType", mock.Name);18 }19 }20}21using Xunit.v3;22{23 {24 public void TestMethod()25 {26 var mock = Mocks.TypeInfo("MyType");27 Assert.Equal("MyType", mock.Name);28 }29 }30}31using Xunit.v3;32{33 {34 public void TestMethod()35 {36 var mock = Mocks.TypeInfo("MyType");37 Assert.Equal("MyType", mock.Name);38 }39 }40}41using Xunit.v3;42{43 {44 public void TestMethod()45 {46 var mock = Mocks.TypeInfo("MyType");47 Assert.Equal("MyType", mock.Name);48 }49 }50}51using Xunit.v3;52{53 {54 public void TestMethod()55 {56 var mock = Mocks.TypeInfo("MyType");57 Assert.Equal("MyType", mock.Name);58 }59 }60}61using Xunit.v3;62{63 {

Full Screen

Full Screen

TypeInfo

Using AI Code Generation

copy

Full Screen

1var typeInfo = Xunit.v3.Mocks.TypeInfo(type);2var typeInfo = Xunit.v3.Mocks.TypeInfo(type);3var typeInfo = Xunit.v3.Mocks.TypeInfo(type);4var typeInfo = Xunit.v3.Mocks.TypeInfo(type);5var typeInfo = Xunit.v3.Mocks.TypeInfo(type);6var typeInfo = Xunit.v3.Mocks.TypeInfo(type);7var typeInfo = Xunit.v3.Mocks.TypeInfo(type);8var typeInfo = Xunit.v3.Mocks.TypeInfo(type);9var typeInfo = Xunit.v3.Mocks.TypeInfo(type);10var typeInfo = Xunit.v3.Mocks.TypeInfo(type);11var typeInfo = Xunit.v3.Mocks.TypeInfo(type);

Full Screen

Full Screen

TypeInfo

Using AI Code Generation

copy

Full Screen

1var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));2var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));3var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));4var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));5var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));6var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));7var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));8var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));9var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));10var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));11var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));12var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));13var typeInfo = Xunit.v3.Mocks.TypeInfo(typeof(2));

Full Screen

Full Screen

TypeInfo

Using AI Code Generation

copy

Full Screen

1using Xunit;2using Xunit.v3;3{4 {5 public void Test()6 {7 var obj = new object();8 var type = Xunit.v3.Mocks.TypeInfo(obj.GetType());9 Assert.Equal("System.Object", type.FullName);10 }11 }12}13using Xunit.v3;14using Xunit;15using Xunit.v3;16{17 {18 public void Test()19 {20 var obj = new object();21 var type = Xunit.v3.Mocks.TypeInfo(obj.GetType());22 Assert.Equal("System.Object", type.FullName);23 }24 }25}26public static ITypeInfo TypeInfo(this System.Type type)27{28 return new Xunit.v3.Mocks.TypeInfo(type);29}30using Xunit;31using Xunit.v3;32{33 {34 public void Test()35 {36 var obj = new object();37 var type = Xunit.v3.Mocks.TypeInfo(obj.GetType());38 Assert.Equal("System.Object", type.FullName);39 }40 }41}42public static ITypeInfo TypeInfo(this System.Type type)43{

Full Screen

Full Screen

TypeInfo

Using AI Code Generation

copy

Full Screen

1var typeInfo = Xunit.v3.Mocks.TypeInfo("MyType", "MyAssembly", "MyNamespace");2var assembly = Xunit.v3.Mocks.AssemblyInfo(typeInfo);3var typeInfo = Xunit.v3.Mocks.TypeInfo("MyType", "MyAssembly", "MyNamespace");4var assembly = Xunit.v3.Mocks.AssemblyInfo(typeInfo);5var typeInfo = Xunit.v3.Mocks.TypeInfo("MyType", "MyAssembly", "MyNamespace");6var assembly = Xunit.v3.Mocks.AssemblyInfo(typeInfo);7var typeInfo = Xunit.v3.Mocks.TypeInfo("MyType", "MyAssembly", "MyNamespace");8var assembly = Xunit.v3.Mocks.AssemblyInfo(typeInfo);9var typeInfo = Xunit.v3.Mocks.TypeInfo("MyType", "MyAssembly", "MyNamespace");10var assembly = Xunit.v3.Mocks.AssemblyInfo(typeInfo);11var typeInfo = Xunit.v3.Mocks.TypeInfo("MyType", "MyAssembly", "MyNamespace");12var assembly = Xunit.v3.Mocks.AssemblyInfo(typeInfo);13var typeInfo = Xunit.v3.Mocks.TypeInfo("MyType", "MyAssembly", "MyNamespace");14var assembly = Xunit.v3.Mocks.AssemblyInfo(typeInfo);15var typeInfo = Xunit.v3.Mocks.TypeInfo("MyType", "MyAssembly",

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