Skip to content

Commit 17abf04

Browse files
authored
Added unit tests for ContentVersionService (#11597)
* Added unit tests for ContentVersionService * Clean up * Fixed tests after using ConfigureMembers = true * Fixed tests after using ConfigureMembers = true
1 parent 90c64a2 commit 17abf04

File tree

4 files changed

+203
-273
lines changed

4 files changed

+203
-273
lines changed

src/Umbraco.Infrastructure/Services/Implement/ContentVersionService.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ public ContentVersionService(
4141
/// In v9 this can live in another class as we publish the notifications via IEventAggregator.
4242
/// But for v8 must be here for access to the static events.
4343
/// </remarks>
44-
public IReadOnlyCollection<HistoricContentVersionMeta> PerformContentVersionCleanup(DateTime asAtDate) =>
45-
CleanupDocumentVersions(asAtDate);
44+
public IReadOnlyCollection<HistoricContentVersionMeta> PerformContentVersionCleanup(DateTime asAtDate)
45+
{
46+
// Media - ignored
47+
// Members - ignored
48+
return CleanupDocumentVersions(asAtDate);
49+
}
50+
4651

47-
// Media - ignored
48-
// Members - ignored
4952
/// <remarks>
5053
/// v9 - move to another class
5154
/// </remarks>

tests/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
using Umbraco.Cms.Web.BackOffice.Controllers;
2222
using Umbraco.Cms.Web.BackOffice.Install;
2323
using Umbraco.Cms.Web.BackOffice.Routing;
24+
using Umbraco.Cms.Web.Common.AspNetCore;
2425
using Umbraco.Cms.Web.Common.Security;
2526

2627
namespace Umbraco.Cms.Tests.UnitTests.AutoFixture
2728
{
29+
2830
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor)]
2931
public class AutoMoqDataAttribute : AutoDataAttribute
3032
{
@@ -40,6 +42,7 @@ public AutoMoqDataAttribute()
4042

4143
internal static class AutoMockCustomizations
4244
{
45+
4346
public static IFixture Default => new Fixture().Customize(new UmbracoCustomization());
4447

4548
private class UmbracoCustomization : ICustomization
@@ -58,7 +61,7 @@ public void Customize(IFixture fixture)
5861
.Customize(new ConstructorCustomization(typeof(BackOfficeUserManager), new GreedyConstructorQuery()))
5962
.Customize(new ConstructorCustomization(typeof(MemberManager), new GreedyConstructorQuery()));
6063

61-
fixture.Customize(new AutoMoqCustomization());
64+
fixture.Customize(new AutoMoqCustomization(){ConfigureMembers = true});
6265

6366
// When requesting an IUserStore ensure we actually uses a IUserLockoutStore
6467
fixture.Customize<IUserStore<BackOfficeIdentityUser>>(cc => cc.FromFactory(() => Mock.Of<IUserLockoutStore<BackOfficeIdentityUser>>()));
@@ -71,6 +74,8 @@ public void Customize(IFixture fixture)
7174
u => u.FromFactory(
7275
() => new UmbracoVersion()));
7376

77+
fixture.Customize<HostingSettings>(x =>
78+
x.With(settings => settings.ApplicationVirtualPath, string.Empty));
7479
fixture.Customize<BackOfficeAreaRoutes>(u => u.FromFactory(
7580
() => new BackOfficeAreaRoutes(
7681
Options.Create(new GlobalSettings()),
@@ -84,12 +89,18 @@ public void Customize(IFixture fixture)
8489
Mock.Of<IHostingEnvironment>(x => x.ToAbsolute(It.IsAny<string>()) == "/umbraco" && x.ApplicationVirtualPath == string.Empty),
8590
Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Run))));
8691

87-
var connectionStrings = new ConnectionStrings();
88-
fixture.Customize<ConnectionStrings>(x => x.FromFactory(() => connectionStrings));
92+
var configConnectionString = new ConfigConnectionString("ss",
93+
"Data Source=(localdb)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\Umbraco.mdf;Integrated Security=True");
94+
fixture.Customize<ConfigConnectionString>(x => x.FromFactory(() => configConnectionString));
95+
8996

9097
var httpContextAccessor = new HttpContextAccessor { HttpContext = new DefaultHttpContext() };
9198
fixture.Customize<HttpContext>(x => x.FromFactory(() => httpContextAccessor.HttpContext));
9299
fixture.Customize<IHttpContextAccessor>(x => x.FromFactory(() => httpContextAccessor));
100+
101+
fixture.Customize<WebRoutingSettings>(x => x.With(settings => settings.UmbracoApplicationUrl, "http://localhost:5000"));
102+
103+
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
93104
}
94105
}
95106
}

0 commit comments

Comments
 (0)