Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Jan 12, 2024
1 parent 841da6a commit 4adfb28
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

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

<ItemGroup>
<None Remove="appsettings.json" />
</ItemGroup>

<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.IdentityMicroservice.Tests" Version="0.0.0.3" />
<PackageReference Include="EasyMicroservices.TemplateGeneratorMicroservice.Clients" Version="0.0.0.24" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
Expand All @@ -22,4 +35,12 @@
</PackageReference>
</ItemGroup>

<ItemGroup>
<Folder Include="Authentications\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EasyMicroservices.TemplateGeneratorMicroservice.WebApi\EasyMicroservices.TemplateGeneratorMicroservice.WebApi.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using EasyMicroservices.Cores.AspEntityFrameworkCoreApi;
using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces;
using EasyMicroservices.IdentityMicroservice.BackgroundServices;
using EasyMicroservices.IdentityMicroservice.Database.Contexts;
using EasyMicroservices.IdentityMicroservice.Interfaces;
using EasyMicroservices.IdentityMicroservice.WebApi.Controllers;
using EasyMicroservices.TemplateGeneratorMicroservice.Database.Contexts;
using EasyMicroservices.TemplateGeneratorMicroservice.DatabaseLogics;
using EasyMicroservices.TemplateGeneratorMicroservice.Helpers;
using EasyMicroservices.TemplateGeneratorMicroservice.WebApi;
using EasyMicroservices.TemplateGeneratorMicroservice.WebApi.Controllers;
using Identity.GeneratedServices;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using TemplateGenerators.GeneratedServices;
using Xunit;

namespace EasyMicroservices.TemplateGeneratorMicroservice.Tests.Fixtures;
public class TestFixture : IAsyncLifetime
{
public IServiceProvider ServiceProvider { get; private set; }
public Task DisposeAsync()
{
return Task.CompletedTask;
}

public async Task InitializeAsync()
{
var app = Program.CreateBuilder(null);
UnitOfWork.MapperTypeAssembly = typeof(ItemTypeDatabaseLogic);
string authBaseUrl = $"http://localhost:{2007}";
string generatorBaseUrl = $"http://localhost:{1050}";
app.Services.AddSingleton(s => new HttpClient());
app.Services.AddTransient(s => new AuthenticationClient(authBaseUrl, s.GetService<HttpClient>()));
app.Services.AddTransient(s => new NoParentFormItemClient(generatorBaseUrl, s.GetService<HttpClient>()));
app.Services.AddMvc().AddApplicationPart(typeof(FormController).Assembly);

var build = await app.BuildWithUseCors<TemplateGeneratorContext>(default, true);
build.MapControllers();
var scope = build.Services.CreateScope();
ApplicationManager.Instance.DependencyManager = scope.ServiceProvider.GetService<IUnitOfWork>();
ServiceProvider = app.Services.BuildServiceProvider();
_ = build.RunAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Databases": [
{
"Name": "Entity",
"ProviderName": "InMemory",
"ConnectionString": "Server=.;Database=TemplateGenerator;Integrated Security=True;Trusted_Connection=True;TrustServerCertificate=True"
}
],
"ServiceAddresses": [
{
"Name": "Authentication",
"Address": "http://localhost:1044",
"Databases": null
},
{
"Name": "WhiteLabel",
"Address": "http://localhost:1041",
"Databases": null
},
{
"Name": "Content",
"Address": "http://localhost:2003",
"Databases": null
}
],
"Authorization": {
"IsUse": true,
"JWT": {
"Key": "VGhpc0lzGHGHGHlY3JldEtleUZvckp3dEF1dGhlbnRpY2F0aW9u=",
"Issuer": "https://github.com/easymicroservices",
"Audience": "easymicroservices",

"TokenExpireTimeInSeconds": 86400
},
"FullAccessPAT": "ownerpat"
},
"Swagger": {
"IsUse": true,
"SwaggerUI": {
"Endpoints": []
}
},

"HasSSL": false,
"Urls": "http://*:1050"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using EasyMicroservices.Cores.Database.Managers;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces;
using EasyMicroservices.TemplateGeneratorMicroservice.Database.Contexts;
using EasyMicroservices.TemplateGeneratorMicroservice.Database.Entities;
using EasyMicroservices.TemplateGeneratorMicroservice.DatabaseLogics;
using EasyMicroservices.TemplateGeneratorMicroservice.Helpers;
using Microsoft.EntityFrameworkCore;

namespace EasyMicroservices.TemplateGeneratorMicroservice.WebApi
{
Expand All @@ -21,7 +23,7 @@ public static async Task Main(string[] args)
build.Run();
}

static WebApplicationBuilder CreateBuilder(string[] args)
public static WebApplicationBuilder CreateBuilder(string[] args)
{
var app = StartUpExtensions.Create<TemplateGeneratorContext>(args);
app.Services.Builder<TemplateGeneratorContext>("TemplateGenerator")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@
}
],
"Authorization": {
"Use": false,
"IsUse": true,
"JWT": {
"Key": "VGhpc0lzGHGHGHlY3JldEtleUZvckp3dEF1dGhlbnRpY2F0aW9u=",
"Issuer": "https://github.com/easymicroservices",
"Audience": "easymicroservices",

"TokenExpireTimeInSeconds": 86400
},
"FullAccessPAT": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJZCI6IjEiLCJyb2xlIjoiT3duZXIiLCJuYmYiOjE3MDEyNjQ4MTQsImV4cCI6MTcwMTM1MTIxNCwiaWF0IjoxNzAxMjY0ODE0LCJpc3MiOiJodHRwczovL2dpdGh1Yi5jb20vZWFzeW1pY3Jvc2VydmljZXMiLCJhdWQiOiJlYXN5bWljcm9zZXJ2aWNlcyJ9.CcfO9sXz3PY_QED7MwHe0-UJc_We_1NihDkAGonIsUs"
"FullAccessPAT": "ownerpat"
},
"Swagger": {
"IsUse": true,
"SwaggerUI": {
"Endpoints": []
}
},

"HasSSL": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@
}
],
"Authorization": {
"Use": false,
"IsUse": true,
"JWT": {
"Key": "VGhpc0lzGHGHGHlY3JldEtleUZvckp3dEF1dGhlbnRpY2F0aW9u=",
"Issuer": "https://github.com/easymicroservices",
"Audience": "easymicroservices",

"TokenExpireTimeInSeconds": 86400
},
"FullAccessPAT": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJZCI6IjEiLCJyb2xlIjoiT3duZXIiLCJuYmYiOjE3MDEyNjQ4MTQsImV4cCI6MTcwMTM1MTIxNCwiaWF0IjoxNzAxMjY0ODE0LCJpc3MiOiJodHRwczovL2dpdGh1Yi5jb20vZWFzeW1pY3Jvc2VydmljZXMiLCJhdWQiOiJlYXN5bWljcm9zZXJ2aWNlcyJ9.CcfO9sXz3PY_QED7MwHe0-UJc_We_1NihDkAGonIsUs"
"FullAccessPAT": "ownerpat"
},
"Swagger": {
"IsUse": true,
"SwaggerUI": {
"Endpoints": []
}
},

"HasSSL": false,
Expand Down

0 comments on commit 4adfb28

Please sign in to comment.