Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
SwimmingRieux committed Sep 8, 2024
2 parents e6bf5d7 + 70d178b commit 40f1614
Show file tree
Hide file tree
Showing 179 changed files with 1,467 additions and 1,540 deletions.
71 changes: 35 additions & 36 deletions RelationAnalysis.Migrations/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,46 @@
using Microsoft.Extensions.Hosting;
using RelationshipAnalysis.Context;

namespace RelationAnalysis.Migrations
namespace RelationAnalysis.Migrations;

internal class Program
{
class Program
private static async Task Main(string[] args)
{
static async Task Main(string[] args)
{
Console.WriteLine("Run console app!");


var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
config.AddJsonFile("appsettings.json");
config.AddEnvironmentVariables();
})
.ConfigureServices((context, services) =>
{
var configuration = context.Configuration;
var connectionString = configuration.GetValue<string>("CONNECTION_STRING");

services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(connectionString));

services.AddTransient<InitialRecordsCreator>();
})
.Build();

var configuration = host.Services.GetRequiredService<IConfiguration>();
Console.WriteLine(configuration.GetValue<string>("CONNECTION_STRING"));
Console.WriteLine(configuration.GetValue<string>("DefaultPassword"));

using (var scope = host.Services.CreateScope())
Console.WriteLine("Run console app!");


var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
config.AddJsonFile("appsettings.json");
config.AddEnvironmentVariables();
})
.ConfigureServices((context, services) =>
{
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
await dbContext.Database.MigrateAsync();
var configuration = context.Configuration;
var connectionString = configuration.GetValue<string>("CONNECTION_STRING");

var myService = scope.ServiceProvider.GetRequiredService<InitialRecordsCreator>();
await myService.AddInitialRecords();
}
services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(connectionString));

Console.WriteLine("Done");
services.AddTransient<InitialRecordsCreator>();
})
.Build();

var configuration = host.Services.GetRequiredService<IConfiguration>();
Console.WriteLine(configuration.GetValue<string>("CONNECTION_STRING"));
Console.WriteLine(configuration.GetValue<string>("DefaultPassword"));

using (var scope = host.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
await dbContext.Database.MigrateAsync();

var myService = scope.ServiceProvider.GetRequiredService<InitialRecordsCreator>();
await myService.AddInitialRecords();
}

Console.WriteLine("Done");
}
}
34 changes: 13 additions & 21 deletions RelationAnalysis.Migrations/RelationAnalysis.Migrations.csproj
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dotenv" Version="0.0.1.1" />
<PackageReference Include="DotNetEnv" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Hosting">
<HintPath>..\..\..\..\..\..\usr\share\dotnet\shared\Microsoft.AspNetCore.App\8.0.8\Microsoft.AspNetCore.Hosting.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration">
<HintPath>..\..\..\..\..\..\usr\share\dotnet\shared\Microsoft.AspNetCore.App\8.0.8\Microsoft.Extensions.Configuration.dll</HintPath>
</Reference>
<ItemGroup>
<PackageReference Include="Dotenv" Version="0.0.1.1"/>
<PackageReference Include="DotNetEnv" Version="3.1.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.8"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RelationshipAnalysis\RelationshipAnalysis.csproj" />
<ProjectReference Include="..\RelationshipAnalysis\RelationshipAnalysis.csproj"/>
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using Microsoft.Extensions.Options;
using RelationshipAnalysis.Dto;
using RelationshipAnalysis.Dto.Panel.Admin;
using RelationshipAnalysis.Dto.Panel.User;
Expand Down Expand Up @@ -37,10 +38,10 @@ private string GenerateAdminJwtToken()
FirstName = "Admin",
LastName = "User",
Email = "[email protected]",
UserRoles = new List<UserRole> { new UserRole { Role = new Role { Name = "Admin" } } }
UserRoles = new List<UserRole> { new() { Role = new Role { Name = "Admin" } } }
};

return new JwtTokenGenerator(new Microsoft.Extensions.Options.OptionsWrapper<JwtSettings>(jwtSettings))
return new JwtTokenGenerator(new OptionsWrapper<JwtSettings>(jwtSettings))
.GenerateJwtToken(user);
}

Expand Down Expand Up @@ -92,7 +93,6 @@ public async Task GetAllUsers_ShouldReturnUsers_WhenAdminIsAuthorized()
Assert.NotNull(responseData);
Assert.True(responseData.AllUserCount > 0);
Assert.True(responseData.Users.Count > 0);

}

[Fact]
Expand Down Expand Up @@ -126,7 +126,7 @@ public async Task CreateUser_ShouldReturnSuccess_WhenAdminIsAuthorized()
FirstName = "New",
LastName = "User",
Email = "[email protected]",
Roles = [ "Admin" ]
Roles = ["Admin"]
};

var request = new HttpRequestMessage(HttpMethod.Post, "/api/admin/users");
Expand Down Expand Up @@ -160,7 +160,7 @@ public async Task CreateUser_ShouldReturnBadRequest_WhenUsernameIsNotUnique()
FirstName = "Existing",
LastName = "User",
Email = "[email protected]",
Roles = [ "Admin" ]
Roles = ["Admin"]
};

var request = new HttpRequestMessage(HttpMethod.Post, "/api/admin/users");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using Microsoft.Extensions.Options;
using RelationshipAnalysis.Dto;
using RelationshipAnalysis.Dto.Panel.User;
using RelationshipAnalysis.Models.Auth;
Expand Down Expand Up @@ -38,7 +39,7 @@ private string GenerateJwtToken()
Email = "[email protected]"
};

return new JwtTokenGenerator(new Microsoft.Extensions.Options.OptionsWrapper<JwtSettings>(jwtSettings)).GenerateJwtToken(user);
return new JwtTokenGenerator(new OptionsWrapper<JwtSettings>(jwtSettings)).GenerateJwtToken(user);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
Expand All @@ -18,37 +15,24 @@
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0"/>
<PackageReference Include="xunit" Version="2.5.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0"/>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RelationshipAnalysis\RelationshipAnalysis.csproj"/>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Compile Update="Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<Reference Include="NSubstitute">
<HintPath>..\..\..\..\.nuget\packages\nsubstitute\5.1.0\lib\net6.0\NSubstitute.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
</Project>
Loading

0 comments on commit 40f1614

Please sign in to comment.