-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Startup class to work only Program.cs class (#19)
* Remove Startup class * Remove deprecated packages from API Project ans fix API Startup from Docker * Remove unused code
- Loading branch information
Showing
8 changed files
with
76 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,11 @@ | ||
using System; | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using NLog; | ||
using NLog.Web; | ||
using Orion.Api; | ||
|
||
namespace Orion.Api | ||
{ | ||
public static class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
try | ||
{ | ||
CreateWebHostBuilder(args).Build().Run(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.Error(ex, "Stopped program because of exception"); | ||
throw; | ||
} | ||
finally | ||
{ | ||
LogManager.Shutdown(); | ||
} | ||
} | ||
builder.Services.ConfigureServices(builder.Configuration); | ||
|
||
private static IWebHostBuilder CreateWebHostBuilder(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseUrls("http://*:5000") | ||
.UseStartup<Startup>() | ||
.UseIISIntegration() | ||
.ConfigureLogging((context, logging) => | ||
{ | ||
logging.ClearProviders(); | ||
logging.AddConsole(); | ||
}).UseNLog(); | ||
var app = builder.Build(); | ||
|
||
} | ||
} | ||
app.ConfigureApp(); | ||
|
||
app.Run(); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,51 @@ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json; | ||
using Orion.Api.Models; | ||
using System; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using Orion.Api; | ||
using Orion.Api.Models; | ||
|
||
namespace Orion.Test.Configuration | ||
{ | ||
public abstract class ApiTestInitializer : WebApplicationFactory<Startup> | ||
public abstract class ApiTestInitializer : IDisposable | ||
{ | ||
protected HttpClient Client; | ||
protected string AuthToken; | ||
|
||
public ApiTestInitializer() | ||
{ | ||
protected readonly HttpClient Client; | ||
protected readonly HttpClient AuthenticatedClient; | ||
protected IServiceProvider ServiceProvider { get; private set; } | ||
|
||
} | ||
|
||
public void Setup() | ||
public ApiTestInitializer() | ||
{ | ||
var builder = new WebHostBuilder(); | ||
|
||
base.ConfigureWebHost(builder); | ||
|
||
Client = Server.CreateClient(); | ||
var appFactory = new WebApplicationFactory<Program>() | ||
.WithWebHostBuilder(builder => | ||
{ | ||
var config = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.Test.json", optional: false, reloadOnChange: true) | ||
.Build(); | ||
|
||
AuthUser(); | ||
|
||
Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AuthToken); | ||
builder | ||
.UseConfiguration(config) | ||
.ConfigureServices(services => | ||
{ | ||
}); | ||
}); | ||
ServiceProvider = appFactory.Services; | ||
Client = appFactory.CreateClient(); | ||
AuthenticatedClient = appFactory.CreateClient(); | ||
} | ||
|
||
public void AuthUser() | ||
{ | ||
var result = Client.PostAsync("/api/Auth/Login", GetStringContent(new UserLoginModel { Email = "[email protected]", Password = "123" })).GetAwaiter().GetResult(); | ||
var result = Client.PostAsync("/api/Auth/Login", GetStringContent( | ||
new UserLoginModel { | ||
Email = "[email protected]", | ||
Password = "123" | ||
})) | ||
.GetAwaiter().GetResult(); | ||
|
||
var content = result.Content.ReadAsStringAsync().GetAwaiter().GetResult(); | ||
|
||
|
@@ -48,12 +59,25 @@ protected static StringContent GetStringContent(object obj) | |
return new StringContent(JsonConvert.SerializeObject(obj), Encoding.Default, "application/json"); | ||
} | ||
|
||
protected override void ConfigureWebHost(IWebHostBuilder builder) | ||
private bool _disposedValue = false; | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
builder.UseEnvironment("Test") | ||
.UseStartup<Startup>(); | ||
if (!_disposedValue) | ||
{ | ||
_disposedValue = true; | ||
} | ||
} | ||
|
||
base.ConfigureWebHost(builder); | ||
~ApiTestInitializer() | ||
{ | ||
Dispose(false); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters