2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
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;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Composing;
|
|
|
|
|
using Umbraco.Cms.Core.DependencyInjection;
|
2020-10-22 15:17:16 +02:00
|
|
|
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-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; }
|
|
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
protected Sql<ISqlContext> Sql() => NPoco.Sql.BuilderFor(SqlContext);
|
2020-10-22 15:17:16 +02:00
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public virtual void Setup()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceCollection container = TestHelper.GetServiceCollection();
|
|
|
|
|
TypeLoader typeLoader = TestHelper.GetMockedTypeLoader();
|
2020-10-22 15:17:16 +02:00
|
|
|
|
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-12-20 08:36:11 +01:00
|
|
|
composition.Services.AddUnique(_ => SqlContext);
|
2020-10-22 15:31:56 +02:00
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
IServiceProvider 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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|