2020-10-22 15:17:16 +02:00
|
|
|
using System;
|
2020-11-18 17:40:23 +00:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2020-10-30 11:16:17 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-10-22 15:17:16 +02:00
|
|
|
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;
|
2020-10-27 10:53:01 +00:00
|
|
|
using Umbraco.Tests.UnitTests.TestHelpers;
|
2020-12-01 12:42:14 +00:00
|
|
|
using Umbraco.Core.DependencyInjection;
|
2020-10-22 15:17:16 +02:00
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2020-10-27 10:53:01 +00:00
|
|
|
var container = TestHelper.GetServiceCollection();
|
2020-10-22 15:17:16 +02:00
|
|
|
var typeLoader = TestHelper.GetMockedTypeLoader();
|
|
|
|
|
|
2020-11-20 11:48:32 +00:00
|
|
|
var composition = new UmbracoBuilder(container, Mock.Of<IConfiguration>(), TestHelper.GetMockedTypeLoader());
|
|
|
|
|
|
2020-10-22 15:17:16 +02:00
|
|
|
|
|
|
|
|
composition.WithCollectionBuilder<MapperCollectionBuilder>()
|
|
|
|
|
.AddCoreMappers();
|
|
|
|
|
|
2020-10-30 11:16:17 +00:00
|
|
|
composition.Services.AddUnique<ISqlContext>(_ => SqlContext);
|
2020-10-22 15:31:56 +02:00
|
|
|
|
2020-10-30 11:16:17 +00:00
|
|
|
var factory = composition.CreateServiceProvider();
|
2020-10-22 15:17:16 +02:00
|
|
|
var pocoMappers = new NPoco.MapperCollection { new PocoMapper() };
|
|
|
|
|
var pocoDataFactory = new FluentPocoDataFactory((type, iPocoDataFactory) => new PocoDataBuilder(type, pocoMappers).Init());
|
|
|
|
|
var sqlSyntax = new SqlServerSyntaxProvider();
|
2020-10-27 10:53:01 +00:00
|
|
|
SqlContext = new SqlContext(sqlSyntax, DatabaseType.SqlServer2012, pocoDataFactory, new Lazy<IMapperCollection>(() => factory.GetRequiredService<IMapperCollection>()));
|
|
|
|
|
Mappers = factory.GetRequiredService<IMapperCollection>();
|
2020-10-22 15:17:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|