Merge pull request #9717 from umbraco/netcore/feature/migrate-more-tests
Netcore: Migrate more tests
This commit is contained in:
@@ -13,33 +13,34 @@ using Umbraco.Core.Persistence.DatabaseAnnotations;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Tests.LegacyXmlPublishedCache;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Persistence.SyntaxProvider
|
||||
{
|
||||
[TestFixture]
|
||||
public class SqlCeSyntaxProviderTests : BaseUsingSqlCeSyntax
|
||||
public class SqlServerSyntaxProviderTests : UmbracoIntegrationTest
|
||||
{
|
||||
private ISqlContext SqlContext => GetRequiredService<IUmbracoDatabaseFactory>().SqlContext;
|
||||
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewEmptyPerTest)]
|
||||
[Test]
|
||||
public void Can_Generate_Delete_SubQuery_Statement()
|
||||
{
|
||||
var mediaObjectType = Constants.ObjectTypes.Media;
|
||||
var subQuery = Sql()
|
||||
.Select("DISTINCT cmsContentXml.nodeId")
|
||||
.From<ContentXmlDto>()
|
||||
var subQuery = SqlContext.Sql()
|
||||
.Select("DISTINCT cmsContentNu.nodeId")
|
||||
.From<ContentNuDto>()
|
||||
.InnerJoin<NodeDto>()
|
||||
.On<ContentXmlDto, NodeDto>(left => left.NodeId, right => right.NodeId)
|
||||
.On<ContentNuDto, NodeDto>(left => left.NodeId, right => right.NodeId)
|
||||
.Where<NodeDto>(dto => dto.NodeObjectType == mediaObjectType);
|
||||
|
||||
var sqlOutput = SqlContext.SqlSyntax.GetDeleteSubquery("cmsContentXml", "nodeId", subQuery);
|
||||
var sqlOutput = SqlContext.SqlSyntax.GetDeleteSubquery("cmsContentNu", "nodeId", subQuery);
|
||||
|
||||
Assert.AreEqual(@"DELETE FROM [cmsContentXml] WHERE [nodeId] IN (SELECT [nodeId] FROM (SELECT DISTINCT cmsContentXml.nodeId
|
||||
FROM [cmsContentXml]
|
||||
Assert.AreEqual(@"DELETE FROM [cmsContentNu] WHERE [nodeId] IN (SELECT [nodeId] FROM (SELECT DISTINCT cmsContentNu.nodeId
|
||||
FROM [cmsContentNu]
|
||||
INNER JOIN [umbracoNode]
|
||||
ON [cmsContentXml].[nodeId] = [umbracoNode].[id]
|
||||
ON [cmsContentNu].[nodeId] = [umbracoNode].[id]
|
||||
WHERE (([umbracoNode].[nodeObjectType] = @0))) x)".Replace(Environment.NewLine, " ").Replace("\n", " ").Replace("\r", " "),
|
||||
sqlOutput.SQL.Replace(Environment.NewLine, " ").Replace("\n", " ").Replace("\r", " "));
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Web.Security;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Templates;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
using Umbraco.Web.Security.Providers;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
|
||||
|
||||
namespace Umbraco.Tests.Testing.TestingTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class MockTests : UmbracoTestBase
|
||||
{
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
|
||||
Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Mock_Service_Context()
|
||||
{
|
||||
// ReSharper disable once UnusedVariable
|
||||
var serviceContext = TestObjects.GetServiceContextMock();
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Mock_Umbraco_Context()
|
||||
{
|
||||
var umbracoContext = TestObjects.GetUmbracoContextMock(Current.UmbracoContextAccessor);
|
||||
Assert.AreEqual(umbracoContext, Current.UmbracoContext);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Mock_Umbraco_Helper()
|
||||
{
|
||||
// unless we can inject them in MembershipHelper, we need need this
|
||||
Builder.Services.AddTransient(_ => Mock.Of<IMemberService>());
|
||||
Builder.Services.AddTransient(_ => Mock.Of<IMemberTypeService>());
|
||||
Builder.Services.AddTransient(_ => Mock.Of<IUserService>());
|
||||
Builder.Services.AddTransient(_ => AppCaches.Disabled);
|
||||
Builder.Services.AddTransient<ServiceContext>();
|
||||
|
||||
var loggerFactory = Mock.Of<ILoggerFactory>();
|
||||
var memberService = Mock.Of<IMemberService>();
|
||||
var memberTypeService = Mock.Of<IMemberTypeService>();
|
||||
var membershipProvider = new MembersMembershipProvider(memberService, memberTypeService, Mock.Of<IUmbracoVersion>(), TestHelper.GetHostingEnvironment(), TestHelper.GetIpResolver());
|
||||
var membershipHelper = new MembershipHelper(Mock.Of<IHttpContextAccessor>(), Mock.Of<IPublishedMemberCache>(), membershipProvider, Mock.Of<RoleProvider>(), memberService, memberTypeService, Mock.Of<IPublicAccessService>(), AppCaches.Disabled, loggerFactory, ShortStringHelper, Mock.Of<IEntityService>());
|
||||
|
||||
// ReSharper disable once UnusedVariable
|
||||
var helper = new UmbracoHelper(Mock.Of<IPublishedContent>(),
|
||||
Mock.Of<ICultureDictionaryFactory>(),
|
||||
Mock.Of<IUmbracoComponentRenderer>(),
|
||||
Mock.Of<IPublishedContentQuery>(),
|
||||
membershipHelper);
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Mock_UrlProvider()
|
||||
{
|
||||
var umbracoContext = TestObjects.GetUmbracoContextMock();
|
||||
|
||||
|
||||
var urlProviderMock = new Mock<IUrlProvider>();
|
||||
urlProviderMock.Setup(provider => provider.GetUrl(It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/hello/world/1234"));
|
||||
var urlProvider = urlProviderMock.Object;
|
||||
|
||||
var webRoutingSettings = new WebRoutingSettings();
|
||||
var theUrlProvider = new UrlProvider(
|
||||
new TestUmbracoContextAccessor(umbracoContext),
|
||||
Microsoft.Extensions.Options.Options.Create(webRoutingSettings),
|
||||
new UrlProviderCollection(new [] { urlProvider }),
|
||||
new MediaUrlProviderCollection( Enumerable.Empty<IMediaUrlProvider>())
|
||||
, umbracoContext.VariationContextAccessor);
|
||||
|
||||
var contentType = new PublishedContentType(Guid.NewGuid(), 666, "alias", PublishedItemType.Content, Enumerable.Empty<string>(), Enumerable.Empty<PublishedPropertyType>(), ContentVariation.Nothing);
|
||||
var publishedContent = Mock.Of<IPublishedContent>();
|
||||
Mock.Get(publishedContent).Setup(x => x.ContentType).Returns(contentType);
|
||||
|
||||
Assert.AreEqual("/hello/world/1234", theUrlProvider.GetUrl(publishedContent));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Mock_UmbracoApiController_Dependencies_With_Injected_UmbracoMapper()
|
||||
{
|
||||
var profilingLogger = Mock.Of<IProfilingLogger>();
|
||||
var memberService = Mock.Of<IMemberService>();
|
||||
var memberTypeService = Mock.Of<IMemberTypeService>();
|
||||
var membershipProvider = new MembersMembershipProvider(memberService, memberTypeService, Mock.Of<IUmbracoVersion>(), TestHelper.GetHostingEnvironment(), TestHelper.GetIpResolver());
|
||||
var umbracoMapper = new UmbracoMapper(new MapDefinitionCollection(new[] { Mock.Of<IMapDefinition>() }));
|
||||
|
||||
var umbracoApiController = new FakeUmbracoApiController(new GlobalSettings(), Mock.Of<IUmbracoContextAccessor>(), Mock.Of<IBackOfficeSecurityAccessor>(), Mock.Of<ISqlContext>(), ServiceContext.CreatePartial(), AppCaches.NoCache, profilingLogger , Mock.Of<IRuntimeState>(), umbracoMapper, Mock.Of<IPublishedUrlProvider>());
|
||||
|
||||
Assert.Pass();
|
||||
}
|
||||
}
|
||||
|
||||
internal class FakeUmbracoApiController : UmbracoApiController
|
||||
{
|
||||
public FakeUmbracoApiController(GlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, IBackOfficeSecurityAccessor backOfficeSecurityAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider)
|
||||
: base(globalSettings, umbracoContextAccessor, backOfficeSecurityAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoMapper, publishedUrlProvider) { }
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Umbraco.Tests.Testing.TestingTests
|
||||
{
|
||||
// these 4 test classes validate that our test class pattern *should* be:
|
||||
// - test base classes *not* marked as [TestFixture] but having a virtual SetUp
|
||||
// method marked as [SetUp]
|
||||
// - test classes inheriting from base class, marked as [TestFixture], and
|
||||
// overriding the SetUp method *without* repeating the [SetUp] attribute
|
||||
// - same for TearDown
|
||||
//
|
||||
// ie what InheritsTestClassWithoutAttribute does - and it works
|
||||
|
||||
[TestFixture]
|
||||
public class InheritsTestClassWithAttribute : NUnitTestClassBase
|
||||
{
|
||||
public const int ConstValue = 77;
|
||||
|
||||
protected int Value { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
Value = ConstValue;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertValues()
|
||||
{
|
||||
Assert.AreEqual(ConstBaseValue, BaseValue);
|
||||
Assert.AreEqual(ConstValue, Value);
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class InheritsTestClassWithoutAttribute : NUnitTestClassBase
|
||||
{
|
||||
public const int ConstValue = 88;
|
||||
|
||||
protected int Value { get; set; }
|
||||
|
||||
// not needed!
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
Value = ConstValue;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertValues()
|
||||
{
|
||||
Assert.AreEqual(ConstBaseValue, BaseValue);
|
||||
Assert.AreEqual(ConstValue, Value);
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class InheritTestFixtureWithAttribute : NUnitTestFixtureBase
|
||||
{
|
||||
public const int ConstValue = 99;
|
||||
|
||||
protected int Value { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
Value = ConstValue;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertValues()
|
||||
{
|
||||
Assert.AreEqual(ConstBaseValue, BaseValue);
|
||||
Assert.AreEqual(ConstValue, Value);
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class InheritTestFixtureWithoutAttribute : NUnitTestFixtureBase
|
||||
{
|
||||
public const int ConstValue = 66;
|
||||
|
||||
protected int Value { get; set; }
|
||||
|
||||
// not needed!
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
Value = ConstValue;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssertValues()
|
||||
{
|
||||
Assert.AreEqual(ConstBaseValue, BaseValue);
|
||||
Assert.AreEqual(ConstValue, Value);
|
||||
}
|
||||
}
|
||||
|
||||
public class NUnitTestClassBase
|
||||
{
|
||||
public const int ConstBaseValue = 33;
|
||||
|
||||
protected int BaseValue { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public virtual void SetUp()
|
||||
{
|
||||
BaseValue = ConstBaseValue;
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class NUnitTestFixtureBase
|
||||
{
|
||||
public const int ConstBaseValue = 42;
|
||||
|
||||
protected int BaseValue { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public virtual void SetUp()
|
||||
{
|
||||
BaseValue = ConstBaseValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,6 @@
|
||||
<Compile Include="TestHelpers\Entities\MockedUser.cs" />
|
||||
<Compile Include="TestHelpers\Entities\MockedUserGroup.cs" />
|
||||
<Compile Include="UmbracoExamine\ExamineExtensions.cs" />
|
||||
<Compile Include="Models\RangeTests.cs" />
|
||||
<Compile Include="Persistence\Mappers\MapperTestBase.cs" />
|
||||
<Compile Include="PublishedContent\NuCacheChildrenTests.cs" />
|
||||
<Compile Include="PublishedContent\PublishedContentLanguageVariantTests.cs" />
|
||||
@@ -189,7 +188,6 @@
|
||||
<Compile Include="TestHelpers\ControllerTesting\TraceExceptionLogger.cs" />
|
||||
<Compile Include="Testing\Objects\Accessors\NoHttpContextAccessor.cs" />
|
||||
<Compile Include="TestHelpers\Stubs\TestExamineManager.cs" />
|
||||
<Compile Include="Testing\TestingTests\NUnitTests.cs" />
|
||||
<Compile Include="Testing\UmbracoTestBase.cs" />
|
||||
<Compile Include="TestHelpers\TestObjects-Mocks.cs" />
|
||||
<Compile Include="TestHelpers\TestObjects.cs" />
|
||||
@@ -200,7 +198,6 @@
|
||||
<Compile Include="Routing\RoutesCacheTests.cs" />
|
||||
<Compile Include="Routing\UrlRoutingTestBase.cs" />
|
||||
<Compile Include="Web\PublishedContentQueryTests.cs" />
|
||||
<Compile Include="Testing\TestingTests\MockTests.cs" />
|
||||
<Compile Include="Web\Mvc\SurfaceControllerTests.cs" />
|
||||
<Compile Include="Web\Mvc\MergeParentContextViewDataAttributeTests.cs" />
|
||||
<Compile Include="Web\Mvc\ViewDataDictionaryExtensionTests.cs" />
|
||||
@@ -211,7 +208,6 @@
|
||||
<Compile Include="Cache\PublishedCache\PublishedMediaCacheTests.cs" />
|
||||
<Compile Include="Models\MediaXmlTest.cs" />
|
||||
<Compile Include="Persistence\FaultHandling\ConnectionRetryTest.cs" />
|
||||
<Compile Include="Persistence\SyntaxProvider\SqlCeSyntaxProviderTests.cs" />
|
||||
<Compile Include="PublishedContent\PublishedContentDataTableTests.cs" />
|
||||
<Compile Include="PublishedContent\PublishedContentTestBase.cs" />
|
||||
<Compile Include="PublishedContent\PublishedContentTests.cs" />
|
||||
@@ -320,6 +316,9 @@
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Persistence\SyntaxProvider" />
|
||||
</ItemGroup>
|
||||
<!-- get NuGet packages directory -->
|
||||
<PropertyGroup>
|
||||
<NuGetPackages>$(NuGetPackageFolders.Split(';')[0])</NuGetPackages>
|
||||
|
||||
Reference in New Issue
Block a user