protected virtual IMegaApiClient CreateClient() { Options = new Options(applicationKey: "ewZQFBBC"); WebClient = new TestWebClient(new WebClient(WebTimeout, null), MaxRetry, _logMessageAction); return(new MegaApiClient(Options, WebClient)); }
public async Task WhenCryptocurrencyIsNotSupportedReturnsNotFound() { const string cryptocurrency = "unknownCryptocurrency"; var endpointUnderTest = $"/api/priceindex/{cryptocurrency}"; _mockProviderService .UponReceiving($"A GET request to get price indexes for '{cryptocurrency}' cryptocurrency") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = endpointUnderTest }) .WillRespondWith(new ProviderServiceResponse { Status = (int)HttpStatusCode.NotFound }); var consumer = new TestWebClient(_mockProviderServiceBaseUri); var(statusCode, coinDeskResponse) = await consumer.Get(endpointUnderTest); Assert.Equal(HttpStatusCode.NotFound, statusCode); Assert.Null(coinDeskResponse); _mockProviderService.VerifyInteractions(); }
public async Task WhenCryptocurrencyIsSupportedReturnsPriceIndexes() { const string cryptocurrency = "bitcoin"; var endpointUnderTest = $"/api/priceindex/{cryptocurrency}"; _mockProviderService .UponReceiving($"A GET request to get price indexes for '{cryptocurrency}' cryptocurrency") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = endpointUnderTest }) .WillRespondWith(new ProviderServiceResponse { Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Status = (int)HttpStatusCode.OK, Body = new { lastUpdatedIso = "Nov 11, 2019 at 22:12 GMT", priceIndexes = new [] { new { code = "EUR", symbol = "€", rate = 7920.6637, }, new { code = "GBP", symbol = "£", rate = 6799.1343, }, new { code = "USD", symbol = "$", rate = 8739.3483, } } } }); var consumer = new TestWebClient(_mockProviderServiceBaseUri); var(statusCode, coinDeskResponse) = await consumer.Get(endpointUnderTest); Assert.Equal(HttpStatusCode.OK, statusCode); Assert.NotNull(coinDeskResponse); _mockProviderService.VerifyInteractions(); }
public async Task Post_PlanningAppsInProgressTensApps(string url) { // Arrange var client = _factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { //Override IService called during POST to return specific test calendar services.AddScoped <IDateService, DateServiceTest>(); }); }) .CreateClient(); var testWebClient = new TestWebClient(client); testWebClient.Login(); Console.WriteLine($"Calling Api Endpoint {url} "); var projectGenerators = await testWebClient.GetProjectGenerator(); var pg = projectGenerators.Items.FirstOrDefault(); await testWebClient.CreatePlanningApp(pg.Id); await testWebClient.CreatePlanningApp(pg.Id); await testWebClient.CreatePlanningApp(pg.Id); await testWebClient.CreatePlanningApp(pg.Id); await testWebClient.CreatePlanningApp(pg.Id); await testWebClient.CreatePlanningApp(pg.Id); await testWebClient.CreatePlanningApp(pg.Id); await testWebClient.CreatePlanningApp(pg.Id); await testWebClient.CreatePlanningApp(pg.Id); await testWebClient.CreatePlanningApp(pg.Id); await testWebClient.CreatePlanningApp(pg.Id); var PAL = await testWebClient.GetPlanningApps(); Assert.True(PAL.Items.Count() == 10); Assert.True(PAL.TotalItems == 11); //Check Paging Is Working }
static void Main(string[] args) { TestWebRequest.TestGetData(@"http://m.weather.com.cn/data/101010100.html"); TestWebClient.TestGetData(@"http://m.weather.com.cn/data/101010100.html"); Console.WriteLine(); TestWebRequest.TestGetData(@"http://www.dianping.com/search/category/1/10/g101"); TestWebClient.TestGetData(@"http://www.dianping.com/search/category/1/10/g101"); Console.ReadLine(); }
public void FixtureSetup() { var baseDir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; var previousDir = new DirectoryInfo(baseDir + "/../../"); var fileName = new FileInfo(Path.Combine(previousDir.FullName, "testappname.application")); if (File.Exists(fileName.FullName)) { File.Delete(fileName.FullName); } File.WriteAllText(fileName.FullName, @"#jarvis-configuration application-name : MyAppParam base-server-address : http://localhost:53642/"); _app = WebApp.Start <ConfigurationServiceApplication>(baseUri); client = new TestWebClient(); }
public async Task Post_AddNewGeneratorEndOfStateList(string url) { // Arrange var client = _factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { //Override IService called during POST to return specific test calendar services.AddScoped <IDateService, DateServiceTest>(); }); }) .CreateClient(); var testWebClient = new TestWebClient(client); testWebClient.Login(); Console.WriteLine($"Calling Api Endpoint {url} "); var results = await testWebClient.GetPlanningApps(); Assert.True(results.Items.Count() == 0); var projectGenerators = await testWebClient.GetProjectGenerator(); var pg = projectGenerators.Items.FirstOrDefault(); var planningAppResource = await testWebClient.CreatePlanningApp(pg.Id); Assert.Equal(planningAppResource.ProjectGeneratorName, TestSettings.ProjectGeneratorName); Assert.True(planningAppResource.PlanningAppStates.Count() == TestSettings.OneState); //Check Ordering var stateList = planningAppResource.PlanningAppStates.ToList(); //Check Planning App Details Assert.Equal("03-01-2019", planningAppResource.CompletionDate); Assert.Equal("OnTime", planningAppResource.CurrentStateStatus); Assert.Equal("03-01-2019", stateList[0].DueByDate); //Loop states and check settings Assert.True(testWebClient.checkListOrdering(stateList)); //Check new generator start flag Assert.True(stateList[0].isLastGeneratorState); }
static void Main(string[] args) { Console.WriteLine("##### 测试 WebClient UploadFile 数据 #####"); // 图片地址. string uploadImgUrl = @"http://113.106.63.156:40081/demo/gold/fileUpload.do"; string uploadFile = "654325198311163726.jpg"; TestWebClient.TestUploadImage(uploadImgUrl, uploadFile); Console.WriteLine("##### 测试 WebClient DownloadFile 数据 #####"); // 图片地址. string imageUrl = @"https://www.baidu.com/img/bdlogo.png"; string localFile = "bdlogo.png"; if (File.Exists(localFile)) { File.Delete(localFile); } TestWebClient.TestDownloadImage(imageUrl, localFile); Console.WriteLine("##### 测试 HttpWebRequest 上传文件 #####"); string uploadUrl = @"http://*****:*****@"http://localhost:9900/Test/TestGet?code=123456&name=张三"; // 测试 Get 数据. TestWebRequest.TestGetData(httpGetUrl); TestHttpWebRequest.TestGetData(httpGetUrl); TestWebClient.TestGetData(httpGetUrl); Console.WriteLine(); Console.WriteLine("##### 测试 WebClient Post 数据 #####"); // Http Post 地址. string httpPostUrl = @"http://localhost:9900/Test/TestPost"; // Http Post 数据. string httpPostData = "code=654321&name=李四"; // 测试 Post 数据. TestWebRequest.TestPostData(httpPostUrl, httpPostData); TestHttpWebRequest.TestPostData(httpPostUrl, httpPostData); TestWebClient.TestPostData(httpPostUrl, httpPostData); Console.WriteLine(); Console.WriteLine("##### 测试 HttpsWebRequest Https + 证书 #####"); string httpsGetUrl = "https://localhost:9901/Test/TestGet?code=13579&name=王五"; TestHttpsWebRequest.TestGetData(httpsGetUrl); Console.WriteLine(); Console.WriteLine("##### 测试 Https (无证书)#####"); // ###### // ###### 调用 https 的时候, 如果服务器安全证书存在问题 的解决办法. // ###### string httpsGetUrl2 = "https://localhost:9901/Test/TestGet?code=24680&name=赵六"; // 简单调用没有 信任证书的 https ,将报错. // 基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。 // 测试 Get 数据. TestWebRequest.TestGetData(httpsGetUrl2); TestHttpWebRequest.TestGetData(httpsGetUrl2); TestWebClient.TestGetData(httpsGetUrl2); Console.WriteLine(); // 避免 “基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系” 错误! Util.SetCertificatePolicy(); TestWebRequest.TestGetData(httpsGetUrl2); TestHttpWebRequest.TestGetData(httpsGetUrl2); TestWebClient.TestGetData(httpsGetUrl2); Console.WriteLine(); Console.ReadLine(); }
public async Task Post_PlanningAppRollDateCheckStatus(string url) { var f = _factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { //Override IService called during POST to return specific test calendar //services.AddScoped<IDateService, DateServiceTest>(); }); }); // Arrange var client = _factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { //Override IService called during POST to return specific test calendar //services.AddScoped<IDateService, DateServiceTest>(); }); }) .CreateClient(); var testWebClient = new TestWebClient(client); testWebClient.Login(); Console.WriteLine($"Calling Api Endpoint {url} "); var BD = await testWebClient.SetBusinessDate("01-01-2019"); var projectGenerators = await testWebClient.GetProjectGenerator(); var pg = projectGenerators.Items.FirstOrDefault(); await testWebClient.CreatePlanningApp(pg.Id); var PAL = await testWebClient.GetPlanningApps(); Assert.True(PAL.Items.Count() == 1); Assert.True(PAL.TotalItems == 1); //Check Paging Is Working var PA = await testWebClient.GetPlanningApp(PAL.Items.SingleOrDefault().Id); Assert.Equal(StatusList.OnTime, PA.CurrentStateStatus); Assert.Equal("TestGen1:State1", PA.CurrentState); Assert.Equal("03-01-2019", PA.ExpectedStateCompletionDate); Assert.Equal("15-01-2019", PA.CompletionDate); //Roll The Business Date To Make current state 'Due; BD = await testWebClient.SetBusinessDate("02-01-2019"); var PA_ROLLED_DUE = await testWebClient.GetPlanningApp(PAL.Items.SingleOrDefault().Id); //Assert Application Status is 'Due' Assert.Equal(StatusList.Due, PA_ROLLED_DUE.CurrentStateStatus); Assert.Equal("TestGen1:State1", PA_ROLLED_DUE.CurrentState); //Assert First State is 'Due; var stateList = PA_ROLLED_DUE.PlanningAppStates.ToList(); Assert.Equal(StatusList.Due, stateList[0].StateStatus); Assert.Equal("TestGen1:State1", stateList[0].StateName); Assert.Equal(StatusList.OnTime, stateList[1].StateStatus); Assert.Equal("TestGen1:State2", stateList[1].StateName); //Assert Roll dates so first state 'Overdue' and second state 'Due' await testWebClient.SetBusinessDate("04-01-2019"); var PA_ROLLED_OVERDUE_DUE = await testWebClient.GetPlanningApp(PAL.Items.SingleOrDefault().Id); stateList = PA_ROLLED_OVERDUE_DUE.PlanningAppStates.ToList(); //Assert Application Status is 'Due' Assert.Equal(StatusList.Overdue, PA_ROLLED_OVERDUE_DUE.CurrentStateStatus); Assert.Equal("TestGen1:State1", PA_ROLLED_OVERDUE_DUE.CurrentState); Assert.Equal(StatusList.Overdue, stateList[0].StateStatus); Assert.Equal("TestGen1:State1", stateList[0].StateName); Assert.Equal(StatusList.Due, stateList[1].StateStatus); Assert.Equal("TestGen1:State2", stateList[1].StateName); Assert.Equal(StatusList.OnTime, stateList[2].StateStatus); Assert.Equal("TestGen1:State3", stateList[2].StateName); //Assert All States overdue except last state 'Due' await testWebClient.SetBusinessDate("15-01-2019"); var PA_ROLLED_ALL_OVERDUE_EX_LAST = await testWebClient.GetPlanningApp(PAL.Items.SingleOrDefault().Id); stateList = PA_ROLLED_ALL_OVERDUE_EX_LAST.PlanningAppStates.ToList(); Assert.Equal(StatusList.Overdue, PA_ROLLED_ALL_OVERDUE_EX_LAST.CurrentStateStatus); Assert.Equal("TestGen1:State1", PA_ROLLED_ALL_OVERDUE_EX_LAST.CurrentState); var TOT_OVERDUE = stateList.Where(s => s.StateStatus == StatusList.Overdue).Count();; Assert.Equal(4, TOT_OVERDUE); Assert.Equal(StatusList.Due, stateList[4].StateStatus); Assert.Equal("TestGen1:State5", stateList[4].StateName); //Assert All States overdue await testWebClient.SetBusinessDate("16-01-2019"); var PA_ROLLED_ALL_OVERDUE = await testWebClient.GetPlanningApp(PAL.Items.SingleOrDefault().Id); stateList = PA_ROLLED_ALL_OVERDUE.PlanningAppStates.ToList(); Assert.Equal(StatusList.Overdue, PA_ROLLED_ALL_OVERDUE.CurrentStateStatus); Assert.Equal("TestGen1:State1", PA_ROLLED_ALL_OVERDUE.CurrentState); Assert.True(stateList.All(s => s.StateStatus == StatusList.Overdue)); }
public async Task Post_PlanningAppNextStateTests(string url) { var f = _factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { //Override IService called during POST to return specific test calendar //services.AddScoped<IDateService, DateServiceTest>(); }); }); // Arrange var client = _factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { //Override IService called during POST to return specific test calendar //services.AddScoped<IDateService, DateServiceTest>(); }); }) .CreateClient(); var testWebClient = new TestWebClient(client); testWebClient.Login(); Console.WriteLine($"Calling Api Endpoint {url} "); var BD = await testWebClient.SetBusinessDate("01-01-2019"); var projectGenerators = await testWebClient.GetProjectGenerator(); var pg = projectGenerators.Items.FirstOrDefault(); await testWebClient.CreatePlanningApp(pg.Id); var PAL = await testWebClient.GetPlanningApps(); Assert.True(PAL.Items.Count() == 1); Assert.True(PAL.TotalItems == 1); //Check Paging Is Working var PA = await testWebClient.GetPlanningApp(PAL.Items.SingleOrDefault().Id); Assert.Equal(StatusList.OnTime, PA.CurrentStateStatus); Assert.Equal(StatusList.AppInProgress, PA.PlanningStatus); Assert.Equal("TestGen1:State1", PA.CurrentState); Assert.Equal("03-01-2019", PA.ExpectedStateCompletionDate); Assert.Equal("15-01-2019", PA.CompletionDate); var NEXT_STATE_PA = await testWebClient.NextState(PA.Id); Assert.Equal(StatusList.OnTime, NEXT_STATE_PA.CurrentStateStatus); Assert.Equal("TestGen1:State2", NEXT_STATE_PA.CurrentState); Assert.Equal("TestGen1:State3", NEXT_STATE_PA.NextState); Assert.Equal("07-01-2019", NEXT_STATE_PA.ExpectedStateCompletionDate); Assert.Equal("15-01-2019", NEXT_STATE_PA.CompletionDate); var stateList = NEXT_STATE_PA.PlanningAppStates.ToList(); Assert.Equal(StatusList.Complete, stateList[0].StateStatus); Assert.Equal("TestGen1:State1", stateList[0].StateName); Assert.Equal("01-01-2019", stateList[0].DateCompleted); Assert.Equal(StatusList.OnTime, stateList[1].StateStatus); Assert.Equal("TestGen1:State2", stateList[1].StateName); var COMPLETE_ALL_BUT_LAST_STATE_PA = await testWebClient.NextState(PA.Id); COMPLETE_ALL_BUT_LAST_STATE_PA = await testWebClient.NextState(PA.Id); COMPLETE_ALL_BUT_LAST_STATE_PA = await testWebClient.NextState(PA.Id); Assert.Equal(StatusList.OnTime, COMPLETE_ALL_BUT_LAST_STATE_PA.CurrentStateStatus); Assert.Equal("TestGen1:State5", COMPLETE_ALL_BUT_LAST_STATE_PA.CurrentState); //Assert All other States are Complete var stateListCtr = COMPLETE_ALL_BUT_LAST_STATE_PA.PlanningAppStates.ToList().Where(s => s.StateStatus == StatusList.Complete); Assert.Equal(4, stateListCtr.Count()); Assert.Null(COMPLETE_ALL_BUT_LAST_STATE_PA.NextState); //Assert Complete State var COMPLETE_PA = await testWebClient.NextState(PA.Id); Assert.Equal(StatusList.Complete, COMPLETE_PA.PlanningStatus); Assert.Null(COMPLETE_PA.CurrentState); Assert.Null(COMPLETE_PA.CurrentStateStatus); //Roll The Business Date To Make current state 'Due; // BD = await testWebClient.SetBusinessDate("02-01-2019"); // var PA_ROLLED_DUE = await testWebClient.GetPlanningApp(PAL.Items.SingleOrDefault().Id); }