Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions NBomber.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcClient", "examples\Grpc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookstoreSimulator", "examples\BookstoreSimulator\BookstoreSimulator.csproj", "{BB8FF9AE-4D47-47E7-9B22-F3ABDFDE28D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphQLServerSimulator", "examples\GraphQLServerSimulator\GraphQLServerSimulator.csproj", "{26A207DB-5268-4C0E-B92F-72005815AC4A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -129,6 +131,18 @@ Global
{BB8FF9AE-4D47-47E7-9B22-F3ABDFDE28D1}.Release|x64.Build.0 = Release|Any CPU
{BB8FF9AE-4D47-47E7-9B22-F3ABDFDE28D1}.Release|x86.ActiveCfg = Release|Any CPU
{BB8FF9AE-4D47-47E7-9B22-F3ABDFDE28D1}.Release|x86.Build.0 = Release|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Debug|x64.ActiveCfg = Debug|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Debug|x64.Build.0 = Debug|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Debug|x86.ActiveCfg = Debug|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Debug|x86.Build.0 = Debug|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Release|Any CPU.Build.0 = Release|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Release|x64.ActiveCfg = Release|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Release|x64.Build.0 = Release|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Release|x86.ActiveCfg = Release|Any CPU
{26A207DB-5268-4C0E-B92F-72005815AC4A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -142,6 +156,7 @@ Global
{D4E6343A-1042-CDB6-308D-6C1662607E77} = {B20C9B19-52F5-4AF1-B41D-D01294BEC6C9}
{EBBD9F26-59E7-0C55-0059-93AD3EB3469A} = {B20C9B19-52F5-4AF1-B41D-D01294BEC6C9}
{BB8FF9AE-4D47-47E7-9B22-F3ABDFDE28D1} = {B20C9B19-52F5-4AF1-B41D-D01294BEC6C9}
{26A207DB-5268-4C0E-B92F-72005815AC4A} = {B20C9B19-52F5-4AF1-B41D-D01294BEC6C9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C7E9329B-84FE-436E-8A44-26D8176C5C6F}
Expand Down
47 changes: 47 additions & 0 deletions examples/Demo/GraphQL/GraphQLExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using NBomber.CSharp;
using NBomber.Http.CSharp;
using System.Text;
using System.Text.Json;

namespace Demo.GraphQL;

class GraphQLExample
{
public void Run()
{
// For this example, you'll need to start the GraphQLServerSimulator, which is located in the examples/simulators solution folder.
// Make sure it’s running before executing the client tests to ensure proper communication.

var httpClient = new HttpClient();

var scenario = Scenario.Create("graphql_scenario", async context =>
{
var queryObject = new
{
query = @"
query {
users(where: { age: { gt: 20 } }) {
name
age
role {
name
}
}
}
"
};
string jsonQuery = JsonSerializer.Serialize(queryObject);

var request = Http.CreateRequest("POST", "http://localhost:5088/graphql")
.WithBody(new StringContent(jsonQuery, Encoding.UTF8, "application/json"));

return await Http.Send(httpClient, request);
})
.WithoutWarmUp()
.WithLoadSimulations(Simulation.KeepConstant(1, TimeSpan.FromSeconds(30)));

NBomberRunner
.RegisterScenarios(scenario)
.Run();
}
}
8 changes: 7 additions & 1 deletion examples/Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
using Demo.AMQP;
using Demo.AMQP.ClientPool;
using Demo.AMQP.IndependentActors;
using Demo.GraphQL;

// -------------------------------
// ----- Hello World examples -----
// -------------------------------
new HelloWorldExample().Run();
//new HelloWorldExample().Run();
// new ScenarioWithInit().Run();
// new ScenarioWithSteps().Run();
// new StepsShareData().Run();
Expand Down Expand Up @@ -134,6 +135,11 @@
// ----------------
// new GrpcExample().Run();

// ----------------
// ---- GraphQL ---
// ----------------
new GraphQLExample().Run();

// ----------------
// ----- Db -------
// ----------------
Expand Down
8 changes: 8 additions & 0 deletions examples/GraphQLServerSimulator/Contracts/Role.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace GraphQLServer.Contracts;

public class Role
{
public int Id { get; set; }
public string Name { get; set; }

Check warning on line 6 in examples/GraphQLServerSimulator/Contracts/Role.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in examples/GraphQLServerSimulator/Contracts/Role.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public ICollection<User> Users { get; set; }

Check warning on line 7 in examples/GraphQLServerSimulator/Contracts/Role.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Users' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in examples/GraphQLServerSimulator/Contracts/Role.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Users' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
11 changes: 11 additions & 0 deletions examples/GraphQLServerSimulator/Contracts/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace GraphQLServer.Contracts;

public class User
{
public int Id { get; set; }
public string Name { get; set; }

Check warning on line 6 in examples/GraphQLServerSimulator/Contracts/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in examples/GraphQLServerSimulator/Contracts/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Country { get; set; }

Check warning on line 7 in examples/GraphQLServerSimulator/Contracts/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Country' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 7 in examples/GraphQLServerSimulator/Contracts/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Country' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public int Age { get; set; }
public int RoleId { get; set; }
public Role Role { get; set; }

Check warning on line 10 in examples/GraphQLServerSimulator/Contracts/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Role' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 10 in examples/GraphQLServerSimulator/Contracts/User.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Role' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
29 changes: 29 additions & 0 deletions examples/GraphQLServerSimulator/Data/DbInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Bogus;
using GraphQLServer.Contracts;

namespace GraphQLServer.Data;

public static class DbInitializer
{
public static void Initialize(UserDbContext context)
{
if (context.Users.Any())
return;

var roleAdmin = new Role { Name = "Admin" };
var roleGuest = new Role { Name = "Guest" };

var testUsers = new Faker<User>()
.RuleFor(u => u.Name, f => f.Name.FullName())
.RuleFor(u => u.Country, f => f.Address.Country())
.RuleFor(u => u.Age, f => f.Random.Int(1, 100))
.RuleFor(u => u.RoleId, f => f.Random.Int(1, 2));

testUsers.GenerateBetween(100, 100);

context.Roles.AddRange(roleAdmin, roleGuest);
context.Users.AddRange(testUsers.GenerateBetween(100, 1000));

context.SaveChanges();
}
}
15 changes: 15 additions & 0 deletions examples/GraphQLServerSimulator/Data/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace GraphQLServer.Data;

public static class Extensions
{
public static void CreateDbIfNotExists(this IHost host)
{
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = services.GetRequiredService<UserDbContext>();
context.Database.EnsureCreated();
DbInitializer.Initialize(context);
}
}
}
23 changes: 23 additions & 0 deletions examples/GraphQLServerSimulator/Data/UserDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using GraphQLServer.Contracts;
using Microsoft.EntityFrameworkCore;

namespace GraphQLServer.Data;

public class UserDbContext : DbContext
{
public DbSet<User> Users => Set<User>();
public DbSet<Role> Roles => Set<Role>();

public UserDbContext(DbContextOptions<UserDbContext> options) : base(options) { }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<User>()
.HasOne(u => u.Role)
.WithMany(r => r.Users)
.HasForeignKey(u => u.RoleId)
.OnDelete(DeleteBehavior.Restrict);
}
}
18 changes: 18 additions & 0 deletions examples/GraphQLServerSimulator/GraphQLServerSimulator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

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

<ItemGroup>
<PackageReference Include="Bogus" Version="35.6.3" />
<PackageReference Include="HotChocolate.AspNetCore" Version="15.1.3" />
<PackageReference Include="HotChocolate.Data" Version="15.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions examples/GraphQLServerSimulator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using GraphQLServer;
using GraphQLServer.Data;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDbContext<UserDbContext>(options =>
options.UseInMemoryDatabase("UserDb"))
.AddLogging(Console.WriteLine);

builder.Services
.AddGraphQLServer()
.AddQueryType<Query>()
.AddFiltering();

var app = builder.Build();

app.CreateDbIfNotExists();

app.MapGraphQL();

app.Run();
13 changes: 13 additions & 0 deletions examples/GraphQLServerSimulator/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5088",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
11 changes: 11 additions & 0 deletions examples/GraphQLServerSimulator/Query.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using GraphQLServer.Contracts;
using GraphQLServer.Data;
using Microsoft.EntityFrameworkCore;

namespace GraphQLServer;

public class Query
{
[UseFiltering]
public IQueryable<User> GetUsers(UserDbContext dbContext) => dbContext.Users.Include(u => u.Role);
}
8 changes: 8 additions & 0 deletions examples/GraphQLServerSimulator/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions examples/GraphQLServerSimulator/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}