V10: fix build warnings in test projects (#12509)
* Run code cleanup * Dotnet format benchmarks project * Fix up Test.Common * Run dotnet format + manual cleanup * Run code cleanup for unit tests * Run dotnet format * Fix up errors * Manual cleanup of Unit test project * Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix according to review * Fix after merge * Fix errors Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -11,67 +11,71 @@ using Umbraco.Cms.Infrastructure.Persistence.Querying;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax;
|
||||
using Umbraco.Cms.Persistence.SqlServer.Services;
|
||||
|
||||
namespace Umbraco.Tests.Benchmarks
|
||||
namespace Umbraco.Tests.Benchmarks;
|
||||
|
||||
[MemoryDiagnoser]
|
||||
public class ModelToSqlExpressionHelperBenchmarks
|
||||
{
|
||||
[MemoryDiagnoser]
|
||||
public class ModelToSqlExpressionHelperBenchmarks
|
||||
private readonly CachedExpression _cachedExpression;
|
||||
private readonly IMapperCollection _mapperCollection;
|
||||
|
||||
private readonly ISqlSyntaxProvider _syntaxProvider =
|
||||
new SqlServerSyntaxProvider(Options.Create(new GlobalSettings()));
|
||||
|
||||
public ModelToSqlExpressionHelperBenchmarks()
|
||||
{
|
||||
protected Lazy<ISqlContext> MockSqlContext()
|
||||
var contentMapper = new ContentMapper(MockSqlContext(), CreateMaps());
|
||||
_cachedExpression = new CachedExpression();
|
||||
var mapperCollection = new Mock<IMapperCollection>();
|
||||
mapperCollection.Setup(x => x[It.IsAny<Type>()]).Returns(contentMapper);
|
||||
_mapperCollection = mapperCollection.Object;
|
||||
}
|
||||
|
||||
protected Lazy<ISqlContext> MockSqlContext()
|
||||
{
|
||||
var sqlContext = Mock.Of<ISqlContext>();
|
||||
var syntax = new SqlServerSyntaxProvider(Options.Create(new GlobalSettings()));
|
||||
Mock.Get(sqlContext).Setup(x => x.SqlSyntax).Returns(syntax);
|
||||
return new Lazy<ISqlContext>(() => sqlContext);
|
||||
}
|
||||
|
||||
protected MapperConfigurationStore CreateMaps() => new();
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void WithNonCached()
|
||||
{
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
var sqlContext = Mock.Of<ISqlContext>();
|
||||
var syntax = new SqlServerSyntaxProvider(Options.Create(new GlobalSettings()));
|
||||
Mock.Get(sqlContext).Setup(x => x.SqlSyntax).Returns(syntax);
|
||||
return new Lazy<ISqlContext>(() => sqlContext);
|
||||
var a = i;
|
||||
var b = i * 10;
|
||||
Expression<Func<IContent, bool>> predicate = content =>
|
||||
content.Path.StartsWith("-1") && content.Published &&
|
||||
(content.ContentTypeId == a || content.ContentTypeId == b);
|
||||
|
||||
var modelToSqlExpressionHelper =
|
||||
new ModelToSqlExpressionVisitor<IContent>(_syntaxProvider, _mapperCollection);
|
||||
var result = modelToSqlExpressionHelper.Visit(predicate);
|
||||
}
|
||||
}
|
||||
|
||||
protected MapperConfigurationStore CreateMaps()
|
||||
=> new MapperConfigurationStore();
|
||||
|
||||
public ModelToSqlExpressionHelperBenchmarks()
|
||||
[Benchmark]
|
||||
public void WithCachedExpression()
|
||||
{
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
var contentMapper = new ContentMapper(MockSqlContext(), CreateMaps());
|
||||
_cachedExpression = new CachedExpression();
|
||||
var mapperCollection = new Mock<IMapperCollection>();
|
||||
mapperCollection.Setup(x => x[It.IsAny<Type>()]).Returns(contentMapper);
|
||||
_mapperCollection = mapperCollection.Object;
|
||||
}
|
||||
var a = i;
|
||||
var b = i * 10;
|
||||
Expression<Func<IContent, bool>> predicate = content =>
|
||||
content.Path.StartsWith("-1") && content.Published &&
|
||||
(content.ContentTypeId == a || content.ContentTypeId == b);
|
||||
|
||||
private readonly ISqlSyntaxProvider _syntaxProvider = new SqlServerSyntaxProvider(Options.Create(new GlobalSettings()));
|
||||
private readonly CachedExpression _cachedExpression;
|
||||
private readonly IMapperCollection _mapperCollection;
|
||||
var modelToSqlExpressionHelper =
|
||||
new ModelToSqlExpressionVisitor<IContent>(_syntaxProvider, _mapperCollection);
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void WithNonCached()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
var a = i;
|
||||
var b = i * 10;
|
||||
Expression<Func<IContent, bool>> predicate = content =>
|
||||
content.Path.StartsWith("-1") && content.Published && (content.ContentTypeId == a || content.ContentTypeId == b);
|
||||
//wrap it!
|
||||
_cachedExpression.Wrap(predicate);
|
||||
|
||||
var modelToSqlExpressionHelper = new ModelToSqlExpressionVisitor<IContent>(_syntaxProvider, _mapperCollection);
|
||||
var result = modelToSqlExpressionHelper.Visit(predicate);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void WithCachedExpression()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
var a = i;
|
||||
var b = i * 10;
|
||||
Expression<Func<IContent, bool>> predicate = content =>
|
||||
content.Path.StartsWith("-1") && content.Published && (content.ContentTypeId == a || content.ContentTypeId == b);
|
||||
|
||||
var modelToSqlExpressionHelper = new ModelToSqlExpressionVisitor<IContent>(_syntaxProvider, _mapperCollection);
|
||||
|
||||
//wrap it!
|
||||
_cachedExpression.Wrap(predicate);
|
||||
|
||||
var result = modelToSqlExpressionHelper.Visit(_cachedExpression);
|
||||
}
|
||||
var result = modelToSqlExpressionHelper.Visit(_cachedExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user