Moves controller integration tests into correct namespace

This commit is contained in:
Shannon
2021-02-02 14:46:46 +11:00
parent d5f595def2
commit 2f97265bc0
5 changed files with 49 additions and 22 deletions

View File

@@ -19,7 +19,6 @@ using Umbraco.Core.Cache;
using Umbraco.Core.Composing; using Umbraco.Core.Composing;
using Umbraco.Core.DependencyInjection; using Umbraco.Core.DependencyInjection;
using Umbraco.Extensions; using Umbraco.Extensions;
using Umbraco.Infrastructure.PublishedCache.DependencyInjection;
using Umbraco.Tests.Integration.DependencyInjection; using Umbraco.Tests.Integration.DependencyInjection;
using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Integration.Testing;
using Umbraco.Tests.Testing; using Umbraco.Tests.Testing;
@@ -84,11 +83,32 @@ namespace Umbraco.Tests.Integration.TestServerTest
/// This returns the url but also sets the HttpContext.request into to use this url. /// This returns the url but also sets the HttpContext.request into to use this url.
/// </summary> /// </summary>
/// <returns>The string URL of the controller action.</returns> /// <returns>The string URL of the controller action.</returns>
protected string PrepareUrl<T>(Expression<Func<T, object>> methodSelector) protected string PrepareApiControllerUrl<T>(Expression<Func<T, object>> methodSelector)
where T : UmbracoApiController where T : UmbracoApiController
{ {
string url = LinkGenerator.GetUmbracoApiService<T>(methodSelector); string url = LinkGenerator.GetUmbracoApiService(methodSelector);
return PrepareUrl(url);
}
/// <summary>
/// Prepare a url before using <see cref="Client"/>.
/// This returns the url but also sets the HttpContext.request into to use this url.
/// </summary>
/// <returns>The string URL of the controller action.</returns>
protected string PrepareSurfaceControllerUrl<T>(Expression<Func<T, object>> methodSelector)
where T : SurfaceController
{
string url = LinkGenerator.GetUmbracoSurfaceUrl(methodSelector);
return PrepareUrl(url);
}
/// <summary>
/// Prepare a url before using <see cref="Client"/>.
/// This returns the url but also sets the HttpContext.request into to use this url.
/// </summary>
/// <returns>The string URL of the controller action.</returns>
protected string PrepareUrl(string url)
{
IBackOfficeSecurityFactory backofficeSecurityFactory = GetRequiredService<IBackOfficeSecurityFactory>(); IBackOfficeSecurityFactory backofficeSecurityFactory = GetRequiredService<IBackOfficeSecurityFactory>();
IUmbracoContextFactory umbracoContextFactory = GetRequiredService<IUmbracoContextFactory>(); IUmbracoContextFactory umbracoContextFactory = GetRequiredService<IUmbracoContextFactory>();
IHttpContextAccessor httpContextAccessor = GetRequiredService<IHttpContextAccessor>(); IHttpContextAccessor httpContextAccessor = GetRequiredService<IHttpContextAccessor>();
@@ -150,6 +170,9 @@ namespace Umbraco.Tests.Integration.TestServerTest
// Adds Umbraco.Web.Website // Adds Umbraco.Web.Website
mvcBuilder.AddApplicationPart(typeof(SurfaceController).Assembly); mvcBuilder.AddApplicationPart(typeof(SurfaceController).Assembly);
// Adds Umbraco.Tests.Integration
mvcBuilder.AddApplicationPart(typeof(UmbracoTestServerTestBase).Assembly);
}) })
.AddWebServer() .AddWebServer()
.AddWebsite() .AddWebsite()

View File

