diff --git a/Bootstrap.Admin/Controllers/Api/ProfilesController.cs b/Bootstrap.Admin/Controllers/Api/ProfilesController.cs index 746cbea8..07a630a4 100644 --- a/Bootstrap.Admin/Controllers/Api/ProfilesController.cs +++ b/Bootstrap.Admin/Controllers/Api/ProfilesController.cs @@ -126,13 +126,11 @@ namespace Bootstrap.Admin.Controllers.Api public bool Put([FromBody]User value) { 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.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); else if (value.UserStatus == UserStates.ChangePassword) ret = UserHelper.ChangePassword(value.UserName, value.Password, value.NewPassword); diff --git a/UnitTest/Bootstrap.Admin/Api/ProfilesTest.cs b/UnitTest/Bootstrap.Admin/Api/ProfilesTest.cs index 6d3b002c..bb2ad4f4 100644 --- a/UnitTest/Bootstrap.Admin/Api/ProfilesTest.cs +++ b/UnitTest/Bootstrap.Admin/Api/ProfilesTest.cs @@ -1,50 +1,55 @@ -using Bootstrap.DataAccess; -using System; -using System.Linq; -using Xunit; - -namespace Bootstrap.Admin.Api -{ - public class ProfilesTest : ControllerTest - { +using Bootstrap.DataAccess; +using Xunit; + +namespace Bootstrap.Admin.Api +{ + public class ProfilesTest : ControllerTest + { public ProfilesTest(BAWebHost factory) : base(factory, "api/Profiles") { } - - [Fact] - public async void Put_Ok() - { - var usr = new User { UserName = "UnitTest_Change", Password = "1", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "default.jpg", Css = "blue.css" }; - usr.Delete(usr.Retrieves().Where(u => u.UserName == usr.UserName).Select(u => u.Id)); - Assert.True(usr.Save(usr)); - - // change theme - usr.UserStatus = UserStates.ChangeTheme; - var resp = await Client.PutAsJsonAsync(usr); - Assert.True(resp); - - // Login as new user - var client = Host.CreateClient(); - await client.LoginAsync("UnitTest_Change", "1"); - - // change password - usr.UserStatus = UserStates.ChangePassword; - usr.NewPassword = "1"; - usr.Password = "1"; - resp = await client.PutAsJsonAsync("/api/Profiles", usr); - Assert.True(resp); - - // change displayname - usr.UserStatus = UserStates.ChangeDisplayName; - resp = await client.PutAsJsonAsync("/api/Profiles", usr); - Assert.True(resp); - - // change app - usr.App = "UnitTest"; - usr.UserStatus = UserStates.SaveApp; - resp = await client.PutAsJsonAsync("/api/Profiles", usr); - Assert.True(resp); - - // delete - usr.Delete(usr.Retrieves().Where(u => u.UserName == usr.UserName).Select(u => u.Id)); - } - } -} + + [Fact] + public async void Put_SaveTheme() + { + var usr = new User { UserName = "Admin" }; + // change theme + usr.Css = "blue.css"; + usr.UserStatus = UserStates.ChangeTheme; + var resp = await Client.PutAsJsonAsync(usr); + Assert.True(resp); + } + + [Fact] + public async void Put_ChangePassword() + { + var usr = new User() { UserName = "Admin" }; + // change password + usr.UserStatus = UserStates.ChangePassword; + usr.NewPassword = "123789"; + usr.Password = "123789"; + var resp = await Client.PutAsJsonAsync(usr); + Assert.True(resp); + } + + [Fact] + public async void Put_ChangeDisplayName() + { + var usr = new User() { UserName = "Admin" }; + // change displayname + usr.UserStatus = UserStates.ChangeDisplayName; + usr.DisplayName = "Administrator"; + var resp = await Client.PutAsJsonAsync(usr); + Assert.True(resp); + } + + [Fact] + public async void Put_SaveApp() + { + var usr = new User() { UserName = "Admin" }; + // change app + usr.App = "UnitTest"; + usr.UserStatus = UserStates.SaveApp; + var resp = await Client.PutAsJsonAsync(usr); + Assert.True(resp); + } + } +}