переделывание тестов

This commit is contained in:
2025-02-05 10:58:50 +03:00
parent fd1eda2661
commit f51dd93c87
28 changed files with 407 additions and 325 deletions
@@ -116,7 +116,7 @@ namespace {Namespace}
foreach (var method in methodBody)
{
var index = methods.Count;
methods.Add((namespaceName + "." + className, method));
methods.Add((namespaceName + "." + originalName, method));
var sb = new StringBuilder();
//Creating signature
@@ -230,6 +230,14 @@ public class CoCodegenMethodRepository :IMethodRepository
{{
return _methods;
}}
public void Inject<T>(T dependency)
{{
}}
public void Bake()
{{
}}
}}
";
context.AddSource($"CoCodegenMethodRepository.g.cs", SourceText.From(coCodegenRepoCode, Encoding.UTF8));
@@ -237,10 +245,11 @@ public class CoCodegenMethodRepository :IMethodRepository
var fronendRepoCode = @$"// <auto-generated/>
using System.Collections.Frozen;
namespace mROA.Implementation;
namespace mROA.Codegen;
public class FrontendContextRepository(ISerialisationModule.IFrontendSerialisationModule serialisationModule) : IContextRepository
public class FrontendContextRepository : IContextRepository
{{
private ISerialisationModule.IFrontendSerialisationModule _serialisationModule;
private static readonly FrozenDictionary<Type, Type> _remoteTypes = new Dictionary<Type, Type> {{
{string.Join(", \r\n\t\t", frontendContextRepo)}}}.ToFrozenDictionary();
@@ -263,7 +272,7 @@ public class FrontendContextRepository(ISerialisationModule.IFrontendSerialisati
{{
if (_remoteTypes.TryGetValue(typeof(T), out var remoteType))
{{
var remote = (T)Activator.CreateInstance(remoteType, id, serialisationModule)!;
var remote = (T)Activator.CreateInstance(remoteType, id, _serialisationModule)!;
return remote;
}}
throw new NotSupportedException();
@@ -271,7 +280,7 @@ public class FrontendContextRepository(ISerialisationModule.IFrontendSerialisati
public object GetSingleObject(Type type)
{{
return Activator.CreateInstance(_remoteTypes[type], -1, serialisationModule)!;
return Activator.CreateInstance(_remoteTypes[type], -1, _serialisationModule)!;
}}
public int GetObjectIndex(object o)
@@ -282,6 +291,16 @@ public class FrontendContextRepository(ISerialisationModule.IFrontendSerialisati
}}
throw new NotSupportedException();
}}
public void Inject<T>(T dependency)
{{
if (dependency is ISerialisationModule.IFrontendSerialisationModule serialisationModule)
_serialisationModule = serialisationModule;
}}
public void Bake()
{{
}}
}}
";
context.AddSource("FrontendContextRepository.g.cs", SourceText.From(fronendRepoCode, Encoding.UTF8));
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ad2ef8e4b754b4cb2c5d3dbaa5c24f15201dd0f9")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+fd1eda26618b8cebe94eaa0e27ce5e97353d2d09")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -5,18 +5,18 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Mikhail\.nuget\packages\" />
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.codeanalysis.analyzers\3.3.4\buildTransitive\Microsoft.CodeAnalysis.Analyzers.props" Condition="Exists('$(NuGetPackageRoot)microsoft.codeanalysis.analyzers\3.3.4\buildTransitive\Microsoft.CodeAnalysis.Analyzers.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgMicrosoft_CodeAnalysis_Analyzers Condition=" '$(PkgMicrosoft_CodeAnalysis_Analyzers)' == '' ">C:\Users\Mikhail\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.4</PkgMicrosoft_CodeAnalysis_Analyzers>
<PkgMicrosoft_CodeAnalysis_Analyzers Condition=" '$(PkgMicrosoft_CodeAnalysis_Analyzers)' == '' ">C:\Users\Mimm\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.4</PkgMicrosoft_CodeAnalysis_Analyzers>
</PropertyGroup>
</Project>
+1 -3
View File
@@ -1,7 +1,4 @@
using System.Runtime.InteropServices;
using mROA.Codegen;
using mROA.Implementation.Test;
namespace mROA.Example;
@@ -21,5 +18,6 @@ public class MainX
var size = Marshal.SizeOf(typeof(T));
var place = Marshal.AllocHGlobal(size);
var pt = (T*)place;
return [];
}
}
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Example")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ad2ef8e4b754b4cb2c5d3dbaa5c24f15201dd0f9")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+fd1eda26618b8cebe94eaa0e27ce5e97353d2d09")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Example")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Example")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -5,12 +5,12 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Mikhail\.nuget\packages\" />
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>
+21 -7
View File
@@ -1,6 +1,8 @@
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using mROA.Abstract;
using mROA.Codegen;
using mROA.Example;
using mROA.Implementation;
@@ -21,21 +23,33 @@ public class FrontendFinalTest
[SetUp]
public void Setup()
{
var repo = new MethodRepository();
repo.CollectForAssembly(Assembly.GetExecutingAssembly());
_methodRepository = repo;
_methodRepository = new CoCodegenMethodRepository();
var repo2 = new ContextRepository();
repo2.FillSingletons(Assembly.GetExecutingAssembly());
repo2.FillSingletons(typeof(ITestController).Assembly);
_contextRepository = repo2;
_interactionModule = new StreamBasedInteractionModule();
_serialisationModule = new JsonSerialisationModule(_interactionModule, _methodRepository);
_serialisationModule = new JsonSerialisationModule();
_executeModule = new LaunchReadyExecutionModule(_methodRepository, _serialisationModule, _contextRepository);
_executeModule = new LaunchReadyExecutionModule();
IInjectableModule[] backendModules = [_methodRepository, _contextRepository, _interactionModule, _serialisationModule, _executeModule];
foreach (var backendModule in backendModules)
foreach (var injection in backendModules)
backendModule.Inject(injection);
_frontendInteractionModule = new StreamBasedFrontendInteractionModule();
_frontendSerialisationModule = new JsonFrontendSerialisationModule(_frontendInteractionModule);
_frontendSerialisationModule = new JsonFrontendSerialisationModule();
_frontendContextRepository = new FrontendContextRepository();
IInjectableModule[] frontendModules = [_frontendInteractionModule, _frontendSerialisationModule, _frontendContextRepository];
foreach (var backendModule in frontendModules)
foreach (var injection in frontendModules)
backendModule.Inject(injection);
Task.Run(() =>
{
TcpListener listener = new TcpListener(IPAddress.Loopback, 4567);
+65 -66
View File
@@ -1,66 +1,65 @@
using System.Net;
using System.Net.Sockets;
using System.Text.Json;
using mROA.Implementation;
using mROA.Implementation.Test;
namespace mROA.Test;
public class StreamTest
{
private StreamBasedInteractionModule _interactionModule;
private StreamBasedFrontendInteractionModule _frontendInteractionModule;
private JsonFrontendSerialisationModule _frontendSerialisationModule;
private ISerialisationModule _serialisationModule;
private IExecuteModule _executeModule;
bool isTestNotFinished = true;
[SetUp]
public void Setup()
{
_interactionModule = new StreamBasedInteractionModule();
_serialisationModule = new JsonSerialisationModule(_interactionModule, new MockMethodRepository());
_executeModule = new MockExecModule();
_serialisationModule.SetExecuteModule(_executeModule);
_frontendInteractionModule = new StreamBasedFrontendInteractionModule();
_frontendSerialisationModule = new JsonFrontendSerialisationModule(_frontendInteractionModule);
Task.Run(() =>
{
TcpListener listener = new TcpListener(IPAddress.Loopback, 4567);
listener.Start();
var stream = listener.AcceptTcpClient().GetStream();
Console.WriteLine("Client connected");
_interactionModule.RegisterSourse(stream);
while (isTestNotFinished) ;
});
}
[Test]
public void StreamingTest()
{
var tcpClient = new TcpClient();
tcpClient.Connect(IPAddress.Loopback, 4567);
_frontendInteractionModule.ServerStream = tcpClient.GetStream();
var req = new DefaultCallRequest { CommandId = 1, ObjectId = -1 };
_frontendSerialisationModule.PostCallRequest(req);
var res = ((JsonElement)_frontendSerialisationModule.GetNextCommandExecution<FinalCommandExecution>(req.CallRequestId).GetAwaiter().GetResult().Result!).Deserialize<MockResult>();
isTestNotFinished = false;
Assert.That(res.A == "wqer" && res.B == 5);
}
[Test]
public void RemoteObjectTest()
{
}
}
// using System.Net;
// using System.Net.Sockets;
// using System.Text.Json;
// using mROA.Implementation;
//
// namespace mROA.Test;
//
// public class StreamTest
// {
// private StreamBasedInteractionModule _interactionModule;
// private StreamBasedFrontendInteractionModule _frontendInteractionModule;
// private JsonFrontendSerialisationModule _frontendSerialisationModule;
// private ISerialisationModule _serialisationModule;
// private IExecuteModule _executeModule;
// bool isTestNotFinished = true;
//
// [SetUp]
// public void Setup()
// {
// _interactionModule = new StreamBasedInteractionModule();
//
// _serialisationModule = new JsonSerialisationModule(_interactionModule, new MockMethodRepository());
//
// _executeModule = new MockExecModule();
// _serialisationModule.SetExecuteModule(_executeModule);
//
// _frontendInteractionModule = new StreamBasedFrontendInteractionModule();
// _frontendSerialisationModule = new JsonFrontendSerialisationModule(_frontendInteractionModule);
//
// Task.Run(() =>
// {
// TcpListener listener = new TcpListener(IPAddress.Loopback, 4567);
// listener.Start();
//
// var stream = listener.AcceptTcpClient().GetStream();
//
// Console.WriteLine("Client connected");
//
// _interactionModule.RegisterSourse(stream);
//
// while (isTestNotFinished) ;
// });
// }
//
// [Test]
// public void StreamingTest()
// {
// var tcpClient = new TcpClient();
// tcpClient.Connect(IPAddress.Loopback, 4567);
// _frontendInteractionModule.ServerStream = tcpClient.GetStream();
//
// var req = new DefaultCallRequest { CommandId = 1, ObjectId = -1 };
// _frontendSerialisationModule.PostCallRequest(req);
// var res = ((JsonElement)_frontendSerialisationModule
// .GetNextCommandExecution<FinalCommandExecution>(req.CallRequestId).GetAwaiter().GetResult().Result!)
// .Deserialize<MockResult>();
// isTestNotFinished = false;
// Assert.That(res.A == "wqer" && res.B == 5);
// }
//
// [Test]
// public void RemoteObjectTest()
// {
// }
// }
+154 -154
View File
@@ -1,154 +1,154 @@
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Text.Json;
using mROA.Example;
using mROA.Implementation;
using Newtonsoft.Json;
using JsonSerializer = System.Text.Json.JsonSerializer;
namespace mROA.Test;
public class Tests
{
private ProgramlyInteractionChanel _interactionModule;
private ISerialisationModule _serialisationModule;
private IExecuteModule _executeModule;
private IMethodRepository _methodRepository;
private IContextRepository _contextRepository;
private ITestController _testController;
[SetUp]
public void Setup()
{
_interactionModule = new ProgramlyInteractionChanel();
var repo = new MethodRepository();
repo.CollectForAssembly(Assembly.GetExecutingAssembly());
_methodRepository = repo;
var repo2 = new ContextRepository();
repo2.FillSingletons(Assembly.GetExecutingAssembly());
_contextRepository = repo2;
_serialisationModule = new JsonSerialisationModule(_interactionModule, _methodRepository);
_executeModule = new LaunchReadyExecutionModule(_methodRepository, _serialisationModule, _contextRepository);
TransmissionConfig.DefaultContextRepository = _contextRepository;
}
[Test]
public void CommandPipelineTest()
{
var sw = Stopwatch.StartNew();
_interactionModule.PassCommand(132, """
{
"RequestTypeId": 0,
"CommandId": 2
}
"""u8.ToArray());
Assert.Pass(_interactionModule.OutputBuffer.Last());
}
[Test]
public void CommandPipelineTestAsync()
{
var sw = Stopwatch.StartNew();
_interactionModule.PassCommand(132, """
{
"RequestTypeId": 0,
"CommandId": 3
}
"""u8.ToArray());
while (_interactionModule.OutputBuffer.Count != 2) ;
Assert.Pass(_interactionModule.OutputBuffer.Last());
}
[Test]
public void MethodRegistrationTest()
{
var repo = new MethodRepository();
repo.CollectForAssembly(Assembly.GetExecutingAssembly());
Assert.That(repo.GetMethods().ToList().Count == 8);
}
[Test]
public void ContextSupplyTest()
{
var repo = new ContextRepository();
repo.FillSingletons(Assembly.GetExecutingAssembly());
var singleObject = repo.GetSingleObject(typeof(ITestController)) as ITestController;
singleObject.B();
Assert.That(singleObject.B() == 6);
}
[Test]
public void TransmissionTest()
{
_interactionModule.PassCommand(132, """
{
"CommandId": 4
}
"""u8.ToArray());
var response =
JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
?.Result.ToString()
);
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 2, ObjectId = response.ContextId })));
var firstFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
.GetInt32();
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 4, ObjectId = response.ContextId })));
response =
JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
?.Result.ToString()
);
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 2, ObjectId = response.ContextId })));
_interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 2, ObjectId = response.ContextId })));
var secondFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
.GetInt32();
Assert.That(firstFull == 456789 && secondFull == 6);
}
[Test]
public void LinkedObjectsAndParametersTest()
{
_interactionModule.PassCommand(132, """
{
"CommandId": 6
}
"""u8.ToArray());
var response =
JsonSerializer.Deserialize<TransmittedSharedObject<ITestParameter>>(
JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
?.Result.ToString()
);
var x = response.ContextId;
_interactionModule.PassCommand(132,Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(new DefaultCallRequest
{
CommandId = 5,
Parameter = new TestParameter
{
A = 10,
LinkedObject = new TransmittedSharedObject<ITestParameter> { ContextId = x }
}
})));
var finalResponse = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result").GetInt32();
Assert.That(finalResponse, Is.EqualTo(20));
}
}
// using System.Diagnostics;
// using System.Reflection;
// using System.Text;
// using System.Text.Json;
// using mROA.Example;
// using mROA.Implementation;
// using Newtonsoft.Json;
// using JsonSerializer = System.Text.Json.JsonSerializer;
//
// namespace mROA.Test;
//
// public class Tests
// {
// private ProgramlyInteractionChanel _interactionModule;
// private ISerialisationModule _serialisationModule;
// private IExecuteModule _executeModule;
// private IMethodRepository _methodRepository;
// private IContextRepository _contextRepository;
//
// private ITestController _testController;
//
// [SetUp]
// public void Setup()
// {
// _interactionModule = new ProgramlyInteractionChanel();
// var repo = new MethodRepository();
// repo.CollectForAssembly(Assembly.GetExecutingAssembly());
// _methodRepository = repo;
// var repo2 = new ContextRepository();
// repo2.FillSingletons(Assembly.GetExecutingAssembly());
// _contextRepository = repo2;
// _serialisationModule = new JsonSerialisationModule(_interactionModule, _methodRepository);
//
// _executeModule = new LaunchReadyExecutionModule(_methodRepository, _serialisationModule, _contextRepository);
// TransmissionConfig.DefaultContextRepository = _contextRepository;
// }
//
// [Test]
// public void CommandPipelineTest()
// {
// var sw = Stopwatch.StartNew();
//
// _interactionModule.PassCommand(132, """
// {
// "RequestTypeId": 0,
// "CommandId": 2
// }
// """u8.ToArray());
// Assert.Pass(_interactionModule.OutputBuffer.Last());
// }
//
// [Test]
// public void CommandPipelineTestAsync()
// {
// var sw = Stopwatch.StartNew();
// _interactionModule.PassCommand(132, """
// {
// "RequestTypeId": 0,
// "CommandId": 3
// }
// """u8.ToArray());
// while (_interactionModule.OutputBuffer.Count != 2) ;
//
// Assert.Pass(_interactionModule.OutputBuffer.Last());
// }
//
// [Test]
// public void MethodRegistrationTest()
// {
// var repo = new MethodRepository();
// repo.CollectForAssembly(Assembly.GetExecutingAssembly());
// Assert.That(repo.GetMethods().ToList().Count == 8);
// }
//
// [Test]
// public void ContextSupplyTest()
// {
// var repo = new ContextRepository();
// repo.FillSingletons(Assembly.GetExecutingAssembly());
// var singleObject = repo.GetSingleObject(typeof(ITestController)) as ITestController;
// singleObject.B();
// Assert.That(singleObject.B() == 6);
// }
//
// [Test]
// public void TransmissionTest()
// {
// _interactionModule.PassCommand(132, """
// {
// "CommandId": 4
// }
// """u8.ToArray());
// var response =
// JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
// JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
// ?.Result.ToString()
// );
//
// _interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
// JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 2, ObjectId = response.ContextId })));
//
// var firstFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
// .GetInt32();
//
// _interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
// JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 4, ObjectId = response.ContextId })));
//
// response =
// JsonSerializer.Deserialize<TransmittedSharedObject<IContextRepository>>(
// JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
// ?.Result.ToString()
// );
//
// _interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
// JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 2, ObjectId = response.ContextId })));
// _interactionModule.PassCommand(132, Encoding.UTF8.GetBytes(
// JsonSerializer.Serialize(new DefaultCallRequest { CommandId = 2, ObjectId = response.ContextId })));
//
// var secondFull = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result")
// .GetInt32();
//
// Assert.That(firstFull == 456789 && secondFull == 6);
// }
//
// [Test]
// public void LinkedObjectsAndParametersTest()
// {
// _interactionModule.PassCommand(132, """
// {
// "CommandId": 6
// }
// """u8.ToArray());
// var response =
// JsonSerializer.Deserialize<TransmittedSharedObject<ITestParameter>>(
// JsonSerializer.Deserialize<FinalCommandExecution>(_interactionModule.OutputBuffer.Last())
// ?.Result.ToString()
// );
// var x = response.ContextId;
// _interactionModule.PassCommand(132,Encoding.UTF8.GetBytes(
// JsonSerializer.Serialize(new DefaultCallRequest
// {
// CommandId = 5,
// Parameter = new TestParameter
// {
// A = 10,
// LinkedObject = new TransmittedSharedObject<ITestParameter> { ContextId = x }
// }
// })));
//
// var finalResponse = JsonDocument.Parse(_interactionModule.OutputBuffer.Last()).RootElement.GetProperty("Result").GetInt32();
//
// Assert.That(finalResponse, Is.EqualTo(20));
// }
// }
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ad2ef8e4b754b4cb2c5d3dbaa5c24f15201dd0f9")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+fd1eda26618b8cebe94eaa0e27ce5e97353d2d09")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2fac34a1ceac82d71c748b1421917d8fc2a60fa7")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+fd1eda26618b8cebe94eaa0e27ce5e97353d2d09")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
+3 -3
View File
@@ -5,12 +5,12 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Mikhail\.nuget\packages\" />
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
@@ -21,6 +21,6 @@
<Import Project="$(NuGetPackageRoot)microsoft.net.test.sdk\17.12.0\build\netcoreapp3.1\Microsoft.NET.Test.Sdk.props" Condition="Exists('$(NuGetPackageRoot)microsoft.net.test.sdk\17.12.0\build\netcoreapp3.1\Microsoft.NET.Test.Sdk.props')" />
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgNUnit_Analyzers Condition=" '$(PkgNUnit_Analyzers)' == '' ">C:\Users\Mikhail\.nuget\packages\nunit.analyzers\4.6.0</PkgNUnit_Analyzers>
<PkgNUnit_Analyzers Condition=" '$(PkgNUnit_Analyzers)' == '' ">C:\Users\Mimm\.nuget\packages\nunit.analyzers\4.6.0</PkgNUnit_Analyzers>
</PropertyGroup>
</Project>
+3 -2
View File
@@ -1,8 +1,9 @@
using mROA.Implementation;
using mROA.Abstract;
using mROA.Implementation;
namespace mROA;
public interface IContextRepository
public interface IContextRepository : IInjectableModule
{
int ResisterObject(object o);
void ClearObject(int id);
+2 -1
View File
@@ -2,5 +2,6 @@ namespace mROA.Abstract;
public interface IInjectableModule
{
public void Inject<T>(T dependency);
void Inject<T>(T dependency);
void Bake();
}
+1 -2
View File
@@ -4,10 +4,9 @@ namespace mROA;
public interface IInteractionModule : IInjectableModule
{
void SetMessageHandler(Action<int, byte[]> handler);
void SendTo(int clientId, byte[] message);
void RegisterSourse(Stream stream);
public interface IFrontendInteractionModule
public interface IFrontendInteractionModule : IInjectableModule
{
public Task<byte[]> ReceiveMessage();
public void PostMessage(byte[] message);
+2 -1
View File
@@ -1,8 +1,9 @@
using System.Reflection;
using mROA.Abstract;
namespace mROA;
public interface IMethodRepository
public interface IMethodRepository : IInjectableModule
{
MethodInfo GetMethod(int id);
int RegisterMethod(MethodInfo method);
+1 -1
View File
@@ -7,7 +7,7 @@ public interface ISerialisationModule : IInjectableModule
{
void HandleIncomingRequest(int clientId, byte[] command);
void PostResponse(ICommandExecution call);
public interface IFrontendSerialisationModule
public interface IFrontendSerialisationModule : IInjectableModule
{
Task<T> GetNextCommandExecution<T>(Guid requestId) where T : ICommandExecution;
Task<FinalCommandExecution<T>> GetFinalCommandExecution<T>(Guid requestId);
@@ -9,13 +9,6 @@ public class JsonSerialisationModule : ISerialisationModule
private IInteractionModule _dataSource;
private IExecuteModule _executeModule;
private IMethodRepository _methodRepository;
// public JsonSerialisationModule(IInteractionModule dataSource, IMethodRepository methodRepository)
// {
// _dataSource = dataSource;
// _methodRepository = methodRepository;
// _dataSource.SetMessageHandler(HandleIncomingRequest);
// }
public void HandleIncomingRequest(int clientId, byte[] command)
{
@@ -55,4 +48,8 @@ public class JsonSerialisationModule : ISerialisationModule
if (dependency is IMethodRepository methodRepository)
_methodRepository = methodRepository;
}
public void Bake()
{
}
}
@@ -12,11 +12,6 @@ public class StreamBasedInteractionModule : IInteractionModule
ListenTo((id, stream), _handler);
}
public void SetMessageHandler(Action<int, byte[]> handler)
{
_handler = handler;
}
public void SendTo(int clientId, byte[] message)
{
if (!_streams.TryGetValue(clientId, out var stream))
@@ -51,6 +46,13 @@ public class StreamBasedInteractionModule : IInteractionModule
public void Inject<T>(T dependency)
{
throw new NotImplementedException();
if (dependency is ISerialisationModule serialisationModule)
{
_handler = serialisationModule.HandleIncomingRequest;
}
}
public void Bake()
{
}
}
+7
View File
@@ -85,4 +85,11 @@ public class ContextRepository : IContextRepository
Array.Copy(_storage, nextStorage, _storage.Length);
return _storage.Length;
}
public void Inject<T>(T dependency)
{
}
public void Bake()
{
}
}
@@ -1,47 +1,59 @@
using System.Collections.Frozen;
namespace mROA.Implementation;
public class FrontendContextRepository(Dictionary<Type, Type> remoteTypes, ISerialisationModule.IFrontendSerialisationModule serialisationModule) : IContextRepository
{
private FrozenDictionary<Type, Type> _remoteTypes = remoteTypes.ToFrozenDictionary();
public int ResisterObject(object o)
{
throw new NotSupportedException();
}
public void ClearObject(int id)
{
throw new NotSupportedException();
}
public object GetObject(int id)
{
throw new NotSupportedException();
}
public T GetObject<T>(int id)
{
if (_remoteTypes.TryGetValue(typeof(T), out var remoteType))
{
var remote = (T)Activator.CreateInstance(remoteType, id, serialisationModule)!;
return remote;
}
throw new NotSupportedException();
}
public object GetSingleObject(Type type)
{
return Activator.CreateInstance(remoteTypes[type], -1, serialisationModule)!;
}
public int GetObjectIndex(object o)
{
if (o is IRemoteObject remote)
{
return remote.Id;
}
throw new NotSupportedException();
}
}
// using System.Collections.Frozen;
//
// namespace mROA.Implementation;
//
// public class FrontendContextRepository(
// Dictionary<Type, Type> remoteTypes,
// ISerialisationModule.IFrontendSerialisationModule serialisationModule) : IContextRepository
// {
// private FrozenDictionary<Type, Type> _remoteTypes = remoteTypes.ToFrozenDictionary();
//
// public int ResisterObject(object o)
// {
// throw new NotSupportedException();
// }
//
// public void ClearObject(int id)
// {
// throw new NotSupportedException();
// }
//
// public object GetObject(int id)
// {
// throw new NotSupportedException();
// }
//
// public T GetObject<T>(int id)
// {
// if (_remoteTypes.TryGetValue(typeof(T), out var remoteType))
// {
// var remote = (T)Activator.CreateInstance(remoteType, id, serialisationModule)!;
// return remote;
// }
//
// throw new NotSupportedException();
// }
//
// public object GetSingleObject(Type type)
// {
// return Activator.CreateInstance(remoteTypes[type], -1, serialisationModule)!;
// }
//
// public int GetObjectIndex(object o)
// {
// if (o is IRemoteObject remote)
// {
// return remote.Id;
// }
//
// throw new NotSupportedException();
// }
//
// public void Inject<T>(T dependency)
// {
// }
//
// public void Bake()
// {
// }
// }
@@ -3,30 +3,34 @@ using System.Text.Json;
namespace mROA.Implementation;
public class JsonFrontendSerialisationModule(IInteractionModule.IFrontendInteractionModule interactionModule)
public class JsonFrontendSerialisationModule
: ISerialisationModule.IFrontendSerialisationModule
{
private IInteractionModule.IFrontendInteractionModule _interactionModule;
public async Task<T> GetNextCommandExecution<T>(Guid requestId) where T : ICommandExecution
{
var receiveMessage = await interactionModule.ReceiveMessage();
var receiveMessage = await _interactionModule.ReceiveMessage();
var parsed = JsonSerializer.Deserialize<T>(receiveMessage);
while (parsed.CallRequestId != requestId)
{
receiveMessage = await interactionModule.ReceiveMessage();
receiveMessage = await _interactionModule.ReceiveMessage();
parsed = JsonSerializer.Deserialize<T>(receiveMessage);
}
return parsed;
}
public async Task<FinalCommandExecution<T>> GetFinalCommandExecution<T>(Guid requestId)
{
var receiveMessage = await interactionModule.ReceiveMessage();
var receiveMessage = await _interactionModule.ReceiveMessage();
var parsed = JsonSerializer.Deserialize<FinalCommandExecution<T>>(receiveMessage);
while (parsed.CallRequestId != requestId)
{
receiveMessage = await interactionModule.ReceiveMessage();
receiveMessage = await _interactionModule.ReceiveMessage();
parsed = JsonSerializer.Deserialize<FinalCommandExecution<T>>(receiveMessage);
}
parsed.Result = parsed.Result! is JsonElement e ? e.Deserialize<T>() : (T)parsed.Result!;
return parsed;
}
@@ -34,6 +38,16 @@ public class JsonFrontendSerialisationModule(IInteractionModule.IFrontendInterac
public void PostCallRequest(ICallRequest callRequest)
{
var post = JsonSerializer.Serialize(callRequest, callRequest.GetType());
interactionModule.PostMessage(Encoding.UTF8.GetBytes(post));
_interactionModule.PostMessage(Encoding.UTF8.GetBytes(post));
}
public void Inject<T>(T dependency)
{
if (dependency is IInteractionModule.IFrontendInteractionModule interactionModule)
_interactionModule = interactionModule;
}
public void Bake()
{
}
}
@@ -23,4 +23,11 @@ public class StreamBasedFrontendInteractionModule : IInteractionModule.IFrontend
ServerStream.Write(BitConverter.GetBytes((ushort)message.Length), 0, sizeof(ushort));
ServerStream.Write(message, 0, message.Length);
}
public void Inject<T>(T dependency)
{
}
public void Bake()
{
}
}
@@ -17,7 +17,11 @@ public class LaunchReadyExecutionModule : IExecuteModule
if (dependency is IContextRepository contextRepo)
_contextRepo = contextRepo;
}
public void Bake()
{
}
public ICommandExecution Execute(ICallRequest command)
{
var currentCommand = _methodRepo.GetMethod(command.CommandId);
+7
View File
@@ -34,4 +34,11 @@ public class MethodRepository : IMethodRepository
RegisterMethod(method);
}
}
public void Inject<T>(T dependency)
{
}
public void Bake()
{
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ad2ef8e4b754b4cb2c5d3dbaa5c24f15201dd0f9")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+fd1eda26618b8cebe94eaa0e27ce5e97353d2d09")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -8,7 +8,7 @@ build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = mROA
build_property.ProjectDir = C:\Users\Mikhail\Projects\VisualStudioProjects\mROA\mROA\
build_property.ProjectDir = C:\Users\Mimm\Projects\VisualStudioProjects\mROA\mROA\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.EffectiveAnalysisLevelStyle = 9.0
+2 -2
View File
@@ -5,12 +5,12 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Mikhail\.nuget\packages\" />
<SourceRoot Include="C:\Users\Mimm\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>