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.DependencyInjection;
using Umbraco.Extensions;
using Umbraco.Infrastructure.PublishedCache.DependencyInjection;
using Umbraco.Tests.Integration.DependencyInjection;
using Umbraco.Tests.Integration.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.
/// </summary>
/// <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
{
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>();
IUmbracoContextFactory umbracoContextFactory = GetRequiredService<IUmbracoContextFactory>();
IHttpContextAccessor httpContextAccessor = GetRequiredService<IHttpContextAccessor>();
@@ -150,6 +170,9 @@ namespace Umbraco.Tests.Integration.TestServerTest
// Adds Umbraco.Web.Website
mvcBuilder.AddApplicationPart(typeof(SurfaceController).Assembly);
// Adds Umbraco.Tests.Integration
mvcBuilder.AddApplicationPart(typeof(UmbracoTestServerTestBase).Assembly);
})
.AddWebServer()
.AddWebsite()

View File

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

View File

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

View File

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

View File

@@ -17,13 +17,14 @@ using Umbraco.Core.Models.Membership;
using Umbraco.Core.Services;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Common.Builders.Extensions;
using Umbraco.Tests.Integration.TestServerTest;
using Umbraco.Tests.Testing;
using Umbraco.Web.BackOffice.Controllers;
using Umbraco.Web.Common.Filters;
using Umbraco.Web.Common.Formatters;
using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Tests.Integration.TestServerTest.Controllers
namespace Umbraco.Tests.Integration.Umbraco.Web.BackOffice.Controllers
{
[TestFixture]
public class UsersControllerTests : UmbracoTestServerTestBase
@@ -31,7 +32,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
[Test]
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>();
@@ -81,7 +82,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
public async Task GetPagedUsers_Empty()
{
// 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
HttpResponseMessage response = await Client.GetAsync(url);
@@ -106,7 +107,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
{
int totalNumberOfUsers = 11;
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>();
@@ -144,7 +145,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
[Test]
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
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()
{
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
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));
@@ -184,7 +185,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
.Build();
userService.Save(user);
string url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(new[] { user.Id }));
string url = PrepareApiControllerUrl<UsersController>(x => x.PostUnlockUsers(new[] { user.Id }));
// Act
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));
@@ -228,7 +229,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
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
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));