feature/backend #2
12
BitSearch/BitSearch.API/BitSearch.API.csproj
Normal file
12
BitSearch/BitSearch.API/BitSearch.API.csproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
69
BitSearch/BitSearch.API/Controllers/SearchController.cs
Normal file
69
BitSearch/BitSearch.API/Controllers/SearchController.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using BitSearch.API.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BitSearch.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class SearchController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly ILogger<SearchController> _logger;
|
||||
private readonly IConfiguration Configuration;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
|
||||
public SearchController(ILogger<SearchController> logger, IConfiguration configuration, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_httpClientFactory = httpClientFactory;
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
[HttpGet("ranking")]
|
||||
public IActionResult GetRanking()
|
||||
{
|
||||
//var request = new HttpRequestMessage(HttpMethod.Get, "https://api.twitter.com/2/tweets/counts/recent");
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("analise/{hash}")]
|
||||
public async Task<IActionResult> GetAnalysis(string hash)
|
||||
{
|
||||
var queryString = new Dictionary<string, string>()
|
||||
{
|
||||
{"query", hash},
|
||||
{"max_results", "100"},
|
||||
{"tweet.fields", "lang,referenced_tweets"},
|
||||
};
|
||||
|
||||
var token = Configuration["Token"];
|
||||
var httpClient = _httpClientFactory.CreateClient();
|
||||
httpClient.BaseAddress = new Uri("https://api.twitter.com/2/tweets/search/");
|
||||
var requestUri = QueryHelpers.AddQueryString("recent", queryString);
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
var response = await httpClient.SendAsync(request);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return Ok(await response.Content.ReadAsStringAsync());
|
||||
}
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
}
|
15
BitSearch/BitSearch.API/Models/CryptoAnalysis.cs
Normal file
15
BitSearch/BitSearch.API/Models/CryptoAnalysis.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BitSearch.API.Models
|
||||
{
|
||||
public class CryptoAnalysis
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public decimal Positive { get; set; }
|
||||
public decimal Negative { get; set; }
|
||||
|
||||
}
|
||||
}
|
14
BitSearch/BitSearch.API/Models/CryptoRanking.cs
Normal file
14
BitSearch/BitSearch.API/Models/CryptoRanking.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BitSearch.API.Models
|
||||
{
|
||||
public class CryptoRanking
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Hasztag { get; set; }
|
||||
public int TweetAmount { get; set; }
|
||||
}
|
||||
}
|
26
BitSearch/BitSearch.API/Program.cs
Normal file
26
BitSearch/BitSearch.API/Program.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BitSearch.API
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
}
|
||||
}
|
31
BitSearch/BitSearch.API/Properties/launchSettings.json
Normal file
31
BitSearch/BitSearch.API/Properties/launchSettings.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:62241",
|
||||
"sslPort": 44393
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"BitSearch.API": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": "true",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
BitSearch/BitSearch.API/Startup.cs
Normal file
60
BitSearch/BitSearch.API/Startup.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BitSearch.API
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
|
||||
services.AddControllers();
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "BitSearch.API", Version = "v1" });
|
||||
});
|
||||
services.AddHttpClient();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "BitSearch.API v1"));
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
9
BitSearch/BitSearch.API/appsettings.Development.json
Normal file
9
BitSearch/BitSearch.API/appsettings.Development.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
12
BitSearch/BitSearch.API/appsettings.json
Normal file
12
BitSearch/BitSearch.API/appsettings.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Token": "AAAAAAAAAAAAAAAAAAAAAJm8XwEAAAAAWyiq2ESxmQgVp5gCbvccbnLzfrE%3D1g4gSrKfNveU4E382aWh6JYkESNw09tsraYMFcdv6Wk87kQixh"
|
||||
|
||||
}
|
16
BitSearch/BitSearch.Tests/BitSearch.Tests.csproj
Normal file
16
BitSearch/BitSearch.Tests/BitSearch.Tests.csproj
Normal file
@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
70
BitSearch/BitSearch.Tests/LoginTests.cs
Normal file
70
BitSearch/BitSearch.Tests/LoginTests.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using NUnit.Framework;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Chrome;
|
||||
|
||||
namespace BitSearch.Tests
|
||||
{
|
||||
public class Browser_ops
|
||||
{
|
||||
IWebDriver webDriver;
|
||||
public void Init_Browser()
|
||||
{
|
||||
var options = new ChromeOptions();
|
||||
options.AcceptInsecureCertificates = true;
|
||||
webDriver = new ChromeDriver("C:\\Program Files (x86)\\Google\\Chrome\\Application", options);
|
||||
webDriver.Manage().Window.Maximize();
|
||||
}
|
||||
public string Title
|
||||
{
|
||||
get { return webDriver.Title; }
|
||||
}
|
||||
public void Goto(string url)
|
||||
{
|
||||
webDriver.Url = url;
|
||||
}
|
||||
public void Close()
|
||||
{
|
||||
webDriver.Quit();
|
||||
}
|
||||
public IWebDriver getDriver
|
||||
{
|
||||
get { return webDriver; }
|
||||
}
|
||||
}
|
||||
|
||||
public class LoginTests
|
||||
{
|
||||
Browser_ops brow = new Browser_ops();
|
||||
string test_url = "https://localhost:44371/Identity/Account/Login";
|
||||
IWebDriver driver;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
brow.Init_Browser();
|
||||
driver = brow.getDriver;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void VerifyValidLogin()
|
||||
{
|
||||
brow.Goto(test_url);
|
||||
System.Threading.Thread.Sleep(2000);
|
||||
driver.FindElement(By.XPath("//*[@id='Input_Email']")).SendKeys("testowy@mail.com");
|
||||
driver.FindElement(By.XPath("//*[@id='Input_Password']")).SendKeys("12#qwE");
|
||||
driver.FindElement(By.XPath("//*[@id='login-submit']")).Click();
|
||||
Assert.AreEqual(driver.Url, "https://localhost:44371/");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void VerifyInvalidLogin()
|
||||
{
|
||||
brow.Goto(test_url);
|
||||
System.Threading.Thread.Sleep(2000);
|
||||
driver.FindElement(By.XPath("//*[@id=\"Input_Email\"]")).SendKeys("wrong@mail.com");
|
||||
driver.FindElement(By.XPath("//*[@id='Input_Password']")).SendKeys("invalid");
|
||||
driver.FindElement(By.XPath("//*[@id='login-submit']")).Click();
|
||||
Assert.AreEqual(driver.FindElement(By.XPath("//*[@id='account']/div[1]/ul/li")).Text, "Invalid login attempt.");
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31112.23
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitSearch", "BitSearch\BitSearch.csproj", "{F5F997CE-0BBE-478A-B7A3-828B0EAB8B99}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitSearch", "BitSearch\BitSearch.csproj", "{F5F997CE-0BBE-478A-B7A3-828B0EAB8B99}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitSearch.Tests", "BitSearch.Tests\BitSearch.Tests.csproj", "{8B871554-1F3D-4828-9642-B191B499A80C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitSearch.API", "BitSearch.API\BitSearch.API.csproj", "{08FC64E2-3128-4517-ADCA-D1BF8AF126F0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +19,14 @@ Global
|
||||
{F5F997CE-0BBE-478A-B7A3-828B0EAB8B99}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F5F997CE-0BBE-478A-B7A3-828B0EAB8B99}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F5F997CE-0BBE-478A-B7A3-828B0EAB8B99}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8B871554-1F3D-4828-9642-B191B499A80C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8B871554-1F3D-4828-9642-B191B499A80C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8B871554-1F3D-4828-9642-B191B499A80C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8B871554-1F3D-4828-9642-B191B499A80C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{08FC64E2-3128-4517-ADCA-D1BF8AF126F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{08FC64E2-3128-4517-ADCA-D1BF8AF126F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{08FC64E2-3128-4517-ADCA-D1BF8AF126F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{08FC64E2-3128-4517-ADCA-D1BF8AF126F0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user