重构代码:ProfileController 保存样式检查用户名
This commit is contained in:
parent
78a38b7f8b
commit
50b2d4ecd4
|
@ -126,13 +126,11 @@ namespace Bootstrap.Admin.Controllers.Api
|
||||||
public bool Put([FromBody]User value)
|
public bool Put([FromBody]User value)
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
if (value.UserStatus == UserStates.ChangeTheme)
|
|
||||||
{
|
|
||||||
return UserHelper.SaveUserCssByName(value.UserName, value.Css);
|
|
||||||
}
|
|
||||||
if (value.UserName.Equals(User.Identity.Name, StringComparison.OrdinalIgnoreCase))
|
if (value.UserName.Equals(User.Identity.Name, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
if (value.UserStatus == UserStates.ChangeDisplayName)
|
if (value.UserStatus == UserStates.ChangeTheme)
|
||||||
|
ret = UserHelper.SaveUserCssByName(value.UserName, value.Css);
|
||||||
|
else if (value.UserStatus == UserStates.ChangeDisplayName)
|
||||||
ret = UserHelper.SaveDisplayName(value.UserName, value.DisplayName);
|
ret = UserHelper.SaveDisplayName(value.UserName, value.DisplayName);
|
||||||
else if (value.UserStatus == UserStates.ChangePassword)
|
else if (value.UserStatus == UserStates.ChangePassword)
|
||||||
ret = UserHelper.ChangePassword(value.UserName, value.Password, value.NewPassword);
|
ret = UserHelper.ChangePassword(value.UserName, value.Password, value.NewPassword);
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using Bootstrap.DataAccess;
|
using Bootstrap.DataAccess;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Bootstrap.Admin.Api
|
namespace Bootstrap.Admin.Api
|
||||||
|
@ -10,41 +8,48 @@ namespace Bootstrap.Admin.Api
|
||||||
public ProfilesTest(BAWebHost factory) : base(factory, "api/Profiles") { }
|
public ProfilesTest(BAWebHost factory) : base(factory, "api/Profiles") { }
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void Put_Ok()
|
public async void Put_SaveTheme()
|
||||||
{
|
{
|
||||||
var usr = new User { UserName = "UnitTest_Change", Password = "1", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "default.jpg", Css = "blue.css" };
|
var usr = new User { UserName = "Admin" };
|
||||||
usr.Delete(usr.Retrieves().Where(u => u.UserName == usr.UserName).Select(u => u.Id));
|
|
||||||
Assert.True(usr.Save(usr));
|
|
||||||
|
|
||||||
// change theme
|
// change theme
|
||||||
|
usr.Css = "blue.css";
|
||||||
usr.UserStatus = UserStates.ChangeTheme;
|
usr.UserStatus = UserStates.ChangeTheme;
|
||||||
var resp = await Client.PutAsJsonAsync<User, bool>(usr);
|
var resp = await Client.PutAsJsonAsync<User, bool>(usr);
|
||||||
Assert.True(resp);
|
Assert.True(resp);
|
||||||
|
}
|
||||||
|
|
||||||
// Login as new user
|
[Fact]
|
||||||
var client = Host.CreateClient();
|
public async void Put_ChangePassword()
|
||||||
await client.LoginAsync("UnitTest_Change", "1");
|
{
|
||||||
|
var usr = new User() { UserName = "Admin" };
|
||||||
// change password
|
// change password
|
||||||
usr.UserStatus = UserStates.ChangePassword;
|
usr.UserStatus = UserStates.ChangePassword;
|
||||||
usr.NewPassword = "1";
|
usr.NewPassword = "123789";
|
||||||
usr.Password = "1";
|
usr.Password = "123789";
|
||||||
resp = await client.PutAsJsonAsync<User, bool>("/api/Profiles", usr);
|
var resp = await Client.PutAsJsonAsync<User, bool>(usr);
|
||||||
Assert.True(resp);
|
Assert.True(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void Put_ChangeDisplayName()
|
||||||
|
{
|
||||||
|
var usr = new User() { UserName = "Admin" };
|
||||||
// change displayname
|
// change displayname
|
||||||
usr.UserStatus = UserStates.ChangeDisplayName;
|
usr.UserStatus = UserStates.ChangeDisplayName;
|
||||||
resp = await client.PutAsJsonAsync<User, bool>("/api/Profiles", usr);
|
usr.DisplayName = "Administrator";
|
||||||
|
var resp = await Client.PutAsJsonAsync<User, bool>(usr);
|
||||||
Assert.True(resp);
|
Assert.True(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void Put_SaveApp()
|
||||||
|
{
|
||||||
|
var usr = new User() { UserName = "Admin" };
|
||||||
// change app
|
// change app
|
||||||
usr.App = "UnitTest";
|
usr.App = "UnitTest";
|
||||||
usr.UserStatus = UserStates.SaveApp;
|
usr.UserStatus = UserStates.SaveApp;
|
||||||
resp = await client.PutAsJsonAsync<User, bool>("/api/Profiles", usr);
|
var resp = await Client.PutAsJsonAsync<User, bool>(usr);
|
||||||
Assert.True(resp);
|
Assert.True(resp);
|
||||||
|
|
||||||
// delete
|
|
||||||
usr.Delete(usr.Retrieves().Where(u => u.UserName == usr.UserName).Select(u => u.Id));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue