Skip to content

Commit

Permalink
Updated README and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutierrez committed Jul 25, 2024
1 parent 0fe3cab commit 80976ee
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
37 changes: 37 additions & 0 deletions Nixie.Tests/Actors/FireAndForgetActorStruct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

namespace Nixie.Tests.Actors;

public sealed class FireAndForgetActorStruct : IActorStruct<int>
{
private readonly Dictionary<int, int> receivedMessages = new();

public FireAndForgetActorStruct(IActorContextStruct<FireAndForgetActorStruct, int> _)
{

}

public int GetMessages(int id)
{
if (receivedMessages.TryGetValue(id, out int number))
return number;

return 0;
}

public void IncrMessage(int id)
{
if (!receivedMessages.TryGetValue(id, out int value))
receivedMessages.Add(id, 1);
else
receivedMessages[id] = ++value;
}

public async Task Receive(int message)
{
await Task.CompletedTask;

//Console.WriteLine("hello");

IncrMessage(message);
}
}
46 changes: 46 additions & 0 deletions Nixie.Tests/TestSendMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,50 @@ public async Task TestSendMessageToSingleActorRef()

Assert.Equal(1, ((ReplyActorStruct)actor.Runner.Actor!).GetMessages(100));
}

[Fact]
public async Task TestSendMultipleMessageToSingleActorStruct()
{
using ActorSystem asx = new();

IActorRefStruct<ReplyActorStruct, int, int> actor = asx.SpawnStruct<ReplyActorStruct, int, int>();

actor.Send(100);
actor.Send(100);
actor.Send(100);

await asx.Wait();

Assert.Equal(3, ((ReplyActorStruct)actor.Runner.Actor!).GetMessages(100));
}

[Fact]
public async Task TestSendMessageToSingleActorNoResponseStruct()
{
using ActorSystem asx = new();

IActorRefStruct<FireAndForgetActorStruct, int> actor = asx.SpawnStruct<FireAndForgetActorStruct, int>();

actor.Send(100);

await asx.Wait();

Assert.Equal(1, ((FireAndForgetActorStruct)actor.Runner.Actor!).GetMessages(100));
}

[Fact]
public async Task TestSendMultipleMessageToSingleActorNoResponseStruct()
{
using ActorSystem asx = new();

IActorRefStruct<FireAndForgetActorStruct, int> actor = asx.SpawnStruct<FireAndForgetActorStruct, int>("TestSendMultipleMessageToSingleActorNoResponseStruct");

actor.Send(100);
actor.Send(100);
actor.Send(100);

await asx.Wait();

Assert.Equal(3, ((FireAndForgetActorStruct)actor.Runner.Actor!).GetMessages(100));
}
}
25 changes: 25 additions & 0 deletions Nixie/Nixie.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nixie", "Nixie.csproj", "{10FB054D-0B49-4734-967A-6F6BBE68837D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{10FB054D-0B49-4734-967A-6F6BBE68837D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10FB054D-0B49-4734-967A-6F6BBE68837D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10FB054D-0B49-4734-967A-6F6BBE68837D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10FB054D-0B49-4734-967A-6F6BBE68837D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DE891718-4FA7-4333-8F64-6D0133A9D013}
EndGlobalSection
EndGlobal
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ To install Nixie into your C#/.NET project, you can use the .NET CLI or the NuGe
#### Using .NET CLI

```shell
dotnet add package Nixie --version 0.0.8-alpha
dotnet add package Nixie --version 1.0.0
```

### Using NuGet Package Manager

Search for Nixie and install it from the NuGet package manager UI, or use the Package Manager Console:

```shell
Install-Package Nixie -Version 0.0.8-alpha
Install-Package Nixie -Version 1.0.0
```

## Usage
Expand Down

0 comments on commit 80976ee

Please sign in to comment.