@@ -5,9 +5,10 @@ using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
using Umbraco.Tests.Integration.TestServerTest;
using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.BackOffice.Controllers;
namespace Umbraco.Tests.Integration.TestServerTest.Controllers namespace Umbraco.Tests.Integration.Umbraco.Web.BackOffice.Controllers
{ {
[TestFixture] [TestFixture]
public class BackOfficeAssetsControllerTests : UmbracoTestServerTestBase public class BackOfficeAssetsControllerTests : UmbracoTestServerTestBase
@@ -16,7 +17,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
public async Task EnsureSuccessStatusCode() public async Task EnsureSuccessStatusCode()
{ {
// Arrange // Arrange
string url = PrepareUrl<BackOfficeAssetsController>(x => x.GetSupportedLocales()); string url = PrepareApiControllerUrl<BackOfficeAssetsController>(x => x.GetSupportedLocales());
// Act // Act
HttpResponseMessage response = await Client.GetAsync(url); HttpResponseMessage response = await Client.GetAsync(url);

View File

@@ -12,11 +12,12 @@ using Umbraco.Core.Models;
using Umbraco.Core.Services; using Umbraco.Core.Services;
using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions; using Umbraco.Tests.Common.Builders.Extensions;
using Umbraco.Tests.Integration.TestServerTest;
using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.BackOffice.Controllers;
using Umbraco.Web.Common.Formatters; using Umbraco.Web.Common.Formatters;
using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Tests.Integration.TestServerTest.Controllers namespace Umbraco.Tests.Integration.Umbraco.Web.BackOffice.Controllers
{ {
[TestFixture] [TestFixture]
public class ContentControllerTests : UmbracoTestServerTestBase public class ContentControllerTests : UmbracoTestServerTestBase
@@ -35,7 +36,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
.WithIsDefault(false) .WithIsDefault(false)
.Build()); .Build());
string url = PrepareUrl<ContentController>(x => x.PostSave(null)); string url = PrepareApiControllerUrl<ContentController>(x => x.PostSave(null));
IContentService contentService = GetRequiredService<IContentService>(); IContentService contentService = GetRequiredService<IContentService>();
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>(); IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
@@ -93,7 +94,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
.WithIsDefault(false) .WithIsDefault(false)
.Build()); .Build());
string url = PrepareUrl<ContentController>(x => x.PostSave(null)); string url = PrepareApiControllerUrl<ContentController>(x => x.PostSave(null));
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>(); IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
@@ -162,7 +163,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
.WithIsDefault(false) .WithIsDefault(false)
.Build()); .Build());
string url = PrepareUrl<ContentController>(x => x.PostSave(null)); string url = PrepareApiControllerUrl<ContentController>(x => x.PostSave(null));
IContentService contentService = GetRequiredService<IContentService>(); IContentService contentService = GetRequiredService<IContentService>();
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>(); IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
@@ -227,7 +228,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
.WithIsDefault(false) .WithIsDefault(false)
.Build()); .Build());
string url = PrepareUrl<ContentController>(x => x.PostSave(null)); string url = PrepareApiControllerUrl<ContentController>(x => x.PostSave(null));
IContentService contentService = GetRequiredService<IContentService>(); IContentService contentService = GetRequiredService<IContentService>();
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>(); IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
@@ -288,7 +289,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
.WithIsDefault(false) .WithIsDefault(false)
.Build()); .Build());
string url = PrepareUrl<ContentController>(x => x.PostSave(null)); string url = PrepareApiControllerUrl<ContentController>(x => x.PostSave(null));
IContentService contentService = GetRequiredService<IContentService>(); IContentService contentService = GetRequiredService<IContentService>();
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>(); IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
@@ -352,7 +353,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
.WithIsDefault(false) .WithIsDefault(false)
.Build()); .Build());
string url = PrepareUrl<ContentController>(x => x.PostSave(null)); string url = PrepareApiControllerUrl<ContentController>(x => x.PostSave(null));
IContentService contentService = GetRequiredService<IContentService>(); IContentService contentService = GetRequiredService<IContentService>();
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>(); IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();

View File

