Migrate the bare minimum of BaseUsingSqlCeSyntax to be able to migrate NPoco unit tests

This commit is contained in:
Mole
2020-10-22 15:17:16 +02:00
parent 016d3f2b5b
commit b28548849f
5 changed files with 51 additions and 7 deletions

View File

@@ -0,0 +1,46 @@
using System;
using Moq;
using NPoco;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Tests.TestHelpers
{
[TestFixture]
public abstract class BaseUsingSqlSyntax
{
protected IMapperCollection Mappers { get; private set; }
protected ISqlContext SqlContext { get; private set; }
protected Sql<ISqlContext> Sql()
{
return NPoco.Sql.BuilderFor(SqlContext);
}
[SetUp]
public virtual void Setup()
{
var container = TestHelper.GetRegister();
var typeLoader = TestHelper.GetMockedTypeLoader();
var composition = new Composition(container, typeLoader, Mock.Of<IProfilingLogger>(), Mock.Of<IRuntimeState>(), TestHelper.IOHelper, AppCaches.NoCache);
composition.WithCollectionBuilder<MapperCollectionBuilder>()
.AddCoreMappers();
var factory = composition.CreateFactory();
var pocoMappers = new NPoco.MapperCollection { new PocoMapper() };
var pocoDataFactory = new FluentPocoDataFactory((type, iPocoDataFactory) => new PocoDataBuilder(type, pocoMappers).Init());
var sqlSyntax = new SqlServerSyntaxProvider();
SqlContext = new SqlContext(sqlSyntax, DatabaseType.SqlServer2012, pocoDataFactory, new Lazy<IMapperCollection>(() => factory.GetInstance<IMapperCollection>()));
Mappers = factory.GetInstance<IMapperCollection>();
}
}
}

View File

@@ -5,13 +5,12 @@ using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Dtos;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
using static Umbraco.Core.Persistence.SqlExtensionsStatics;
namespace Umbraco.Tests.Persistence.NPocoTests
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Persistence.NPocoTests
{
[TestFixture]
public class NPocoSqlExtensionsTests : BaseUsingSqlCeSyntax
public class NPocoSqlExtensionsTests : BaseUsingSqlSyntax
{
[Test]
public void WhereTest()

View File

@@ -6,6 +6,7 @@ using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core;
using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Persistence.NPocoTests
{

View File

@@ -9,10 +9,10 @@ using Umbraco.Core.Persistence.Querying;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Persistence.NPocoTests
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Persistence.NPocoTests
{
[TestFixture]
public class NPocoSqlTests : BaseUsingSqlCeSyntax
public class NPocoSqlTests : BaseUsingSqlSyntax
{
[Test]
public void Where_Clause_With_Starts_With_Additional_Parameters()

View File

@@ -139,8 +139,6 @@
<Compile Include="Migrations\MigrationPlanTests.cs" />
<Compile Include="Migrations\MigrationTests.cs" />
<Compile Include="Models\ContentXmlTest.cs" />
<Compile Include="Persistence\NPocoTests\NPocoSqlExtensionsTests.cs" />
<Compile Include="Persistence\NPocoTests\NPocoSqlTests.cs" />
<Compile Include="PublishedContent\SolidPublishedSnapshot.cs" />
<Compile Include="Published\ConvertersTests.cs" />
<Compile Include="Published\ModelTypeTests.cs" />