protected override void CreateCollectionFixture(Type fixtureType) { var ctors = fixtureType.GetTypeInfo().DeclaredConstructors.Where(ci => !ci.IsStatic && ci.IsPublic).ToList(); if (ctors.Count != 1) { Aggregator.Add(new TestClassException("Collection fixture type '" + fixtureType.FullName + "' may only define a single public constructor.")); } else { var ctor = ctors[0]; var missingParameters = new List <ParameterInfo>(); var ctorArgs = ctor.GetParameters().Select(p => { if (!CollectionFixtureMappings.TryGetValue(p.ParameterType, out var arg)) { missingParameters.Add(p); } return(arg); }).ToArray(); if (missingParameters.Count > 0) { var parameters = string.Join(", ", missingParameters.Select(p => $"{p.ParameterType.Name} {p.Name}")); Aggregator.Add(new TestClassException( $"Class fixture type '{fixtureType.FullName}' had one or more unresolved constructor arguments: {parameters}" )); } else { Aggregator.Run(() => CollectionFixtureMappings[fixtureType] = ctor.Invoke(ctorArgs)); } } }
protected override Task BeforeTestCollectionFinishedAsync() { // We need to remove the assembly fixtures so they won't get disposed. foreach (var mapping in _assemblyFixtureMappings) { CollectionFixtureMappings.Remove(mapping.Key); } return(base.BeforeTestCollectionFinishedAsync()); }
protected override async Task AfterTestCollectionStartingAsync() { await base.AfterTestCollectionStartingAsync(); foreach (var mapping in _assemblyFixtureMappings) { CollectionFixtureMappings.Add(mapping.Key, mapping.Value); } }
protected override async Task AfterTestCollectionStartingAsync() { await base.AfterTestCollectionStartingAsync(); // note: We pass the assembly fixtures into the runner as ICollectionFixture<> - this seems to work OK without any // drawbacks. It's reasonable that we could add IAssemblyFixture<> and related plumbing if it ever became required. // // The reason for assembly fixture is when we want to start/stop something as the project scope - tests can only be // in one test collection at a time. foreach (var mapping in _assemblyFixtureMappings) { CollectionFixtureMappings.Add(mapping.Key, mapping.Value); } }