Merge pull request #8394 from umbraco/netcore/feature/fix-integration-tests
Netcore: More tests migrated..
This commit is contained in:
108
src/Umbraco.Tests.Integration/Services/AuditServiceTests.cs
Normal file
108
src/Umbraco.Tests.Integration/Services/AuditServiceTests.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class AuditServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
[Test]
|
||||
public void GetPage()
|
||||
{
|
||||
var sut = (AuditService) GetRequiredService<IAuditService>();
|
||||
var expected = new AuditEntryBuilder().Build();
|
||||
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
sut.Write(
|
||||
expected.PerformingUserId + i,
|
||||
expected.PerformingDetails,
|
||||
expected.PerformingIp,
|
||||
expected.EventDateUtc.AddMinutes(i),
|
||||
expected.AffectedUserId+ i,
|
||||
expected.AffectedDetails,
|
||||
expected.EventType,
|
||||
expected.EventDetails);
|
||||
}
|
||||
|
||||
var entries = sut.GetPage(2, 2, out var count).ToArray();
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(2, entries.Length);
|
||||
Assert.AreEqual(expected.PerformingUserId + 5, entries[0].PerformingUserId);
|
||||
Assert.AreEqual(expected.PerformingUserId + 4, entries[1].PerformingUserId);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUserLogs()
|
||||
{
|
||||
var sut = (AuditService) Services.GetRequiredService<IAuditService>();
|
||||
|
||||
var eventDateUtc = DateTime.UtcNow.AddDays(-1);
|
||||
|
||||
var numberOfEntries = 10;
|
||||
for (var i = 0; i < numberOfEntries; i++)
|
||||
{
|
||||
eventDateUtc = eventDateUtc.AddMinutes(1);
|
||||
sut.Add(AuditType.Unpublish, -1, 33, "", "blah");
|
||||
}
|
||||
|
||||
sut.Add(AuditType.Publish, -1, 33, "", "blah");
|
||||
|
||||
var logs = sut.GetUserLogs(-1, AuditType.Unpublish).ToArray();
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.IsNotNull(logs);
|
||||
CollectionAssert.AllItemsAreNotNull(logs);
|
||||
Assert.AreEqual(numberOfEntries, logs.Length);
|
||||
Assert.AreEqual(numberOfEntries, logs.Count(x => x.AuditType == AuditType.Unpublish));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Write_and_GetAll()
|
||||
{
|
||||
var sut = (AuditService) Services.GetRequiredService<IAuditService>();
|
||||
var expected = new AuditEntryBuilder().Build();
|
||||
|
||||
var actual = sut.Write(
|
||||
expected.PerformingUserId,
|
||||
expected.PerformingDetails,
|
||||
expected.PerformingIp,
|
||||
expected.EventDateUtc,
|
||||
expected.AffectedUserId,
|
||||
expected.AffectedDetails,
|
||||
expected.EventType,
|
||||
expected.EventDetails);
|
||||
|
||||
var entries = sut.GetAll().ToArray();
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(expected.PerformingUserId, actual.PerformingUserId);
|
||||
Assert.AreEqual(expected.PerformingDetails, actual.PerformingDetails);
|
||||
Assert.AreEqual(expected.EventDateUtc, actual.EventDateUtc);
|
||||
Assert.AreEqual(expected.AffectedUserId, actual.AffectedUserId);
|
||||
Assert.AreEqual(expected.AffectedDetails, actual.AffectedDetails);
|
||||
Assert.AreEqual(expected.EventType, actual.EventType);
|
||||
Assert.AreEqual(expected.EventDetails, actual.EventDetails);
|
||||
Assert.IsNotNull(entries);
|
||||
Assert.AreEqual(1, entries.Length);
|
||||
Assert.AreEqual(expected.PerformingUserId, entries[0].PerformingUserId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ using Umbraco.Web.BackOffice.Controllers;
|
||||
namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class BackOfficeAssetsControllerTests: UmbracoTestServerTestBase
|
||||
{
|
||||
[Test]
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
@@ -16,9 +17,8 @@ using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
{
|
||||
[Explicit("We need to fix the tests on buildserver and when running multiple tests in one run")]
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
[Explicit("Need to figure out whats wrong with these tests when executed all in one run.")]
|
||||
public class ContentControllerTests : UmbracoTestServerTestBase
|
||||
{
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
|
||||
Assert.AreEqual(")]}',\n{\"message\":\"No variants flagged for saving\"}", body);
|
||||
Assert.AreEqual(")]}',\n{\"Message\":\"No variants flagged for saving\"}", body);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -14,9 +14,7 @@ using Umbraco.Web.Models.TemplateQuery;
|
||||
|
||||
namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
{
|
||||
[Explicit("We need to fix the tests on buildserver and when running multiple tests in one run")]
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class TemplateQueryControllerTests : UmbracoTestServerTestBase
|
||||
{
|
||||
[Test]
|
||||
@@ -43,7 +41,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
{
|
||||
var alias = nameof(ContentTypeModel.Alias);
|
||||
var camelCaseAlias = alias.ToCamelCase();
|
||||
Assert.IsNotNull(jToken.Value<string>(camelCaseAlias), $"'{jToken}' do not contain the key '{camelCaseAlias}'");
|
||||
Assert.IsNotNull(jToken.Value<string>(camelCaseAlias), $"'{jToken}' do not contain the key '{camelCaseAlias}' in the expected casing");
|
||||
Assert.IsNull(jToken.Value<string>(alias), $"'{jToken}' do contain the key '{alias}', which was not expect in that casing");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,9 +22,7 @@ using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
{
|
||||
[Explicit("We need to fix the tests on buildserver and when running multiple tests in one run")]
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class UsersControllerTests : UmbracoTestServerTestBase
|
||||
{
|
||||
[Test]
|
||||
@@ -182,7 +180,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
|
||||
var user = new UserBuilder()
|
||||
.AddUserGroup()
|
||||
.WithAlias("writer") // Needs to be an existing alias
|
||||
.WithAlias("writer") // Needs to be an existing alias
|
||||
.Done()
|
||||
.WithIsLockedOut(true, DateTime.UtcNow)
|
||||
.Build();
|
||||
|
||||
@@ -11,6 +11,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Composing;
|
||||
using Umbraco.Extensions;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Common.Controllers;
|
||||
using Umbraco.Web.Editors;
|
||||
@@ -19,6 +20,7 @@ using Umbraco.Web.Editors;
|
||||
namespace Umbraco.Tests.Integration.TestServerTest
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, Logger = UmbracoTestOptions.Logger.Console, Boot = false)]
|
||||
public abstract class UmbracoTestServerTestBase : UmbracoIntegrationTest
|
||||
{
|
||||
[SetUp]
|
||||
@@ -29,7 +31,6 @@ namespace Umbraco.Tests.Integration.TestServerTest
|
||||
AllowAutoRedirect = false
|
||||
});
|
||||
LinkGenerator = Factory.Services.GetRequiredService<LinkGenerator>();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -53,7 +53,8 @@ namespace Umbraco.Tests.Integration.TestServerTest
|
||||
{
|
||||
x.AddInMemoryCollection(new Dictionary<string, string>()
|
||||
{
|
||||
["ConnectionStrings:"+ Constants.System.UmbracoConnectionName] = _testDbConnectionString
|
||||
["ConnectionStrings:"+ Constants.System.UmbracoConnectionName] = _testDbConnectionString,
|
||||
["Umbraco:CMS:Hosting:Debug"] = "true",
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -249,7 +249,6 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
Debugger.Launch();
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
@@ -18,7 +19,9 @@ using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Integration.Extensions;
|
||||
using Umbraco.Tests.Integration.Implementations;
|
||||
using Umbraco.Extensions;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using ILogger = Umbraco.Core.Logging.ILogger;
|
||||
|
||||
namespace Umbraco.Tests.Integration.Testing
|
||||
{
|
||||
@@ -98,6 +101,8 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
{
|
||||
var umbracoContainer = GetUmbracoContainer(out var serviceProviderFactory);
|
||||
var testHelper = new TestHelper();
|
||||
// get the currently set db options
|
||||
var testOptions = TestOptionAttributeBase.GetTestOptions<UmbracoTestAttribute>();
|
||||
|
||||
var hostBuilder = new HostBuilder()
|
||||
.UseUmbraco(serviceProviderFactory)
|
||||
@@ -117,6 +122,9 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
|
||||
services.AddMvc();
|
||||
|
||||
|
||||
services.AddSingleton<ILogger>(new ConsoleLogger(new MessageTemplates()));
|
||||
|
||||
CustomTestSetup(services);
|
||||
});
|
||||
|
||||
@@ -129,10 +137,15 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
app.UseTestLocalDb(testHelper.WorkingDirectory, this, out var connectionString);
|
||||
TestDBConnectionString = connectionString;
|
||||
|
||||
app.UseUmbracoCore();
|
||||
if (testOptions.Boot)
|
||||
{
|
||||
app.UseUmbracoCore();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected T GetRequiredService<T>() => Services.GetRequiredService<T>();
|
||||
|
||||
#region Common services
|
||||
|
||||
protected string TestDBConnectionString { get; private set; }
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="3.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="Moq" Version="4.13.1" />
|
||||
<PackageReference Include="nunit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
|
||||
|
||||
Reference in New Issue
Block a user