Skip to content

Commit

Permalink
Merge pull request #114 from SyndARn/TestingSimpleActor
Browse files Browse the repository at this point in the history
Add test
  • Loading branch information
SyndARn committed Apr 27, 2020
2 parents 8511e72 + 897de62 commit 1e97aa0
Show file tree
Hide file tree
Showing 29 changed files with 16,674 additions and 16,502 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DynamicActor : DynamicObject, IActor
{
private class InternalDynamicActor : BaseActor
{
private dynamic fDynamic;
private readonly dynamic fDynamic;

public InternalDynamicActor(dynamic dyn) : base()
{
Expand All @@ -31,7 +31,7 @@ public void DoDynamic(Tuple<InvokeMemberBinder, object[]> msg)
}
}

private IActor fActor;
private readonly IActor fActor;
private readonly dynamic fDynamic;

public DynamicActor(dynamic dynamic)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using Actor.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Actor.TestApplication
{
public class TestLauncherActor : ActionActor
{
private Future<bool> future = new Future<bool>();
private readonly Future<bool> future = new Future<bool>();
public TestLauncherActor()
: base()
{
Expand Down
16 changes: 1 addition & 15 deletions ARnActorSolution/Application/ActorWeather/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
using Actor.Base;
using Actor.Server;
using Actor.Util;
using Actor.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ActorWeather
{
Expand Down
11 changes: 4 additions & 7 deletions ARnActorSolution/Application/Amoeba/Amoeba.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Actor.MonteCarlo;
using Actor.Base;
using System.Windows.Forms;

namespace Amoeba
{
public class ResultActor : BaseActor
{
private List<long> results = new List<long>();
private readonly List<long> _results = new List<long>();
public ResultActor()
{
Become(new Behavior<long>(ResultMessage));
Expand All @@ -20,13 +17,13 @@ public ResultActor()

private void ResultMessage(long s)
{
results.Add(s);
_results.Add(s);
}

private void FutureMessage(IActor aFuture)
{
long total = results.Count(r => r <= 0);
long qtt = results.Count();
long total = _results.Count(r => r <= 0);
long qtt = _results.Count();
aFuture.SendMessage(total, qtt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace BrokerDemoApplication
{
public class DemoWorker : WorkerActor<string>
{
CollectionActor<string> fMemLogger;
readonly CollectionActor<string> fMemLogger;
public DemoWorker(CollectionActor<string> memLogger) : base()
{
fMemLogger = memLogger;
Expand Down
9 changes: 3 additions & 6 deletions ARnActorSolution/TestActor/ActorBase/FutureTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Actor.Base;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestActor;
using System.Threading.Tasks;

namespace TestActor
namespace Actor.Base.Test
{
internal class FutureAsyncActorTest : BaseActor
{
Expand Down
22 changes: 10 additions & 12 deletions ARnActorSolution/TestActor/ActorBase/IActorExtensionTest.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Actor.Util;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Actor.Base;
using System.Collections.Generic;
using System.Linq;
using TestActor;

namespace TestActor
namespace Actor.Util.Test
{

class ExtensionTestActor : BaseActor
internal class ExtensionTestActor : BaseActor
{
private List<string> fList = new List<string>();
private readonly List<string> _list = new List<string>();
public ExtensionTestActor() : base()
{
Become(new Behavior<string>(s => fList.Add(s)));
AddBehavior(new Behavior<string,string>((s1,s2) => fList.Add(s2)));
AddBehavior(new Behavior<string, string,string>((s1, s2, s3) => fList.Add(s3)));
AddBehavior(new Behavior<string, string, string, string>((s1, s2, s3, s4) => fList.Add(s4)));
AddBehavior(new Behavior<IActor>(a => a.SendMessage(fList.AsEnumerable())));
Become(new Behavior<string>(s => _list.Add(s)));
AddBehavior(new Behavior<string,string>((s1,s2) => _list.Add(s2)));
AddBehavior(new Behavior<string, string,string>((s1, s2, s3) => _list.Add(s3)));
AddBehavior(new Behavior<string, string, string, string>((s1, s2, s3, s4) => _list.Add(s4)));
AddBehavior(new Behavior<IActor>(a => a.SendMessage(_list.AsEnumerable())));
}
}

Expand Down
8 changes: 3 additions & 5 deletions ARnActorSolution/TestActor/ActorServer/ShardDirectoryTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Actor.Base;
using System.Linq;
using Actor.Util;
using Actor.Server;
using TestActor;

namespace TestActor
namespace Actor.Server.Tests
{
[TestClass]
public class ShardDirectoryTest
Expand Down
6 changes: 2 additions & 4 deletions ARnActorSolution/TestActor/Behavior/BasicBehaviorsTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Actor.Base;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
using System.Collections.Generic;

namespace TestActor
namespace Actor.Base.Test
{
[TestClass]
public class BasicBehaviorsTest
Expand Down
2 changes: 1 addition & 1 deletion ARnActorSolution/TestActor/Broker/WorkerActorTestString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Actor.Server.Tests
{
class WorkerActorTestString : WorkerActor<string>
{
EnumerableActor<string> fActorReport;
readonly EnumerableActor<string> fActorReport;
public WorkerActorTestString(EnumerableActor<string> actor)
{
fActorReport = actor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public void EchoClient100Test()
{
EchoClientActor aClient = new EchoClientActor();
aClient.Connect("EchoServer");
aClient.SendMessage("client-" + i.ToString());
aClient.SendMessage($"client-{i}");
}
Task.Delay(10000).Wait();
},15000);
var mess = GlobalContext.MessageTracerService.CopyAllMessages();
Assert.IsTrue(mess.Count(t => t.StartsWith("client receive")) >= 1);
#pragma warning disable CA1827 // Do not use Count() or LongCount() when Any() can be used
Assert.IsTrue(mess.Count(t => t.StartsWith("client receive", StringComparison.InvariantCulture)) >= 1);
#pragma warning restore CA1827 // Do not use Count() or LongCount() when Any() can be used
}
}
}
4 changes: 2 additions & 2 deletions ARnActorSolution/TestActor/Collection/ActorQueueTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Actor.Util;
using TestActor;

namespace TestActor
namespace Actor.Util.Test
{
[TestClass]
public class ActorQueueTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void GetDirectoryTest()
[TestMethod()]
public void StatTest()
{
Assert.IsTrue(DirectoryActor.GetDirectory().Stat().StartsWith("Directory entries "));
Assert.IsTrue(DirectoryActor.GetDirectory().Stat().StartsWith("Directory entries ",System.StringComparison.InvariantCulture));
}

[TestMethod()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public void RegisterUnregisterTestV2()
HostDirectoryActor.Unregister(actor);
Task.Delay(5000).Wait();
var stat2 = HostDirectoryActor.GetInstance().GetEntries();
Assert.IsTrue(stat2.Count(t => t == actor.Tag.Key())== 0);
#pragma warning disable CA1827 // Do not use Count() or LongCount() when Any() can be used
Assert.IsTrue(stat2.Count(t => t == actor.Tag.Key())== 0); // don't touch
#pragma warning restore CA1827 // Do not use Count() or LongCount() when Any() can be used
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void TestDistributedDictionary()
var dic = new DistributedDictionaryActor<int, string>();
foreach(var i in Enumerable.Range(1,1000))
{
dic.AddKeyValue(i, i.ToString() + " Test");
dic.AddKeyValue(i, $"{i} Test");
}
// find key 3
var future = dic.GetKeyValue(3);
Expand Down
6 changes: 2 additions & 4 deletions ARnActorSolution/TestActor/Exception/CheckArgTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Actor.Base;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;

namespace TestActor
namespace Actor.Base.Test
{
[TestClass]
public class CheckArgTest
Expand Down
2 changes: 1 addition & 1 deletion ARnActorSolution/TestActor/MapReduce/MapReduceTesting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Go(string aFilename, IActor actor)
(a, d) =>
{
for (int i = 0; i < 10; i++)
a.SendMessage(d,i.ToString()+" "+i.ToString());
a.SendMessage(d,$"{i} {i}");
},
// map
(a, k, v) =>
Expand Down
2 changes: 1 addition & 1 deletion ARnActorSolution/TestActor/Report/badge_branchcoverage.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ARnActorSolution/TestActor/Report/badge_combined.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ARnActorSolution/TestActor/Report/badge_linecoverage.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions ARnActorSolution/TestActor/Service/StringParserActorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ namespace Actor.Service.Tests

class TestParserActor : BaseActor
{
List<string> fList = new List<string>();
private readonly List<string> _list = new List<string>();
public TestParserActor()
{
Become(new Behavior<IActor, string>((a, s) =>
{
fList.Add(s);
_list.Add(s);
}));
AddBehavior(new Behavior<IActor>(a =>
{
IEnumerable<string> enumerable = fList.AsEnumerable();
IEnumerable<string> enumerable = _list.AsEnumerable();
a.SendMessage(enumerable);
}
));
Expand Down
29 changes: 29 additions & 0 deletions ARnActorSolution/TestActor/SimpleActor/SimpleActorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestActor;

namespace Actor.Base.Test
{
[TestClass()]
public class SimpleActorTest
{
[TestMethod()]
public void SimpleAndReceiveTest()
{
TestLauncherActor.Test(() =>
{
List<string> list = new List<string>();
var bhv = new Behavior<IActor, string>((i, s1) => i.SendMessage(i,s1));
var simple = new SimpleActor(bhv);
var bhv2 = new Behavior<IActor, string>((i, s2) => list.Add(s2));
var receiver = new SimpleActor(bhv2);
simple.SendMessage(receiver,"Simple works");
Task.Delay(5000).Wait();
var s = list.FirstOrDefault();
Assert.AreEqual("Simple works", s);
});
}
}
}
2 changes: 2 additions & 0 deletions ARnActorSolution/TestActor/TestActor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.XML" />
Expand Down Expand Up @@ -172,6 +173,7 @@
<Compile Include="Serializer\NetDataContract\NetDataContractSerializeServiceTests.cs" />
<Compile Include="Service\RingActorTests.cs" />
<Compile Include="Service\StringParserActorTests.cs" />
<Compile Include="SimpleActor\SimpleActorTest.cs" />
<Compile Include="Trait\TraitTest.cs" />
<Compile Include="Composition\InjectionActorTest.cs" />
<Compile Include="Util\TextWriterActorTest.cs" />
Expand Down

0 comments on commit 1e97aa0

Please sign in to comment.