@@ -11,12 +11,13 @@ using Newtonsoft.Json.Linq;
using NUnit.Framework; using NUnit.Framework;
using Umbraco.Core; using Umbraco.Core;
using Umbraco.Tests.Common.Builders.Extensions; using Umbraco.Tests.Common.Builders.Extensions;
using Umbraco.Tests.Integration.TestServerTest;
using Umbraco.Tests.Testing; using Umbraco.Tests.Testing;
using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.BackOffice.Controllers;
using Umbraco.Web.Common.Formatters; using Umbraco.Web.Common.Formatters;
using Umbraco.Web.Models.TemplateQuery; using Umbraco.Web.Models.TemplateQuery;
namespace Umbraco.Tests.Integration.TestServerTest.Controllers namespace Umbraco.Tests.Integration.Umbraco.Web.BackOffice.Controllers
{ {
[TestFixture] [TestFixture]
public class TemplateQueryControllerTests : UmbracoTestServerTestBase public class TemplateQueryControllerTests : UmbracoTestServerTestBase
@@ -24,7 +25,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
[Test] [Test]
public async Task GetContentTypes__Ensure_camel_case() public async Task GetContentTypes__Ensure_camel_case()
{ {
string url = PrepareUrl<TemplateQueryController>(x => x.GetContentTypes()); string url = PrepareApiControllerUrl<TemplateQueryController>(x => x.GetContentTypes());
// Act // Act
HttpResponseMessage response = await Client.GetAsync(url); HttpResponseMessage response = await Client.GetAsync(url);

View File

@@ -17,13 +17,14 @@ using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services; using Umbraco.Core.Services;
using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions; using Umbraco.Tests.Common.Builders.Extensions;
using Umbraco.Tests.Integration.TestServerTest;
using Umbraco.Tests.Testing; using Umbraco.Tests.Testing;
using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.BackOffice.Controllers;
using Umbraco.Web.Common.Filters; using Umbraco.Web.Common.Filters;
using Umbraco.Web.Common.Formatters; using Umbraco.Web.Common.Formatters;
using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Tests.Integration.TestServerTest.Controllers namespace Umbraco.Tests.Integration.Umbraco.Web.BackOffice.Controllers
{ {
[TestFixture] [TestFixture]
public class UsersControllerTests : UmbracoTestServerTestBase public class UsersControllerTests : UmbracoTestServerTestBase
@@ -31,7 +32,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
[Test] [Test]
public async Task Save_User() public async Task Save_User()
{ {
string url = PrepareUrl<UsersController>(x => x.PostSaveUser(null)); string url = PrepareApiControllerUrl<UsersController>(x => x.PostSaveUser(null));
IUserService userService = GetRequiredService<IUserService>(); IUserService userService = GetRequiredService<IUserService>();
@@ -81,7 +82,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
public async Task GetPagedUsers_Empty() public async Task GetPagedUsers_Empty()
{ {
// We get page 2 to force an empty response because there always in the useradmin user // We get page 2 to force an empty response because there always in the useradmin user
string url = PrepareUrl<UsersController>(x => x.GetPagedUsers(2, 10, "username", Direction.Ascending, null, null, string.Empty)); string url = PrepareApiControllerUrl<UsersController>(x => x.GetPagedUsers(2, 10, "username", Direction.Ascending, null, null, string.Empty));
// Act // Act
HttpResponseMessage response = await Client.GetAsync(url); HttpResponseMessage response = await Client.GetAsync(url);
@@ -106,7 +107,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
{ {
int totalNumberOfUsers = 11; int totalNumberOfUsers = 11;
int pageSize = totalNumberOfUsers - 1; int pageSize = totalNumberOfUsers - 1;
string url = PrepareUrl<UsersController>(x => x.GetPagedUsers(1, pageSize, "username", Direction.Ascending, null, null, string.Empty)); string url = PrepareApiControllerUrl<UsersController>(x => x.GetPagedUsers(1, pageSize, "username", Direction.Ascending, null, null, string.Empty));
IUserService userService = GetRequiredService<IUserService>(); IUserService userService = GetRequiredService<IUserService>();
@@ -144,7 +145,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
[Test] [Test]
public async Task PostUnlockUsers_When_UserIds_Not_Supplied_Expect_Ok_Response() public async Task PostUnlockUsers_When_UserIds_Not_Supplied_Expect_Ok_Response()
{ {
string url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(Array.Empty<int>())); string url = PrepareApiControllerUrl<UsersController>(x => x.PostUnlockUsers(Array.Empty<int>()));
// Act // Act
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty)); HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));
@@ -156,7 +157,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
public async Task PostUnlockUsers_When_User_Does_Not_Exist_Expect_Zero_Users_Message() public async Task PostUnlockUsers_When_User_Does_Not_Exist_Expect_Zero_Users_Message()
{ {
int userId = 42; // Must not exist int userId = 42; // Must not exist
string url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(new[] { userId })); string url = PrepareApiControllerUrl<UsersController>(x => x.PostUnlockUsers(new[] { userId }));
// Act // Act
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty)); HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));
@@ -184,7 +185,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
.Build(); .Build();
userService.Save(user); userService.Save(user);
string url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(new[] { user.Id })); string url = PrepareApiControllerUrl<UsersController>(x => x.PostUnlockUsers(new[] { user.Id }));
// Act // Act
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty)); HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));
@@ -228,7 +229,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
userService.Save(user); userService.Save(user);
} }
string url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(users.Select(x => x.Id).ToArray())); string url = PrepareApiControllerUrl<UsersController>(x => x.PostUnlockUsers(users.Select(x => x.Id).ToArray()));
// Act // Act
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty)); HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));