From 53900a563ad868e7552c198f2178116122e31c06 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Mon, 8 Apr 2019 16:01:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=BB=84=E4=BB=B6=EF=BC=9ALo?= =?UTF-8?q?ngbow.Web=E5=8D=87=E7=BA=A7=E5=88=B02.2.9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Comment OnlineUser功能整合到Longbow.Web组件中 --- Bootstrap.Admin/Bootstrap.Admin.csproj | 2 +- .../Controllers/AccountController.cs | 10 +- .../Controllers/Api/LoginController.cs | 6 +- .../Controllers/Api/LogsController.cs | 5 +- .../Controllers/Api/OnlineUsersController.cs | 1 + .../OnlineUsers/DefaultOnlineUsers.cs | 187 ------------------ Bootstrap.Admin/OnlineUsers/IOnlineUsers.cs | 41 ---- Bootstrap.Admin/OnlineUsers/OnlineUser.cs | 94 --------- .../OnlineUsersMiddlewareExtensions.cs | 66 ------- ...OnlineUsersServicesCollectionExtensions.cs | 31 --- Bootstrap.Admin/Startup.cs | 5 +- .../Bootstrap.Client.DataAccess.csproj | 2 +- .../Bootstrap.DataAccess.csproj | 4 +- Bootstrap.DataAccess/Helper/DictHelper.cs | 17 ++ Bootstrap.DataAccess/Helper/TraceHelper.cs | 25 ++- UnitTest/Bootstrap.Admin/Api/OnlineTest.cs | 59 +++--- UnitTest/Bootstrap.Admin/Api/UsersTest.cs | 2 - 17 files changed, 91 insertions(+), 466 deletions(-) delete mode 100644 Bootstrap.Admin/OnlineUsers/DefaultOnlineUsers.cs delete mode 100644 Bootstrap.Admin/OnlineUsers/IOnlineUsers.cs delete mode 100644 Bootstrap.Admin/OnlineUsers/OnlineUser.cs delete mode 100644 Bootstrap.Admin/OnlineUsers/OnlineUsersMiddlewareExtensions.cs delete mode 100644 Bootstrap.Admin/OnlineUsers/OnlineUsersServicesCollectionExtensions.cs diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 4e5ecfc7..a1b55f84 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -1,4 +1,4 @@ - + netcoreapp2.2 diff --git a/Bootstrap.Admin/Controllers/AccountController.cs b/Bootstrap.Admin/Controllers/AccountController.cs index d55d294d..58053a60 100644 --- a/Bootstrap.Admin/Controllers/AccountController.cs +++ b/Bootstrap.Admin/Controllers/AccountController.cs @@ -41,13 +41,14 @@ namespace Bootstrap.Admin.Controllers /// /// The login. /// + /// /// User name. /// Password. /// Remember. [HttpPost] - public async Task Login([FromServices]IOnlineUsers onlineUserSvr, string userName, string password, string remember) + public async Task Login([FromServices]IOnlineUsers onlineUserSvr, [FromServices]IIPLocatorProvider ipLocator, string userName, string password, string remember) { - if (UserHelper.Authenticate(userName, password, loginUser => CreateLoginUser(onlineUserSvr, HttpContext, loginUser))) + if (UserHelper.Authenticate(userName, password, loginUser => CreateLoginUser(onlineUserSvr, ipLocator, HttpContext, loginUser))) { var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme); identity.AddClaim(new Claim(ClaimTypes.Name, userName)); @@ -63,13 +64,14 @@ namespace Bootstrap.Admin.Controllers /// /// /// + /// /// /// - internal static void CreateLoginUser(IOnlineUsers onlineUserSvr, HttpContext context, LoginUser loginUser) + internal static void CreateLoginUser(IOnlineUsers onlineUserSvr, IIPLocatorProvider ipLocator, HttpContext context, LoginUser loginUser) { var agent = new UserAgent(context.Request.Headers["User-Agent"]); loginUser.Ip = (context.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString(); - loginUser.City = onlineUserSvr.RetrieveLocaleByIp(loginUser.Ip); + loginUser.City = ipLocator.Locate(loginUser.Ip); loginUser.Browser = $"{agent.Browser.Name} {agent.Browser.Version}"; loginUser.OS = $"{agent.OS.Name} {agent.OS.Version}"; } diff --git a/Bootstrap.Admin/Controllers/Api/LoginController.cs b/Bootstrap.Admin/Controllers/Api/LoginController.cs index 2b5596f9..373e10d1 100644 --- a/Bootstrap.Admin/Controllers/Api/LoginController.cs +++ b/Bootstrap.Admin/Controllers/Api/LoginController.cs @@ -1,5 +1,6 @@ using Bootstrap.DataAccess; using Bootstrap.Security; +using Longbow.Web; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; @@ -28,17 +29,18 @@ namespace Bootstrap.Admin.Controllers.Api /// /// /// + /// /// /// [AllowAnonymous] [HttpPost] - public string Post([FromServices]IOnlineUsers onlineUserSvr, [FromBody]JObject value) + public string Post([FromServices]IOnlineUsers onlineUserSvr, [FromServices]IIPLocatorProvider ipLocator, [FromBody]JObject value) { string token = null; dynamic user = value; string userName = user.userName; string password = user.password; - if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password, loginUser => AccountController.CreateLoginUser(onlineUserSvr, HttpContext, loginUser))) + if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password, loginUser => AccountController.CreateLoginUser(onlineUserSvr, ipLocator, HttpContext, loginUser))) { token = BootstrapAdminJwtTokenHandler.CreateToken(userName); } diff --git a/Bootstrap.Admin/Controllers/Api/LogsController.cs b/Bootstrap.Admin/Controllers/Api/LogsController.cs index 60c74cb3..d96b8ab2 100644 --- a/Bootstrap.Admin/Controllers/Api/LogsController.cs +++ b/Bootstrap.Admin/Controllers/Api/LogsController.cs @@ -29,16 +29,17 @@ namespace Bootstrap.Admin.Controllers.Api /// /// /// + /// /// /// [HttpPost] - public bool Post([FromServices]IOnlineUsers onlineUserSvr, [FromBody]Log value) + public bool Post([FromServices]IOnlineUsers onlineUserSvr, [FromServices]IIPLocatorProvider ipLocator, [FromBody]Log value) { var agent = new UserAgent(Request.Headers["User-Agent"]); value.Ip = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString(); value.Browser = $"{agent.Browser.Name} {agent.Browser.Version}"; value.OS = $"{agent.OS.Name} {agent.OS.Version}"; - value.City = onlineUserSvr.RetrieveLocaleByIp(value.Ip); + value.City = ipLocator.Locate(value.Ip); value.UserName = User.Identity.Name; return LogHelper.Save(value); } diff --git a/Bootstrap.Admin/Controllers/Api/OnlineUsersController.cs b/Bootstrap.Admin/Controllers/Api/OnlineUsersController.cs index 2d9c7665..3fa52cc7 100644 --- a/Bootstrap.Admin/Controllers/Api/OnlineUsersController.cs +++ b/Bootstrap.Admin/Controllers/Api/OnlineUsersController.cs @@ -1,3 +1,4 @@ +using Longbow.Web; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; diff --git a/Bootstrap.Admin/OnlineUsers/DefaultOnlineUsers.cs b/Bootstrap.Admin/OnlineUsers/DefaultOnlineUsers.cs deleted file mode 100644 index 6f92fc7b..00000000 --- a/Bootstrap.Admin/OnlineUsers/DefaultOnlineUsers.cs +++ /dev/null @@ -1,187 +0,0 @@ -using Bootstrap.DataAccess; -using Longbow.Cache; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Linq; -using System.Net.Http; -using System.Threading.Tasks; - -namespace Bootstrap.Admin -{ - /// - /// - /// - internal class DefaultOnlineUsers : IOnlineUsers - { - private readonly ConcurrentDictionary> _onlineUsers = new ConcurrentDictionary>(); - private readonly ConcurrentDictionary> _ipLocator = new ConcurrentDictionary>(); - private readonly HttpClient _client; - private readonly IEnumerable _local = new string[] { "::1", "127.0.0.1" }; - /// - /// - /// - /// - public DefaultOnlineUsers(IHttpClientFactory factory) - { - _client = factory.CreateClient(OnlineUsersServicesCollectionExtensions.IPSvrHttpClientName); - } - - /// - /// - /// - /// - public IEnumerable OnlineUsers - { - get { return _onlineUsers.Values.Select(v => v.Value); } - } - - /// - /// - /// - /// - /// - /// - /// - public AutoExpireCacheEntry AddOrUpdate(string key, Func> addValueFactory, Func, AutoExpireCacheEntry> updateValueFactory) => _onlineUsers.AddOrUpdate(key, addValueFactory, updateValueFactory); - - /// - /// - /// - /// - /// - /// - public bool TryRemove(string key, out AutoExpireCacheEntry onlineUserCache) => _onlineUsers.TryRemove(key, out onlineUserCache); - - /// - /// - /// - /// - /// - public string RetrieveLocaleByIp(string ip = null) => _ipLocator.GetOrAdd(ip, key => new AutoExpireCacheEntry(IPProxy(key), 1000 * 60, __ => _ipLocator.TryRemove(key, out _))).Value; - - private string IPProxy(string ip) - { - var ipSvr = DictHelper.RetrieveLocaleIPSvr(); - if (ipSvr.IsNullOrEmpty() || ipSvr.Equals("None", StringComparison.OrdinalIgnoreCase) || ip.IsNullOrEmpty() || _local.Any(p => p == ip)) return "本地连接"; - - var ipSvrUrl = DictHelper.RetrieveLocaleIPSvrUrl(ipSvr); - if (ipSvrUrl.IsNullOrEmpty()) return "本地连接"; - - var url = $"{ipSvrUrl}{ip}"; - var task = ipSvr == "BaiDuIPSvr" ? RetrieveLocator(url) : RetrieveLocator(url); - task.Wait(); - return task.Result; - } - - private async Task RetrieveLocator(string url) - { - var ret = default(T); - try - { - ret = await _client.GetAsJsonAsync(url); - } - catch (Exception ex) - { - ex.Log(new NameValueCollection() - { - ["Url"] = url - }); - } - return ret?.ToString(); - } - - /// - /// - /// - private class BaiDuIPLocator - { - /// - /// 详细地址信息 - /// - public string Address { get; set; } - - /// - /// 结果状态返回码 - /// - public string Status { get; set; } - - /// - /// - /// - /// - public override string ToString() - { - return Status == "0" ? string.Join(" ", Address.SpanSplit("|").Skip(1).Take(2)) : "XX XX"; - } - } - - private class JuheIPLocator - { - /// - /// - /// - public string ResultCode { get; set; } - - /// - /// - /// - public string Reason { get; set; } - - /// - /// - /// - public JuheIPLocatorResult Result { get; set; } - - /// - /// - /// - /// - public int Error_Code { get; set; } - - /// - /// - /// - /// - public override string ToString() - { - return Error_Code != 0 ? "XX XX" : Result.ToString(); - } - } - - private class JuheIPLocatorResult - { - /// - /// - /// - public string Country { get; set; } - - /// - /// - /// - public string Province { get; set; } - - /// - /// - /// - public string City { get; set; } - - /// - /// - /// - public string Isp { get; set; } - - /// - /// - /// - /// - public override string ToString() - { - return Country != "中国" ? $"{Country} {Province} {Isp}" : $"{Province} {City} {Isp}"; - } - } - } -} diff --git a/Bootstrap.Admin/OnlineUsers/IOnlineUsers.cs b/Bootstrap.Admin/OnlineUsers/IOnlineUsers.cs deleted file mode 100644 index 08d134f2..00000000 --- a/Bootstrap.Admin/OnlineUsers/IOnlineUsers.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Longbow.Cache; -using System; -using System.Collections.Generic; - -namespace Bootstrap.Admin -{ - /// - /// - /// - public interface IOnlineUsers - { - /// - /// - /// - IEnumerable OnlineUsers { get; } - - /// - /// - /// - /// - /// - /// - /// - AutoExpireCacheEntry AddOrUpdate(string key, Func> addValueFactory, Func, AutoExpireCacheEntry> updateValueFactory); - - /// - /// - /// - /// - /// - /// - bool TryRemove(string key, out AutoExpireCacheEntry onlineUserCache); - - /// - /// - /// - /// - /// - string RetrieveLocaleByIp(string ip = null); - } -} diff --git a/Bootstrap.Admin/OnlineUsers/OnlineUser.cs b/Bootstrap.Admin/OnlineUsers/OnlineUser.cs deleted file mode 100644 index 35d3f8f4..00000000 --- a/Bootstrap.Admin/OnlineUsers/OnlineUser.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; - -namespace Bootstrap.Admin -{ - - /// - /// - /// - public class OnlineUser - { - private ConcurrentQueue> _requestUrls = new ConcurrentQueue>(); - - /// - /// - /// - public string ConnectionId { get; set; } - - /// - /// - /// - public string UserName { get; set; } - - /// - /// - /// - public string DisplayName { get; set; } - - /// - /// - /// - public DateTime FirstAccessTime { get; set; } - - /// - /// - /// - public DateTime LastAccessTime { get; set; } - - /// - /// - /// - public string Location { get; set; } - - /// - /// - /// - public string Method { get; set; } - - /// - /// - /// - public string Ip { get; set; } - - /// - /// - /// - public string Browser { get; set; } - - /// - /// - /// - public string OS { get; set; } - - /// - /// - /// - public string RequestUrl { get; set; } - - /// - /// - /// - public IEnumerable> RequestUrls - { - get - { - return _requestUrls.ToArray(); - } - } - - /// - /// - /// - /// - public void AddRequestUrl(string url) - { - _requestUrls.Enqueue(new KeyValuePair(DateTime.Now, url)); - if (_requestUrls.Count > 5) - { - _requestUrls.TryDequeue(out _); - } - } - } -} diff --git a/Bootstrap.Admin/OnlineUsers/OnlineUsersMiddlewareExtensions.cs b/Bootstrap.Admin/OnlineUsers/OnlineUsersMiddlewareExtensions.cs deleted file mode 100644 index d4792ba8..00000000 --- a/Bootstrap.Admin/OnlineUsers/OnlineUsersMiddlewareExtensions.cs +++ /dev/null @@ -1,66 +0,0 @@ -using Bootstrap.Admin; -using Bootstrap.DataAccess; -using Longbow.Cache; -using Longbow.Web; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Linq; -using System.Net; - -namespace Microsoft.AspNetCore.Builder -{ - /// - /// - /// - public static class OnlineUsersMiddlewareExtensions - { - /// - /// - /// - /// - /// - public static IApplicationBuilder UseOnlineUsers(this IApplicationBuilder builder) => builder.UseWhen(context => context.Filter(), app => app.Use(async (context, next) => - { - await System.Threading.Tasks.Task.Run(() => - { - var user = UserHelper.RetrieveUserByUserName(context.User.Identity.Name); - if (user == null) return; - - var onlineUserSvr = context.RequestServices.GetRequiredService(); - var proxy = new Func, Action, AutoExpireCacheEntry>((c, action) => - { - var v = c.Value; - v.UserName = user.UserName; - v.DisplayName = user.DisplayName; - v.LastAccessTime = DateTime.Now; - v.Method = context.Request.Method; - v.RequestUrl = context.Request.Path; - v.AddRequestUrl(context.Request.Path); - action?.Invoke(); - TraceHelper.Save(new Trace { Ip = v.Ip, RequestUrl = v.RequestUrl, LogTime = v.LastAccessTime, City = v.Location, Browser = v.Browser, OS = v.OS, UserName = v.UserName }); - return c; - }); - onlineUserSvr.AddOrUpdate(context.Connection.Id ?? "", key => - { - var agent = new UserAgent(context.Request.Headers["User-Agent"]); - var v = new OnlineUser(); - v.ConnectionId = key; - v.Ip = (context.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString(); - v.Location = onlineUserSvr.RetrieveLocaleByIp(v.Ip); - v.Browser = $"{agent.Browser.Name} {agent.Browser.Version}"; - v.OS = $"{agent.OS.Name} {agent.OS.Version}"; - v.FirstAccessTime = DateTime.Now; - return proxy(new AutoExpireCacheEntry(v, 1000 * 60, __ => onlineUserSvr.TryRemove(key, out _)), null); - }, (key, v) => proxy(v, () => v.Reset())); - }); - await next(); - })); - - private static bool Filter(this HttpContext context) - { - var url = context.Request.Path; - return !new string[] { "/api", "/NotiHub", "/swagger" }.Any(r => url.StartsWithSegments(r, StringComparison.OrdinalIgnoreCase)); - } - } -} diff --git a/Bootstrap.Admin/OnlineUsers/OnlineUsersServicesCollectionExtensions.cs b/Bootstrap.Admin/OnlineUsers/OnlineUsersServicesCollectionExtensions.cs deleted file mode 100644 index 6bbfa3f5..00000000 --- a/Bootstrap.Admin/OnlineUsers/OnlineUsersServicesCollectionExtensions.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Bootstrap.Admin; -using Microsoft.Extensions.DependencyInjection.Extensions; - -namespace Microsoft.Extensions.DependencyInjection -{ - /// - /// - /// - public static class OnlineUsersServicesCollectionExtensions - { - /// - /// - /// - internal const string IPSvrHttpClientName = "IPSvr"; - - /// - /// - /// - /// - /// - public static IServiceCollection AddOnlineUsers(this IServiceCollection services) - { - services.TryAddSingleton(); - services.AddHttpClient(IPSvrHttpClientName, client => - { - client.DefaultRequestHeaders.Connection.Add("keep-alive"); - }); - return services; - } - } -} diff --git a/Bootstrap.Admin/Startup.cs b/Bootstrap.Admin/Startup.cs index 7bf5ee87..c95dd5ba 100644 --- a/Bootstrap.Admin/Startup.cs +++ b/Bootstrap.Admin/Startup.cs @@ -1,4 +1,4 @@ -using Bootstrap.DataAccess; +using Bootstrap.DataAccess; using Bootstrap.Security.Filter; using Longbow.Web; using Longbow.Web.SignalR; @@ -60,6 +60,7 @@ namespace Bootstrap.Admin services.AddConfigurationManager(Configuration); services.AddCacheManager(Configuration); services.AddDbAdapter(); + services.AddIPLocator(DictHelper.ConfigIPLocator); services.AddOnlineUsers(); var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"]) .SetApplicationName(Configuration["ApplicationName"]) @@ -127,7 +128,7 @@ namespace Bootstrap.Admin app.UseStaticFiles(); app.UseAuthentication(); app.UseBootstrapAdminAuthorization(RoleHelper.RetrieveRolesByUserName, RoleHelper.RetrieveRolesByUrl, AppHelper.RetrievesByUserName); - app.UseOnlineUsers(); + app.UseOnlineUsers(callback: TraceHelper.Save); app.UseCacheManagerCorsHandler(); app.UseSignalR(routes => { routes.MapHub("/NotiHub"); }); app.UseMvc(routes => diff --git a/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj b/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj index 466392b1..a998f045 100644 --- a/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj +++ b/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj @@ -14,7 +14,7 @@ - + diff --git a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 7a9fb04e..64d237cc 100644 --- a/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -14,7 +14,7 @@ - + diff --git a/Bootstrap.DataAccess/Helper/DictHelper.cs b/Bootstrap.DataAccess/Helper/DictHelper.cs index d68fabaa..93ae369f 100644 --- a/Bootstrap.DataAccess/Helper/DictHelper.cs +++ b/Bootstrap.DataAccess/Helper/DictHelper.cs @@ -1,6 +1,8 @@ using Bootstrap.Security; using Longbow.Cache; using Longbow.Data; +using Longbow.Web; +using System; using System.Collections.Generic; using System.Linq; @@ -75,6 +77,21 @@ namespace Bootstrap.DataAccess return ret; } + /// + /// + /// + /// + public static void ConfigIPLocator(IPLocatorOption op) + { + var name = RetrieveLocaleIPSvr(); + if (!string.IsNullOrEmpty(name) && !name.Equals("None", StringComparison.OrdinalIgnoreCase)) + { + var url = RetrieveLocaleIPSvrUrl(name); + op.Locator = string.IsNullOrEmpty(url) ? null : DefaultIPLocatorProvider.CreateLocator(name); + op.Url = string.IsNullOrEmpty(url) ? string.Empty : $"{url}{op.IP}"; + } + } + /// /// 保存网站个性化设置 /// diff --git a/Bootstrap.DataAccess/Helper/TraceHelper.cs b/Bootstrap.DataAccess/Helper/TraceHelper.cs index d4c31808..d85bec1c 100644 --- a/Bootstrap.DataAccess/Helper/TraceHelper.cs +++ b/Bootstrap.DataAccess/Helper/TraceHelper.cs @@ -1,5 +1,7 @@ using Longbow.Data; +using Longbow.Web; using Longbow.Web.Mvc; +using Microsoft.AspNetCore.Http; using PetaPoco; using System; @@ -11,8 +13,27 @@ namespace Bootstrap.DataAccess /// /// 保存访问历史记录 /// - /// - public static void Save(Trace p) => DbContextManager.Create().Save(p); + /// + /// + public static void Save(HttpContext context, OnlineUser v) + { + if (context.User.Identity.IsAuthenticated) + { + var user = UserHelper.RetrieveUserByUserName(context.User.Identity.Name); + v.UserName = user.UserName; + v.DisplayName = user.DisplayName; + DbContextManager.Create().Save(new Trace + { + Ip = v.Ip, + RequestUrl = v.RequestUrl, + LogTime = v.LastAccessTime, + City = v.Location, + Browser = v.Browser, + OS = v.OS, + UserName = v.UserName + }); + } + } /// /// 获得指定IP历史访问记录 diff --git a/UnitTest/Bootstrap.Admin/Api/OnlineTest.cs b/UnitTest/Bootstrap.Admin/Api/OnlineTest.cs index 7398c049..72982baf 100644 --- a/UnitTest/Bootstrap.Admin/Api/OnlineTest.cs +++ b/UnitTest/Bootstrap.Admin/Api/OnlineTest.cs @@ -1,32 +1,33 @@ -using System; -using System.Collections.Generic; -using Xunit; - -namespace Bootstrap.Admin.Api -{ - public class OnlineTest : ControllerTest - { - public OnlineTest(BAWebHost factory) : base(factory, "api/OnlineUsers") { } - - [Fact] - public async void Get_Ok() - { - var users = await Client.GetAsJsonAsync>(); - Assert.Single(users); - } - - [Fact] - public async void GetById_Ok() - { - var urls = await Client.GetAsJsonAsync>>("UnitTest"); - Assert.Empty(urls); +using Longbow.Web; +using System; +using System.Collections.Generic; +using Xunit; + +namespace Bootstrap.Admin.Api +{ + public class OnlineTest : ControllerTest + { + public OnlineTest(BAWebHost factory) : base(factory, "api/OnlineUsers") { } + + [Fact] + public async void Get_Ok() + { + var users = await Client.GetAsJsonAsync>(); + Assert.Single(users); } - [Fact] - public async void Put_Ok() - { - var ret = await Client.PutAsJsonAsync(""); - Assert.False(ret); + [Fact] + public async void GetById_Ok() + { + var urls = await Client.GetAsJsonAsync>>("UnitTest"); + Assert.Empty(urls); } - } -} + + [Fact] + public async void Put_Ok() + { + var ret = await Client.PutAsJsonAsync(""); + Assert.False(ret); + } + } +} diff --git a/UnitTest/Bootstrap.Admin/Api/UsersTest.cs b/UnitTest/Bootstrap.Admin/Api/UsersTest.cs index 57606f61..da8b9dc0 100644 --- a/UnitTest/Bootstrap.Admin/Api/UsersTest.cs +++ b/UnitTest/Bootstrap.Admin/Api/UsersTest.cs @@ -1,12 +1,10 @@ using Bootstrap.DataAccess; -using Longbow.Data; using Longbow.Web.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Xunit; -using DbManager = Longbow.Data.DbManager; namespace Bootstrap.Admin.Api {