public async Task Fetch_Players_Test() { // Arrange var expected = typeof(OkObjectResult); var expectedFriends = 2; _friendsHandlerStub.Friends.Add(new User()); _friendsHandlerStub.Friends.Add(new User()); var identity = new ClaimsIdentity(); identity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/scope", "User.ReadWrite")); _securityValidatorStub.ClaimsPrincipal = new ClaimsPrincipal(identity); var req = HttpRequestHelper.Create("GET"); // Act var actual = await _friendsFunction.Run(req, null); // Assert Assert.IsType(expected, actual); var body = actual as OkObjectResult; var list = body?.Value as List <User>; Assert.Equal(expectedFriends, list?.Count); }
public void TestMethod5() { //string query = @"{""VenueID"":""1"",""WorkDate"":""2017-08"",""CoachID"":""-1"",""CurriculumBeginTime"":""2017-08"",""CurriculumId"":[""2"",""1""]}"; //CreateCoachWageRequest oData = Newtonsoft.Json.JsonConvert.DeserializeObject<CreateCoachWageRequest>(query); HttpRequestHelper RequestHelper = new HttpRequestHelper(); //检查输入项 string apiUrl = "http://localhost:53262/api"; string url = string.Format("{0}/WxUserInfo/SetPosition", apiUrl); RequestHelper.Create(url); RequestHelper.WebRequest.ContentType = "application/json;charset=UTF-8"; RequestHelper.WebRequest.Headers.Add("Accept-Encoding: gzip, deflate"); RequestHelper.WebRequest.AutomaticDecompression = System.Net.DecompressionMethods.Deflate; Sys.Models.WxUserInfo userInfo = new Models.WxUserInfo() { OpenId = "ozLW4wHYTcApj55HIUT0o8Qdet6U", Latitude = 2222, Longitude = 333, }; string jsonStr = JsonHelper.ToJsonStringByNewtonsoft(userInfo); string result = RequestHelper.PostString(jsonStr); JObject jo = JObject.Parse(result); if (Convert.ToBoolean(jo["Error"].ToString())) { throw new Comm.YYException.YYException(jo["Msg"].ToString()); } }
public async Task Fetch_Single_Game_Test() { // Arrange var expected = typeof(OkObjectResult); var expectedGameID = "abc"; _gamesHandlerStub.SingleGame = new MyChessGame() { ID = "abc" }; var identity = new ClaimsIdentity(); identity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/scope", "Games.ReadWrite")); _securityValidatorStub.ClaimsPrincipal = new ClaimsPrincipal(identity); var req = HttpRequestHelper.Create("GET", query: new Dictionary <string, Microsoft.Extensions.Primitives.StringValues>() { { "state", "Archive" } }); // Act var actual = await _gamesFunction.Run(req, SignalRHelper.Create(), "abc"); // Assert Assert.IsType(expected, actual); var body = actual as OkObjectResult; var actualGame = body?.Value as MyChessGame; Assert.Equal(expectedGameID, actualGame?.ID); }
public async Task Fetch_Games_Test() { // Arrange var expected = typeof(OkObjectResult); var expectedGames = 2; _gamesHandlerStub.Games.Add(new MyChessGame()); _gamesHandlerStub.Games.Add(new MyChessGame()); var identity = new ClaimsIdentity(); identity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/scope", "Games.ReadWrite")); _securityValidatorStub.ClaimsPrincipal = new ClaimsPrincipal(identity); var req = HttpRequestHelper.Create("GET", query: new Dictionary <string, Microsoft.Extensions.Primitives.StringValues>() { { "state", "WaitingForYou" } }); // Act var actual = await _gamesFunction.Run(req, SignalRHelper.Create(), null); // Assert Assert.IsType(expected, actual); var body = actual as OkObjectResult; var list = body?.Value as List <MyChessGame>; Assert.Equal(expectedGames, list?.Count); }
public async Task Add_Friend_Test() { // Arrange var expected = typeof(CreatedResult); var expectedPlayerID = "abc"; var friend = new User() { ID = "abc", Name = "John Doe" }; _friendsHandlerStub.SingleFriend = new User() { ID = "abc" }; var identity = new ClaimsIdentity(); identity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/scope", "User.ReadWrite")); _securityValidatorStub.ClaimsPrincipal = new ClaimsPrincipal(identity); var req = HttpRequestHelper.Create("POST", body: friend); // Act var actual = await _friendsFunction.Run(req, "abc"); // Assert Assert.IsType(expected, actual); var body = actual as CreatedResult; var actualPlayer = body?.Value as User; Assert.Equal(expectedPlayerID, actualPlayer?.ID); }
public async Task Fetch_Me_Test() { // Arrange var expected = typeof(OkObjectResult); var expectedUserID = "abc"; _meHandlerStub.User.ID = "abc"; var identity = new ClaimsIdentity(); identity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/scope", "User.ReadWrite")); _securityValidatorStub.ClaimsPrincipal = new ClaimsPrincipal(identity); var req = HttpRequestHelper.Create("GET"); // Act var actual = await _meFunction.Run(req); // Assert Assert.IsType(expected, actual); var body = actual as OkObjectResult; var actualUser = body?.Value as User; Assert.Equal(expectedUserID, actualUser?.ID); }
public async Task Add_Friend_Fails_Due_Invalid_Player_Test() { // Arrange var expected = typeof(ObjectResult); var expectedError = "1234"; var friend = new User() { ID = "abc", Name = "John Doe" }; _friendsHandlerStub.Error = new Models.HandlerError() { Instance = "some text/1234" }; var identity = new ClaimsIdentity(); identity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/scope", "User.ReadWrite")); _securityValidatorStub.ClaimsPrincipal = new ClaimsPrincipal(identity); var req = HttpRequestHelper.Create("POST", body: friend); // Act var actual = await _friendsFunction.Run(req, "abc"); // Assert Assert.IsType(expected, actual); var body = actual as ObjectResult; var actualError = body?.Value as ProblemDetails; Assert.EndsWith(expectedError, actualError?.Instance); }
public async Task Fetch_Settings_Test() { // Arrange var expected = typeof(OkObjectResult); var expectedPlayAlwaysUp = true; _settingsHandlerStub.UserSettings.PlayAlwaysUp = true; var identity = new ClaimsIdentity(); identity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/scope", "User.ReadWrite")); _securityValidatorStub.ClaimsPrincipal = new ClaimsPrincipal(identity); var req = HttpRequestHelper.Create("GET"); // Act var actual = await _settingsFunction.Run(req); // Assert Assert.IsType(expected, actual); var body = actual as OkObjectResult; var actualUserSettings = body?.Value as UserSettings; Assert.Equal(expectedPlayAlwaysUp, actualUserSettings?.PlayAlwaysUp); }
public async Task Update_Settings_With_Failure_Test() { // Arrange var expected = typeof(ObjectResult); var userSettings = new UserSettings(); _settingsHandlerStub.Error = new HandlerError() { Status = 501 }; var identity = new ClaimsIdentity(); identity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/scope", "User.ReadWrite")); _securityValidatorStub.ClaimsPrincipal = new ClaimsPrincipal(identity); var req = HttpRequestHelper.Create("POST", body: userSettings); // Act var actual = await _settingsFunction.Run(req); // Assert Assert.IsType(expected, actual); }
public void Create_WithHttpRequest_ReturnsHttpWebRequestAdapter() { const int major = 1; const int minor = 0; const int build = 4; const int revision = 3; // Arrange var request = new HttpRequest { ResourcePath = "resource", HttpMethod = HttpMethod.POST }; var expectedUri = string.Format("{0}v1.1/{1}", _uri, request.ResourcePath); var expectedVersion = new Version(major, minor, build, revision); // Act var actualHttpRequest = _helper.Create(request, _uri, expectedVersion); // Assert Assert.That(actualHttpRequest, Is.InstanceOf <HttpWebRequestAdapter>()); Assert.AreEqual(expectedUri, actualHttpRequest.RequestUri.ToString()); Assert.AreEqual(request.HttpMethod.ToString(), actualHttpRequest.Method); Assert.IsFalse(string.IsNullOrEmpty(actualHttpRequest.UserAgent)); Assert.That(actualHttpRequest.UserAgent, Is.EqualTo(string.Format("Esendex .NET SDK v{0}.{1}.{2}", major, minor, build))); }
/// <summary> /// 通过订单号取的详细 /// </summary> /// <param name="OrderID"></param> /// <returns></returns> public dynamic GetOrderByOrderID(int OrderID) { //todo 用户取关检测 //检查输入项 string apiUrl = System.Configuration.ConfigurationManager.AppSettings["ApiUrl"]; string url = string.Format("{0}/Student/GetOrderByOrderID/?OrderID=" + OrderID, apiUrl); RequestHelper.Create(url); RequestHelper.WebRequest.ContentType = "application/json;charset=UTF-8"; RequestHelper.WebRequest.Headers.Add("Accept-Encoding: gzip, deflate"); RequestHelper.WebRequest.AutomaticDecompression = System.Net.DecompressionMethods.Deflate; string result = RequestHelper.RunGetRequest(); dynamic DynamicObject = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(result); return(DynamicObject); }
public void Security_Validator_Header_Test(string name, string value, string?expected) { // Arrange var request = HttpRequestHelper.Create("GET", headers: new Dictionary <string, Microsoft.Extensions.Primitives.StringValues>() { { name, value } }); // Act var actual = _securityValidator.ParseAccessToken(request); // Assert Assert.Equal(expected, actual); }
/// <summary> /// 关注用户回写数据库 /// </summary> /// <param name="userInfo"></param> /// <returns></returns> public bool FollowMP(OAuthUserInfo userInfo) { //todo 用户取关检测 //检查输入项 string apiUrl = System.Configuration.ConfigurationManager.AppSettings["ApiUrl"]; string url = string.Format("{0}/WxUserInfo/Create", apiUrl); RequestHelper.Create(url); RequestHelper.WebRequest.ContentType = "application/json;charset=UTF-8"; RequestHelper.WebRequest.Headers.Add("Accept-Encoding: gzip, deflate"); RequestHelper.WebRequest.AutomaticDecompression = System.Net.DecompressionMethods.Deflate; var tmp = new Sys.Models.WxUserInfo() { City = userInfo.city, Country = userInfo.country, HeadImgUrl = userInfo.headimgurl, LastLoginTime = DateTime.Now, NickName = userInfo.nickname, OpenId = userInfo.openid, Province = userInfo.province, Sex = userInfo.sex == 1, State = 1, }; string jsonStr = JsonHelper.ToJsonStringByNewtonsoft(tmp); string result = RequestHelper.PostString(jsonStr); JObject jo = JObject.Parse(result); if (Convert.ToBoolean(jo["Error"].ToString())) { throw new Comm.YYException.YYException(jo["Msg"].ToString()); } return(true); }
public async Task Create_Game_Fails_Due_Invalid_Opponent_Test() { // Arrange var expected = typeof(ObjectResult); var expectedError = "1234"; var game = new MyChessGame() { Name = "great game", State = "Normal", Updated = DateTimeOffset.UtcNow }; game.Players.White.ID = "p1"; game.Players.Black.ID = "p3"; game.Moves.Add(new MyChessGameMove() { Move = "A2A3", Comment = "Cool move", Start = DateTimeOffset.UtcNow.AddMinutes(-1), End = DateTimeOffset.UtcNow }); _gamesHandlerStub.Error = new Models.HandlerError() { Instance = "some text/1234" }; var identity = new ClaimsIdentity(); identity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/scope", "Games.ReadWrite")); _securityValidatorStub.ClaimsPrincipal = new ClaimsPrincipal(identity); var req = HttpRequestHelper.Create("POST", body: game, query: new Dictionary <string, Microsoft.Extensions.Primitives.StringValues>()); // Act var actual = await _gamesFunction.Run(req, SignalRHelper.Create(), "abc"); // Assert Assert.IsType(expected, actual); var body = actual as ObjectResult; var actualError = body?.Value as ProblemDetails; Assert.EndsWith(expectedError, actualError?.Instance); }
public async Task Create_Game_Test() { // Arrange var expected = typeof(CreatedResult); var expectedGameID = "abc"; var game = new MyChessGame() { Name = "great game", State = "Normal", Updated = DateTimeOffset.UtcNow }; game.Players.White.ID = "p1"; game.Players.Black.ID = "p2"; game.Moves.Add(new MyChessGameMove() { Move = "A2A3", Comment = "Cool move", Start = DateTimeOffset.UtcNow.AddMinutes(-1), End = DateTimeOffset.UtcNow }); _gamesHandlerStub.SingleGame = new MyChessGame() { ID = "abc" }; var identity = new ClaimsIdentity(); identity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/scope", "Games.ReadWrite")); _securityValidatorStub.ClaimsPrincipal = new ClaimsPrincipal(identity); var req = HttpRequestHelper.Create("POST", body: game, query: new Dictionary <string, Microsoft.Extensions.Primitives.StringValues>()); // Act var actual = await _gamesFunction.Run(req, SignalRHelper.Create(), "abc"); // Assert Assert.IsType(expected, actual); var body = actual as CreatedResult; var actualGame = body?.Value as MyChessGame; Assert.Equal(expectedGameID, actualGame?.ID); }
public void Create_WithHttpRequest_ReturnsHttpWebRequestAdapter() { // Arrange HttpRequest request = new HttpRequest() { ResourcePath = "resource", HttpMethod = HttpMethod.POST }; string expectedUri = uri.ToString() + "v1.1/" + request.ResourcePath; // Act IHttpWebRequestAdapter actualHttpRequest = helper.Create(request, uri); // Assert Assert.That(actualHttpRequest, Is.InstanceOf <HttpWebRequestAdapter>()); Assert.AreEqual(expectedUri, actualHttpRequest.RequestUri.ToString()); Assert.AreEqual(request.HttpMethod.ToString(), actualHttpRequest.Method); Assert.IsFalse(string.IsNullOrEmpty(actualHttpRequest.UserAgent)); }
public static void Register(string token, Sys.Models.Venue model) { HttpRequestHelper RequestHelper = new HttpRequestHelper(); string apiUrl = System.Configuration.ConfigurationManager.AppSettings["ApiUrl"]; string url = string.Format("{0}/api/Venue/Create", apiUrl); RequestHelper.Create(url); RequestHelper.WebRequest.Headers.Add("Authorization", "Bearer " + token); RequestHelper.WebRequest.ContentType = "application/json;charset=UTF-8"; RequestHelper.WebRequest.Headers.Add("Accept-Encoding: gzip, deflate"); RequestHelper.WebRequest.AutomaticDecompression = System.Net.DecompressionMethods.Deflate; string jsonStr = JsonHelper.ToJsonStringByNewtonsoft(model); string result = RequestHelper.PostString(jsonStr); JObject jo = JObject.Parse(result); if (Convert.ToBoolean(jo["Error"].ToString())) { throw new Comm.YYException.YYException(jo["Msg"].ToString()); } }
public override void Execute(IJobExecutionContext context) { string apiUrl = System.Configuration.ConfigurationManager.AppSettings["ApiUrl"]; string url = string.Format("{0}/WxNotice/WaitClass4Coach", apiUrl); RequestHelper.Create(url); RequestHelper.WebRequest.ContentType = "application/json;charset=UTF-8"; RequestHelper.WebRequest.Headers.Add("Accept-Encoding: gzip, deflate"); RequestHelper.WebRequest.AutomaticDecompression = System.Net.DecompressionMethods.Deflate; string result = RequestHelper.RunGetRequest(); JObject jo = JObject.Parse(result); if (Convert.ToBoolean(jo["Error"].ToString())) { throw new Comm.YYException.YYException(jo["Msg"].ToString()); } else { var data = JToken.Parse(jo["data"].ToString()).ToList(); foreach (var item in data) { var templateId = Comm.WeiXin.NoticeTemplates.ClassBeginTemplate; var send_data = new { first = new TemplateDataItem("预约课程开始提醒"), keyword1 = new TemplateDataItem(item["Title"].ToString()), keyword2 = new TemplateDataItem(item["CurriculumDate"].ToString() + item["CurriculumBeginTime"].ToString()), remark = new TemplateDataItem("查看 http://m.yiyust.com/student/index") }; var send_result = TemplateApi.SendTemplateMessage(base.AppId, item["openid"].ToString(), templateId, "http://m.yiyust.com/student/index", send_data); //todo 记录日志 } } }