public void TheDefaultFilePathShouldBeUsedWhenAnAssemblyLocationIsEmpty() { const string programName = "testProgram"; var config = ManualConfig.CreateEmpty().CreateImmutableConfig(); var benchmarkMethod = typeof(MockFactory.MockBenchmarkClass) .GetTypeInfo() .GetMethods() .Single(method => method.Name == nameof(MockFactory.MockBenchmarkClass.Foo)); //Simulate loading an assembly from a stream var benchmarkDotNetAssembly = typeof(MockFactory.MockBenchmarkClass).GetTypeInfo().Assembly; var streamLoadedAssembly = Assembly.Load(File.ReadAllBytes(benchmarkDotNetAssembly.Location)); var assemblyType = streamLoadedAssembly.GetRunnableBenchmarks().Select(type => type).FirstOrDefault(); var target = new Descriptor(assemblyType, benchmarkMethod); var benchmarkCase = BenchmarkCase.Create(target, Job.Default, null, config); var benchmarks = new[] { new BenchmarkBuildInfo(benchmarkCase, config.CreateImmutableConfig(), 999) }; var projectGenerator = new SteamLoadedBuildPartition("netcoreapp3.0", null, null, null); string binariesPath = projectGenerator.ResolvePathForBinaries(new BuildPartition(benchmarks, new Resolver()), programName); string expectedPath = Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "BenchmarkDotNet.Bin"), programName); Assert.Equal(expectedPath, binariesPath); }
public void TestAssemblyFilePathIsUsedWhenTheAssemblyLocationIsNotEmpty() { const string programName = "testProgram"; var benchmarkMethod = typeof(MockFactory.MockBenchmarkClass) .GetTypeInfo() .GetMethods() .Single(method => method.Name == nameof(MockFactory.MockBenchmarkClass.Foo)); var target = new Descriptor(typeof(MockFactory.MockBenchmarkClass), benchmarkMethod); var benchmarkCase = BenchmarkCase.Create(target, Job.Default, null, ManualConfig.CreateEmpty().CreateImmutableConfig()); var benchmarks = new[] { new BenchmarkBuildInfo(benchmarkCase, ManualConfig.CreateEmpty().CreateImmutableConfig(), 0) }; var projectGenerator = new SteamLoadedBuildPartition("netcoreapp3.0", null, null, null); var buildPartition = new BuildPartition(benchmarks, new Resolver()); string binariesPath = projectGenerator.ResolvePathForBinaries(buildPartition, programName); string expectedPath = Path.Combine(Path.GetDirectoryName(buildPartition.AssemblyLocation), programName); Assert.Equal(expectedPath, binariesPath); }