Renamed testing projects
This commit is contained in:
4
testing/HopFrame.Testing.Api/.gitignore
vendored
Normal file
4
testing/HopFrame.Testing.Api/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
obj
|
||||
bin
|
||||
Migrations
|
||||
appsettings.Development.json
|
||||
54
testing/HopFrame.Testing.Api/Controllers/TestController.cs
Normal file
54
testing/HopFrame.Testing.Api/Controllers/TestController.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using HopFrame.Api.Logic;
|
||||
using HopFrame.Database.Models;
|
||||
using HopFrame.Security.Authorization;
|
||||
using HopFrame.Security.Claims;
|
||||
using HopFrame.Testing.Api.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HopFrame.Testing.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("test")]
|
||||
public class TestController(ITokenContext userContext, DatabaseContext context) : ControllerBase {
|
||||
|
||||
[HttpGet("permissions"), Authorized]
|
||||
public ActionResult<IList<Permission>> Permissions() {
|
||||
return new ActionResult<IList<Permission>>(userContext.User.Permissions);
|
||||
}
|
||||
|
||||
[HttpGet("generate")]
|
||||
public async Task<ActionResult> GenerateData() {
|
||||
var employee = new Employee() {
|
||||
Name = "Max Mustermann"
|
||||
};
|
||||
|
||||
await context.AddAsync(employee);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
var address = new Address() {
|
||||
City = "Musterstadt",
|
||||
Country = "Musterland",
|
||||
State = "Musterbundesland",
|
||||
ZipCode = 12345,
|
||||
AddressDetails = "Musterstraße 5",
|
||||
Employee = employee
|
||||
};
|
||||
|
||||
await context.AddAsync(address);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
return LogicResult.Ok();
|
||||
}
|
||||
|
||||
[HttpGet("employees")]
|
||||
public async Task<ActionResult<IList<Employee>>> GetEmployees() {
|
||||
return LogicResult<IList<Employee>>.Ok(await context.Employees.Include(e => e.Address).ToListAsync());
|
||||
}
|
||||
|
||||
[HttpGet("addresses")]
|
||||
public async Task<ActionResult<IList<Address>>> GetAddresses() {
|
||||
return LogicResult<IList<Address>>.Ok(await context.Addresses.Include(e => e.Employee).ToListAsync());
|
||||
}
|
||||
|
||||
}
|
||||
25
testing/HopFrame.Testing.Api/DatabaseContext.cs
Normal file
25
testing/HopFrame.Testing.Api/DatabaseContext.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using HopFrame.Database;
|
||||
using HopFrame.Testing.Api.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HopFrame.Testing.Api;
|
||||
|
||||
public class DatabaseContext : HopDbContextBase {
|
||||
|
||||
public DbSet<Employee> Employees { get; set; }
|
||||
public DbSet<Address> Addresses { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
|
||||
optionsBuilder.UseSqlite(@"Data Source=C:\Users\leon\Documents\Projekte\HopFrame\testing\HopFrame.Testing.Api\bin\Debug\net8.0\test.db;Mode=ReadWrite;");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder) {
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Employee>()
|
||||
.HasOne(e => e.Address)
|
||||
.WithOne(a => a.Employee);
|
||||
}
|
||||
}
|
||||
23
testing/HopFrame.Testing.Api/HopFrame.Testing.Api.csproj
Normal file
23
testing/HopFrame.Testing.Api/HopFrame.Testing.Api.csproj
Normal file
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>disable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.7" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.7" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\HopFrame.Api\HopFrame.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
18
testing/HopFrame.Testing.Api/Models/Address.cs
Normal file
18
testing/HopFrame.Testing.Api/Models/Address.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
namespace HopFrame.Testing.Api.Models;
|
||||
|
||||
public class Address {
|
||||
[ForeignKey("Employee")]
|
||||
public int AddressId { get; set; }
|
||||
public string AddressDetails { get; set; }
|
||||
public string City { get; set; }
|
||||
public int ZipCode { get; set; }
|
||||
public string State { get; set; }
|
||||
public string Country { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual Employee Employee { get; set; }
|
||||
}
|
||||
8
testing/HopFrame.Testing.Api/Models/Employee.cs
Normal file
8
testing/HopFrame.Testing.Api/Models/Employee.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace HopFrame.Testing.Api.Models;
|
||||
|
||||
public class Employee {
|
||||
public int EmployeeId { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public virtual Address Address { get; set; }
|
||||
}
|
||||
56
testing/HopFrame.Testing.Api/Program.cs
Normal file
56
testing/HopFrame.Testing.Api/Program.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using HopFrame.Testing.Api;
|
||||
using HopFrame.Api.Extensions;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddHopFrame<DatabaseContext>();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddDbContext<DatabaseContext>();
|
||||
|
||||
builder.Services.AddSwaggerGen(c => {
|
||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme {
|
||||
Description = @"JWT Authorization header using the Bearer scheme. \r\n\r\n
|
||||
Enter 'Bearer' [space] and then your token in the text input below.",
|
||||
Name = "Authorization",
|
||||
In = ParameterLocation.Header,
|
||||
Type = SecuritySchemeType.ApiKey,
|
||||
Scheme = "Bearer"
|
||||
});
|
||||
|
||||
c.AddSecurityRequirement(new OpenApiSecurityRequirement {{
|
||||
new OpenApiSecurityScheme {
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
},
|
||||
Scheme = "oauth2",
|
||||
Name = "Bearer",
|
||||
In = ParameterLocation.Header,
|
||||
},
|
||||
ArraySegment<string>.Empty
|
||||
}});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment()) {
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
23
testing/HopFrame.Testing.Api/Properties/launchSettings.json
Normal file
23
testing/HopFrame.Testing.Api/Properties/launchSettings.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:19326",
|
||||
"sslPort": 44320
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7283;http://localhost:5158",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
testing/HopFrame.Testing.Api/appsettings.json
Normal file
10
testing/HopFrame.Testing.Api/appsettings.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"HopFrame.Security.Authentication.HopFrameAuthentication": "None"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user