remove TestClient and update gitea workflow
This commit is contained in:
parent
24a08c314a
commit
b06acc7675
@ -25,7 +25,7 @@ jobs:
|
|||||||
- name: Setup .NET
|
- name: Setup .NET
|
||||||
uses: actions/setup-dotnet@v3
|
uses: actions/setup-dotnet@v3
|
||||||
with:
|
with:
|
||||||
dotnet-version: 8.x
|
dotnet-version: 10.x
|
||||||
|
|
||||||
- name: Restore dependencies
|
- name: Restore dependencies
|
||||||
run: dotnet restore
|
run: dotnet restore
|
||||||
|
|||||||
@ -1,36 +0,0 @@
|
|||||||
#!/usr/bin/env dotnet-script
|
|
||||||
#r "nuget: Grpc.Net.Client, 2.70.0"
|
|
||||||
#r "nuget: Google.Protobuf, 3.28.3"
|
|
||||||
#r "nuget: Grpc.Tools, 2.70.0"
|
|
||||||
|
|
||||||
using Grpc.Net.Client;
|
|
||||||
using Grpc.Core;
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
// We'll use reflection/dynamic to call the gRPC service
|
|
||||||
// This is a simple HTTP/2 test
|
|
||||||
|
|
||||||
var handler = new HttpClientHandler
|
|
||||||
{
|
|
||||||
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
|
|
||||||
};
|
|
||||||
|
|
||||||
using var channel = GrpcChannel.ForAddress("http://localhost:5000", new GrpcChannelOptions
|
|
||||||
{
|
|
||||||
HttpHandler = handler
|
|
||||||
});
|
|
||||||
|
|
||||||
Console.WriteLine("Connected to gRPC server at http://localhost:5000");
|
|
||||||
Console.WriteLine("Channel state: " + channel.State);
|
|
||||||
|
|
||||||
// Test basic connectivity
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await channel.ConnectAsync();
|
|
||||||
Console.WriteLine("Successfully connected!");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Connection failed: {ex.Message}");
|
|
||||||
}
|
|
||||||
@ -1,100 +0,0 @@
|
|||||||
using Grpc.Core;
|
|
||||||
using Grpc.Net.Client;
|
|
||||||
using Svrnty.CQRS.Grpc.Sample.Grpc;
|
|
||||||
|
|
||||||
Console.WriteLine("=== gRPC Client Validation Test ===");
|
|
||||||
Console.WriteLine();
|
|
||||||
|
|
||||||
// Create a gRPC channel
|
|
||||||
using var channel = GrpcChannel.ForAddress("http://localhost:5000");
|
|
||||||
|
|
||||||
// Create the gRPC client
|
|
||||||
var client = new CommandService.CommandServiceClient(channel);
|
|
||||||
|
|
||||||
// Test 1: Valid request
|
|
||||||
Console.WriteLine("Test 1: Valid AddUser request...");
|
|
||||||
var validRequest = new AddUserCommandRequest
|
|
||||||
{
|
|
||||||
Name = "John Doe",
|
|
||||||
Email = "john.doe@example.com",
|
|
||||||
Age = 30
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var response = await client.AddUserAsync(validRequest);
|
|
||||||
Console.WriteLine($"✓ Success! User added with ID: {response.Result}");
|
|
||||||
}
|
|
||||||
catch (RpcException ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"✗ Unexpected error: {ex.Status.Detail}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine();
|
|
||||||
|
|
||||||
// Test 2: Invalid email (empty)
|
|
||||||
Console.WriteLine("Test 2: Invalid email (empty)...");
|
|
||||||
var invalidEmailRequest = new AddUserCommandRequest
|
|
||||||
{
|
|
||||||
Name = "Jane Doe",
|
|
||||||
Email = "",
|
|
||||||
Age = 25
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var response = await client.AddUserAsync(invalidEmailRequest);
|
|
||||||
Console.WriteLine($"✗ Unexpected success! Validation should have failed.");
|
|
||||||
}
|
|
||||||
catch (RpcException ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"✓ Validation caught! Status: {ex.StatusCode}");
|
|
||||||
Console.WriteLine($" Message: {ex.Status.Detail}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine();
|
|
||||||
|
|
||||||
// Test 3: Invalid email format
|
|
||||||
Console.WriteLine("Test 3: Invalid email format...");
|
|
||||||
var badEmailRequest = new AddUserCommandRequest
|
|
||||||
{
|
|
||||||
Name = "Bob Smith",
|
|
||||||
Email = "not-an-email",
|
|
||||||
Age = 40
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var response = await client.AddUserAsync(badEmailRequest);
|
|
||||||
Console.WriteLine($"✗ Unexpected success! Validation should have failed.");
|
|
||||||
}
|
|
||||||
catch (RpcException ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"✓ Validation caught! Status: {ex.StatusCode}");
|
|
||||||
Console.WriteLine($" Message: {ex.Status.Detail}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine();
|
|
||||||
|
|
||||||
// Test 4: Invalid age (0)
|
|
||||||
Console.WriteLine("Test 4: Invalid age (0)...");
|
|
||||||
var invalidAgeRequest = new AddUserCommandRequest
|
|
||||||
{
|
|
||||||
Name = "Alice Brown",
|
|
||||||
Email = "alice@example.com",
|
|
||||||
Age = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var response = await client.AddUserAsync(invalidAgeRequest);
|
|
||||||
Console.WriteLine($"✗ Unexpected success! Validation should have failed.");
|
|
||||||
}
|
|
||||||
catch (RpcException ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"✓ Validation caught! Status: {ex.StatusCode}");
|
|
||||||
Console.WriteLine($" Message: {ex.Status.Detail}");
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine();
|
|
||||||
Console.WriteLine("All tests completed!");
|
|
||||||
@ -1,58 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
option csharp_namespace = "Svrnty.CQRS.Grpc.Sample.Grpc";
|
|
||||||
|
|
||||||
package cqrs;
|
|
||||||
|
|
||||||
// Command service for CQRS operations
|
|
||||||
service CommandService {
|
|
||||||
// Adds a new user and returns the user ID
|
|
||||||
rpc AddUser (AddUserCommandRequest) returns (AddUserCommandResponse);
|
|
||||||
|
|
||||||
// Removes a user
|
|
||||||
rpc RemoveUser (RemoveUserCommandRequest) returns (RemoveUserCommandResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Query service for CQRS operations
|
|
||||||
service QueryService {
|
|
||||||
// Fetches a user by ID
|
|
||||||
rpc FetchUser (FetchUserQueryRequest) returns (FetchUserQueryResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request message for adding a user
|
|
||||||
message AddUserCommandRequest {
|
|
||||||
string name = 1;
|
|
||||||
string email = 2;
|
|
||||||
int32 age = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response message containing the added user ID
|
|
||||||
message AddUserCommandResponse {
|
|
||||||
int32 result = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request message for removing a user
|
|
||||||
message RemoveUserCommandRequest {
|
|
||||||
int32 user_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response message for remove user (empty)
|
|
||||||
message RemoveUserCommandResponse {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request message for fetching a user
|
|
||||||
message FetchUserQueryRequest {
|
|
||||||
int32 user_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Response message containing the user
|
|
||||||
message FetchUserQueryResponse {
|
|
||||||
User result = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// User entity
|
|
||||||
message User {
|
|
||||||
int32 id = 1;
|
|
||||||
string name = 2;
|
|
||||||
string email = 3;
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Protobuf Include="Protos\*.proto" GrpcServices="Client" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Google.Protobuf" Version="3.33.0" />
|
|
||||||
<PackageReference Include="Grpc.Net.Client" Version="2.71.0" />
|
|
||||||
<PackageReference Include="Grpc.Tools" Version="2.76.0">
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
Loading…
Reference in New Issue
Block a user