Rony.Net 0.1.2

dotnet add package Rony.Net --version 0.1.2                
NuGet\Install-Package Rony.Net -Version 0.1.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rony.Net" Version="0.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rony.Net --version 0.1.2                
#r "nuget: Rony.Net, 0.1.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rony.Net as a Cake Addin
#addin nuget:?package=Rony.Net&version=0.1.2

// Install Rony.Net as a Cake Tool
#tool nuget:?package=Rony.Net&version=0.1.2                

NuGet version

Rony.Net

A simple TCP/UDP mock server for using in test projects which test .Net core based projects.

Problem

When I was working on Cimon.Net project, I realized that I can't mock sockets with existed libraries, So I changed my project to create fake sockets. But the problem still existed, So I started to write this project and finally I used this in Cimon.Net.

Install

You can install Rony.Net with NuGet Package Manager Console:

Install-Package Rony.Net -Version 0.1.2

Or via the .NET Core command-line interface:

dotnet add package Rony.Net --version 0.1.2

Usage

With Rony.Net you can create 3 types of Server :

  • TCP Server
  • TCP Server with SSL/TLS support
  • UDP Server

You can create and run mock servers as below. Port, IP and other settings are configurable via constructors :

using var tcpServer = new MockServer(new TcpServer(3000));
tcpSever.Start();
using var tcpSslServer = new MockServer(new TcpServerSsl(4000, certificateName, SslProtocols.None));
tcpSslServer.Start();

You must address a valid and installed certificate which you have read permission on its private key, and also you can set SslProtocol based on your requirements.

using var udpServer = new MockServer(new UdpServer(5000));

Please pay attention that UDP server does not need to start, because of its nature.

Then you can use a normal client to connect and sending request to them, just like below :

using var client = new TcpClient();
await client.ConnectAsync(IPAddress.Parse("127.0.0.1"), 3000);
var client = new UdpClient();
client.Connect(IPAddress.Parse("127.0.0.1"), 5000);

You can use mockServer.Mock to manage Send/Receive data, then server will return configured data, based on sent data:

mockServer.Mock.Send("Test String").Receive("Test Response");
mockServer.Mock.Send(new byte[] { 1, 2, 3 }).Receive(new byte[] { 3, 2, 1 });
mockServer.Mock.Send("abcd").Receive(x=> x.ToUpper());

An important option in using mockServer.Mock is adding Any request to it, then it will reply to any unconfigured request base on this config (verion 0.1.1 and later), you can config server for this option by using an empty string in Send() method, just like below :

mockServer.Mock.Send("").Receive("Test Response");

You can use mockServer.Mock either before or after mockServer.Run(). For more details please check Test projects.

Compile

You need at least Visual Studio 2019 (you can download the Community Edition for free).

Running the tests

All tests uses Xunit, for running TCP server with SSL/TLS, you should change _certificateName field to a certificate name on your machine. Please pay attention that you must have read permission on private key of certificate.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.2 2,704 1/2/2021
0.1.1 570 1/2/2021
0.1.0 653 12/31/2020 0.1.0 is deprecated because it has critical bugs.

Changed server loginc for adding any request feature to it, and solve some minor bugs