Applied linting rules to tests within the Umbraco.Tests.Integration project.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web.BackOffice.Controllers;
|
||||
|
||||
namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
@@ -13,10 +16,10 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
public async Task EnsureSuccessStatusCode()
|
||||
{
|
||||
// Arrange
|
||||
var url = PrepareUrl<BackOfficeAssetsController>(x=>x.GetSupportedLocales());
|
||||
string url = PrepareUrl<BackOfficeAssetsController>(x => x.GetSupportedLocales());
|
||||
|
||||
// Act
|
||||
var response = await Client.GetAsync(url);
|
||||
HttpResponseMessage response = await Client.GetAsync(url);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
@@ -18,14 +21,13 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
[TestFixture]
|
||||
public class ContentControllerTests : UmbracoTestServerTestBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Returns 404 if the content wasn't found based on the ID specified
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task PostSave_Validate_Existing_Content()
|
||||
{
|
||||
var localizationService = GetRequiredService<ILocalizationService>();
|
||||
ILocalizationService localizationService = GetRequiredService<ILocalizationService>();
|
||||
|
||||
// Add another language
|
||||
localizationService.Save(new LanguageBuilder()
|
||||
@@ -33,12 +35,12 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
.WithIsDefault(false)
|
||||
.Build());
|
||||
|
||||
var url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
string url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
|
||||
var contentService = GetRequiredService<IContentService>();
|
||||
var contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
IContentService contentService = GetRequiredService<IContentService>();
|
||||
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
|
||||
var contentType = new ContentTypeBuilder()
|
||||
IContentType contentType = new ContentTypeBuilder()
|
||||
.WithId(0)
|
||||
.AddPropertyType()
|
||||
.WithAlias("title")
|
||||
@@ -51,7 +53,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var content = new ContentBuilder()
|
||||
Content content = new ContentBuilder()
|
||||
.WithId(0)
|
||||
.WithName("Invariant")
|
||||
.WithContentType(contentType)
|
||||
@@ -61,31 +63,29 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
.Build();
|
||||
contentService.SaveAndPublish(content);
|
||||
|
||||
var model = new ContentItemSaveBuilder()
|
||||
ContentItemSave model = new ContentItemSaveBuilder()
|
||||
.WithContent(content)
|
||||
.WithId(-1337) // HERE We overwrite the Id, so we don't expect to find it on the server
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
HttpResponseMessage response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(JsonConvert.SerializeObject(model)), "contentItem" }
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
|
||||
// Assert.AreEqual(")]}',\n{\"Message\":\"content was not found\"}", response.Item1.Content.ReadAsStringAsync().Result);
|
||||
//
|
||||
// //var obj = JsonConvert.DeserializeObject<PagedResult<UserDisplay>>(response.Item2);
|
||||
// //Assert.AreEqual(0, obj.TotalItems);
|
||||
//// Assert.AreEqual(")]}',\n{\"Message\":\"content was not found\"}", response.Item1.Content.ReadAsStringAsync().Result);
|
||||
////
|
||||
//// //var obj = JsonConvert.DeserializeObject<PagedResult<UserDisplay>>(response.Item2);
|
||||
//// //Assert.AreEqual(0, obj.TotalItems);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PostSave_Validate_At_Least_One_Variant_Flagged_For_Saving()
|
||||
{
|
||||
|
||||
var localizationService = GetRequiredService<ILocalizationService>();
|
||||
ILocalizationService localizationService = GetRequiredService<ILocalizationService>();
|
||||
|
||||
// Add another language
|
||||
localizationService.Save(new LanguageBuilder()
|
||||
@@ -93,11 +93,11 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
.WithIsDefault(false)
|
||||
.Build());
|
||||
|
||||
var url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
string url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
|
||||
var contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
|
||||
var contentType = new ContentTypeBuilder()
|
||||
IContentType contentType = new ContentTypeBuilder()
|
||||
.WithId(0)
|
||||
.AddPropertyType()
|
||||
.WithAlias("title")
|
||||
@@ -110,8 +110,8 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var contentService = GetRequiredService<IContentService>();
|
||||
var content = new ContentBuilder()
|
||||
IContentService contentService = GetRequiredService<IContentService>();
|
||||
Content content = new ContentBuilder()
|
||||
.WithId(0)
|
||||
.WithName("Invariant")
|
||||
.WithContentType(contentType)
|
||||
@@ -121,7 +121,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
.Build();
|
||||
contentService.SaveAndPublish(content);
|
||||
|
||||
var model = new ContentItemSaveBuilder()
|
||||
ContentItemSave model = new ContentItemSaveBuilder()
|
||||
.WithContent(content)
|
||||
.Build();
|
||||
|
||||
@@ -133,20 +133,19 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
});
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
HttpResponseMessage response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(JsonConvert.SerializeObject(model)), "contentItem" }
|
||||
});
|
||||
|
||||
// Assert
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
|
||||
Assert.AreEqual(AngularJsonMediaTypeFormatter.XsrfPrefix + "{\"Message\":\"No variants flagged for saving\"}", body);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -155,7 +154,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
[Test]
|
||||
public async Task PostSave_Validate_Properties_Exist()
|
||||
{
|
||||
var localizationService = GetRequiredService<ILocalizationService>();
|
||||
ILocalizationService localizationService = GetRequiredService<ILocalizationService>();
|
||||
|
||||
// Add another language
|
||||
localizationService.Save(new LanguageBuilder()
|
||||
@@ -163,12 +162,12 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
.WithIsDefault(false)
|
||||
.Build());
|
||||
|
||||
var url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
string url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
|
||||
var contentService = GetRequiredService<IContentService>();
|
||||
var contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
IContentService contentService = GetRequiredService<IContentService>();
|
||||
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
|
||||
var contentType = new ContentTypeBuilder()
|
||||
IContentType contentType = new ContentTypeBuilder()
|
||||
.WithId(0)
|
||||
.AddPropertyType()
|
||||
.WithAlias("title")
|
||||
@@ -181,7 +180,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var content = new ContentBuilder()
|
||||
Content content = new ContentBuilder()
|
||||
.WithId(0)
|
||||
.WithName("Invariant")
|
||||
.WithContentType(contentType)
|
||||
@@ -191,7 +190,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
.Build();
|
||||
contentService.SaveAndPublish(content);
|
||||
|
||||
var model = new ContentItemSaveBuilder()
|
||||
ContentItemSave model = new ContentItemSaveBuilder()
|
||||
.WithId(content.Id)
|
||||
.WithContentTypeAlias(content.ContentType.Alias)
|
||||
.AddVariant()
|
||||
@@ -203,15 +202,14 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
.Done()
|
||||
.Build();
|
||||
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
HttpResponseMessage response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(JsonConvert.SerializeObject(model)), "contentItem" }
|
||||
});
|
||||
|
||||
// Assert
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
|
||||
@@ -221,20 +219,20 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
[Test]
|
||||
public async Task PostSave_Simple_Invariant()
|
||||
{
|
||||
var localizationService = GetRequiredService<ILocalizationService>();
|
||||
ILocalizationService localizationService = GetRequiredService<ILocalizationService>();
|
||||
|
||||
//Add another language
|
||||
// Add another language
|
||||
localizationService.Save(new LanguageBuilder()
|
||||
.WithCultureInfo("da-DK")
|
||||
.WithIsDefault(false)
|
||||
.Build());
|
||||
|
||||
var url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
string url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
|
||||
var contentService = GetRequiredService<IContentService>();
|
||||
var contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
IContentService contentService = GetRequiredService<IContentService>();
|
||||
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
|
||||
var contentType = new ContentTypeBuilder()
|
||||
IContentType contentType = new ContentTypeBuilder()
|
||||
.WithId(0)
|
||||
.AddPropertyType()
|
||||
.WithAlias("title")
|
||||
@@ -247,7 +245,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var content = new ContentBuilder()
|
||||
Content content = new ContentBuilder()
|
||||
.WithId(0)
|
||||
.WithName("Invariant")
|
||||
.WithContentType(contentType)
|
||||
@@ -256,49 +254,46 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
.Done()
|
||||
.Build();
|
||||
contentService.SaveAndPublish(content);
|
||||
var model = new ContentItemSaveBuilder()
|
||||
ContentItemSave model = new ContentItemSaveBuilder()
|
||||
.WithContent(content)
|
||||
.Build();
|
||||
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
HttpResponseMessage response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(JsonConvert.SerializeObject(model)), "contentItem" }
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, body);
|
||||
var display = JsonConvert.DeserializeObject<ContentItemDisplay>(body);
|
||||
ContentItemDisplay display = JsonConvert.DeserializeObject<ContentItemDisplay>(body);
|
||||
Assert.AreEqual(1, display.Variants.Count());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PostSave_Validate_Empty_Name()
|
||||
{
|
||||
var localizationService = GetRequiredService<ILocalizationService>();
|
||||
ILocalizationService localizationService = GetRequiredService<ILocalizationService>();
|
||||
|
||||
//Add another language
|
||||
// Add another language
|
||||
localizationService.Save(new LanguageBuilder()
|
||||
.WithCultureInfo("da-DK")
|
||||
.WithIsDefault(false)
|
||||
.Build());
|
||||
|
||||
var url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
string url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
|
||||
var contentService = GetRequiredService<IContentService>();
|
||||
var contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
IContentService contentService = GetRequiredService<IContentService>();
|
||||
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
|
||||
var contentType = new ContentTypeBuilder()
|
||||
IContentType contentType = new ContentTypeBuilder()
|
||||
.WithId(0)
|
||||
.AddPropertyType()
|
||||
.WithAlias("title")
|
||||
@@ -311,7 +306,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var content = new ContentBuilder()
|
||||
Content content = new ContentBuilder()
|
||||
.WithId(0)
|
||||
.WithName("Invariant")
|
||||
.WithContentType(contentType)
|
||||
@@ -322,27 +317,25 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
contentService.SaveAndPublish(content);
|
||||
|
||||
content.Name = null; // Removes the name of one of the variants to force an error
|
||||
var model = new ContentItemSaveBuilder()
|
||||
ContentItemSave model = new ContentItemSaveBuilder()
|
||||
.WithContent(content)
|
||||
.Build();
|
||||
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
HttpResponseMessage response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(JsonConvert.SerializeObject(model)), "contentItem" }
|
||||
});
|
||||
|
||||
// Assert
|
||||
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
var display = JsonConvert.DeserializeObject<ContentItemDisplay>(body);
|
||||
ContentItemDisplay display = JsonConvert.DeserializeObject<ContentItemDisplay>(body);
|
||||
Assert.AreEqual(1, display.Errors.Count(), string.Join(",", display.Errors));
|
||||
CollectionAssert.Contains(display.Errors.Keys, "Variants[0].Name");
|
||||
});
|
||||
@@ -351,20 +344,20 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
[Test]
|
||||
public async Task PostSave_Validate_Variants_Empty_Name()
|
||||
{
|
||||
var localizationService = GetRequiredService<ILocalizationService>();
|
||||
ILocalizationService localizationService = GetRequiredService<ILocalizationService>();
|
||||
|
||||
//Add another language
|
||||
// Add another language
|
||||
localizationService.Save(new LanguageBuilder()
|
||||
.WithCultureInfo("da-DK")
|
||||
.WithIsDefault(false)
|
||||
.Build());
|
||||
|
||||
var url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
string url = PrepareUrl<ContentController>(x => x.PostSave(null));
|
||||
|
||||
var contentService = GetRequiredService<IContentService>();
|
||||
var contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
IContentService contentService = GetRequiredService<IContentService>();
|
||||
IContentTypeService contentTypeService = GetRequiredService<IContentTypeService>();
|
||||
|
||||
var contentType = new ContentTypeBuilder()
|
||||
IContentType contentType = new ContentTypeBuilder()
|
||||
.WithId(0)
|
||||
.AddPropertyType()
|
||||
.WithAlias("title")
|
||||
@@ -377,7 +370,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
|
||||
contentTypeService.Save(contentType);
|
||||
|
||||
var content = new ContentBuilder()
|
||||
Content content = new ContentBuilder()
|
||||
.WithId(0)
|
||||
.WithCultureName("en-US", "English")
|
||||
.WithCultureName("da-DK", "Danish")
|
||||
@@ -389,30 +382,27 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
contentService.SaveAndPublish(content);
|
||||
|
||||
content.CultureInfos[0].Name = null; // Removes the name of one of the variants to force an error
|
||||
var model = new ContentItemSaveBuilder()
|
||||
ContentItemSave model = new ContentItemSaveBuilder()
|
||||
.WithContent(content)
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
HttpResponseMessage response = await Client.PostAsync(url, new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(JsonConvert.SerializeObject(model)), "contentItem" }
|
||||
});
|
||||
|
||||
// Assert
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
var display = JsonConvert.DeserializeObject<ContentItemDisplay>(body);
|
||||
ContentItemDisplay display = JsonConvert.DeserializeObject<ContentItemDisplay>(body);
|
||||
Assert.AreEqual(2, display.Errors.Count());
|
||||
CollectionAssert.Contains(display.Errors.Keys, "Variants[0].Name");
|
||||
CollectionAssert.Contains(display.Errors.Keys, "_content_variant_en-US_null_");
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
@@ -20,12 +24,12 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
[Test]
|
||||
public async Task GetContentTypes__Ensure_camel_case()
|
||||
{
|
||||
var url = PrepareUrl<TemplateQueryController>(x => x.GetContentTypes());
|
||||
string url = PrepareUrl<TemplateQueryController>(x => x.GetContentTypes());
|
||||
|
||||
// Act
|
||||
var response = await Client.GetAsync(url);
|
||||
HttpResponseMessage response = await Client.GetAsync(url);
|
||||
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
|
||||
@@ -36,17 +40,15 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
|
||||
Assert.DoesNotThrow(() => JsonConvert.DeserializeObject<ContentTypeModel[]>(body));
|
||||
|
||||
var jtokens = JsonConvert.DeserializeObject<JToken[]>(body);
|
||||
foreach (var jToken in jtokens)
|
||||
JToken[] jtokens = JsonConvert.DeserializeObject<JToken[]>(body);
|
||||
foreach (JToken jToken in jtokens)
|
||||
{
|
||||
var alias = nameof(ContentTypeModel.Alias);
|
||||
var camelCaseAlias = alias.ToCamelCase();
|
||||
string alias = nameof(ContentTypeModel.Alias);
|
||||
string camelCaseAlias = alias.ToCamelCase();
|
||||
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");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -28,11 +31,11 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
[Test]
|
||||
public async Task Save_User()
|
||||
{
|
||||
var url = PrepareUrl<UsersController>(x => x.PostSaveUser(null));
|
||||
string url = PrepareUrl<UsersController>(x => x.PostSaveUser(null));
|
||||
|
||||
var userService = GetRequiredService<IUserService>();
|
||||
IUserService userService = GetRequiredService<IUserService>();
|
||||
|
||||
var user = new UserBuilder()
|
||||
User user = new UserBuilder()
|
||||
.AddUserGroup()
|
||||
.WithAlias("writer") // Needs to be an existing alias
|
||||
.Done()
|
||||
@@ -49,101 +52,102 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
Name = user.Name,
|
||||
UserGroups = user.Groups.Select(x => x.Alias).ToArray()
|
||||
};
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url,
|
||||
new StringContent(JsonConvert.SerializeObject(userSave), Encoding.UTF8,
|
||||
MediaTypeNames.Application.Json));
|
||||
HttpResponseMessage response = await Client.PostAsync(
|
||||
url,
|
||||
new StringContent(JsonConvert.SerializeObject(userSave), Encoding.UTF8, MediaTypeNames.Application.Json));
|
||||
|
||||
// Assert
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
var body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
string body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
var actual = JsonConvert.DeserializeObject<UserDisplay>(body, new JsonSerializerSettings
|
||||
UserDisplay actual = JsonConvert.DeserializeObject<UserDisplay>(body, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new IgnoreRequiredAttributesResolver()
|
||||
});
|
||||
Assert.AreEqual(userSave.Name, actual.Name);
|
||||
Assert.AreEqual(userSave.Id, actual.Id);
|
||||
Assert.AreEqual(userSave.Email, actual.Email);
|
||||
var userGroupAliases = actual.UserGroups.Select(x => x.Alias).ToArray();
|
||||
string[] userGroupAliases = actual.UserGroups.Select(x => x.Alias).ToArray();
|
||||
CollectionAssert.AreEquivalent(userSave.UserGroups, userGroupAliases);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetPagedUsers_Empty()
|
||||
{
|
||||
//We get page 2 to force an empty response because there always in the useradmin user
|
||||
var url = PrepareUrl<UsersController>(x => x.GetPagedUsers(2, 10, "username", Direction.Ascending, null, null, string.Empty));
|
||||
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));
|
||||
|
||||
// Act
|
||||
var response = await Client.GetAsync(url);
|
||||
// Act
|
||||
HttpResponseMessage response = await Client.GetAsync(url);
|
||||
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
var actual = JsonConvert.DeserializeObject<PagedResult<UserBasic>>(body, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new IgnoreRequiredAttributesResolver()
|
||||
});
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.IsNotNull(actual);
|
||||
Assert.AreEqual(1, actual.TotalItems);
|
||||
CollectionAssert.IsEmpty(actual.Items);
|
||||
});
|
||||
}
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
PagedResult<UserBasic> actual = JsonConvert.DeserializeObject<PagedResult<UserBasic>>(body, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new IgnoreRequiredAttributesResolver()
|
||||
});
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.IsNotNull(actual);
|
||||
Assert.AreEqual(1, actual.TotalItems);
|
||||
CollectionAssert.IsEmpty(actual.Items);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetPagedUsers_multiple_pages()
|
||||
{
|
||||
var totalNumberOfUsers = 11;
|
||||
var pageSize = totalNumberOfUsers - 1;
|
||||
var url = PrepareUrl<UsersController>(x => x.GetPagedUsers(1, pageSize, "username", Direction.Ascending, null, null, string.Empty));
|
||||
[Test]
|
||||
public async Task GetPagedUsers_multiple_pages()
|
||||
{
|
||||
int totalNumberOfUsers = 11;
|
||||
int pageSize = totalNumberOfUsers - 1;
|
||||
string url = PrepareUrl<UsersController>(x => x.GetPagedUsers(1, pageSize, "username", Direction.Ascending, null, null, string.Empty));
|
||||
|
||||
var userService = GetRequiredService<IUserService>();
|
||||
IUserService userService = GetRequiredService<IUserService>();
|
||||
|
||||
for (int i = 1; i < totalNumberOfUsers; i++) // We already has admin user = -1, so we start from 1
|
||||
{
|
||||
var user = new UserBuilder()
|
||||
// We already has admin user = -1, so we start from 1.
|
||||
for (int i = 1; i < totalNumberOfUsers; i++)
|
||||
{
|
||||
User user = new UserBuilder()
|
||||
.WithName($"Test user {i}")
|
||||
.AddUserGroup()
|
||||
.WithAlias("writer") // Needs to be an existing alias
|
||||
.Done()
|
||||
.Build();
|
||||
|
||||
userService.Save(user);
|
||||
}
|
||||
|
||||
// Act
|
||||
var response = await Client.GetAsync(url);
|
||||
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
var actual = JsonConvert.DeserializeObject<PagedResult<UserBasic>>(body, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new IgnoreRequiredAttributesResolver()
|
||||
});
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.IsNotNull(actual);
|
||||
Assert.AreEqual(totalNumberOfUsers, actual.TotalItems);
|
||||
Assert.AreEqual(pageSize, actual.Items.Count());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PostUnlockUsers_When_UserIds_Not_Supplied_Expect_Ok_Response()
|
||||
{
|
||||
var url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(Array.Empty<int>()));
|
||||
userService.Save(user);
|
||||
}
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url, new StringContent(string.Empty));
|
||||
HttpResponseMessage response = await Client.GetAsync(url);
|
||||
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
PagedResult<UserBasic> actual = JsonConvert.DeserializeObject<PagedResult<UserBasic>>(body, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new IgnoreRequiredAttributesResolver()
|
||||
});
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.IsNotNull(actual);
|
||||
Assert.AreEqual(totalNumberOfUsers, actual.TotalItems);
|
||||
Assert.AreEqual(pageSize, actual.Items.Count());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PostUnlockUsers_When_UserIds_Not_Supplied_Expect_Ok_Response()
|
||||
{
|
||||
string url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(Array.Empty<int>()));
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));
|
||||
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
}
|
||||
@@ -151,31 +155,28 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
[Test]
|
||||
public async Task PostUnlockUsers_When_User_Does_Not_Exist_Expect_Zero_Users_Message()
|
||||
{
|
||||
var userId = 42; // Must not exist
|
||||
var url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(new []{userId}));
|
||||
int userId = 42; // Must not exist
|
||||
string url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(new[] { userId }));
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url, new StringContent(string.Empty));
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var actual = JsonConvert.DeserializeObject<SimpleNotificationModel>(body, new JsonSerializerSettings
|
||||
SimpleNotificationModel actual = JsonConvert.DeserializeObject<SimpleNotificationModel>(body, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new IgnoreRequiredAttributesResolver()
|
||||
});
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual($"Unlocked 0 users", actual.Message);
|
||||
});
|
||||
Assert.Multiple(() => Assert.AreEqual($"Unlocked 0 users", actual.Message));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PostUnlockUsers_When_One_UserId_Supplied_Expect_User_Locked_Out_With_Correct_Response_Message()
|
||||
{
|
||||
var userService = GetRequiredService<IUserService>();
|
||||
IUserService userService = GetRequiredService<IUserService>();
|
||||
|
||||
var user = new UserBuilder()
|
||||
User user = new UserBuilder()
|
||||
.AddUserGroup()
|
||||
.WithAlias("writer") // Needs to be an existing alias
|
||||
.Done()
|
||||
@@ -183,14 +184,14 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
.Build();
|
||||
|
||||
userService.Save(user);
|
||||
var url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(new []{user.Id}));
|
||||
string url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(new[] { user.Id }));
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url, new StringContent(string.Empty));
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
var actual = JsonConvert.DeserializeObject<SimpleNotificationModel>(body, new JsonSerializerSettings
|
||||
SimpleNotificationModel actual = JsonConvert.DeserializeObject<SimpleNotificationModel>(body, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new IgnoreRequiredAttributesResolver()
|
||||
});
|
||||
@@ -205,8 +206,8 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
[Test]
|
||||
public async Task PostUnlockUsers_When_Multiple_UserIds_Supplied_Expect_User_Locked_Out_With_Correct_Response_Message()
|
||||
{
|
||||
var numberOfUsers = 3;
|
||||
var userService = GetRequiredService<IUserService>();
|
||||
int numberOfUsers = 3;
|
||||
IUserService userService = GetRequiredService<IUserService>();
|
||||
|
||||
var users = new List<IUser>();
|
||||
for (int i = 0; i < numberOfUsers; i++)
|
||||
@@ -222,19 +223,19 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
.Build());
|
||||
}
|
||||
|
||||
foreach (var user in users)
|
||||
foreach (IUser user in users)
|
||||
{
|
||||
userService.Save(user);
|
||||
}
|
||||
|
||||
var url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(users.Select(x=>x.Id).ToArray()));
|
||||
string url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(users.Select(x => x.Id).ToArray()));
|
||||
|
||||
// Act
|
||||
var response = await Client.PostAsync(url, new StringContent(string.Empty));
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
HttpResponseMessage response = await Client.PostAsync(url, new StringContent(string.Empty));
|
||||
string body = await response.Content.ReadAsStringAsync();
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
var actual = JsonConvert.DeserializeObject<SimpleNotificationModel>(body, new JsonSerializerSettings
|
||||
SimpleNotificationModel actual = JsonConvert.DeserializeObject<SimpleNotificationModel>(body, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new IgnoreRequiredAttributesResolver()
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user