HavenDV / H.Pipes

A simple, easy to use, strongly-typed, async wrapper around .NET named pipes.
MIT License
242 stars 26 forks source link

Couldn't send data in specflow testing application via pipes #44

Closed DharaniRajamani closed 9 months ago

DharaniRajamani commented 9 months ago

Describe the bug

While I am H Pipes in specflow, c# and nunit Framework for testing the pipe connection and passing data using pipes.

image

The WriteAsync function is called but it's not sending the data to the client application.

Steps to reproduce the bug

  1. create specflow feature file
  2. use the below coding for testing

private PipeServer? _server;

[When(@"Get Sending Data")] public async Task WhenSendingData() {

 do
 {

    Task.Run(() => StartServer());

 } while (Console.ReadKey(true).Key != ConsoleKey.Escape);

}

public async Task StartServer() {

 while (!_token.IsCancellationRequested && _server is not { IsStarted: true })
 {
     try
     {

         _server = new PipeServer<string>("TestPipe");

         _server.ClientConnected += OnClientConnected;

         await _server.StartAsync(_token.Token);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Failed to start server");
     }
 }

}

public void OnClientConnected(object? sender, ConnectionEventArgs e) { Console.WriteLine($"Client has connected to {e.Connection.PipeName}"); Console.WriteLine($"Client has connected to {e.Connection}");

     e.Connection.WriteAsync("Welcome!");

}

  1. Run the test

There is no bug but it's not communicating. If i close the c++ execution, it's giving me pipe closed error. The id for Pipe is also created

Test.SignalPipe_ba006207-cdaf-4365-99b8-a06258d3c65e

Please not the same is working well in console application where I could send message but not working in specflow testing application.

Expected behavior

No response

Screenshots

No response

NuGet package version

<PackageReference Include="H.Formatters.BinaryFormatter" Version="2.0.59" />
<PackageReference Include="H.Pipes" Version="2.0.59" />
<PackageReference Include="H.Pipes.AccessControl" Version="2.0.59" />

Platform

Console

IDE

Visual Studio 2022

Additional context

No response