-
Notifications
You must be signed in to change notification settings - Fork 1k
/
JsonPersistentTestRunStoreSpec.cs
93 lines (76 loc) · 3.99 KB
/
JsonPersistentTestRunStoreSpec.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//-----------------------------------------------------------------------
// <copyright file="JsonPersistentTestRunStoreSpec.cs" company="Akka.NET Project">
// Copyright (C) 2009-2018 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2018 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------
using System.IO;
using System.Linq;
using Akka.Actor;
using Akka.MultiNodeTestRunner.Shared.Persistence;
using Akka.MultiNodeTestRunner.Shared.Reporting;
using Akka.MultiNodeTestRunner.Shared.Sinks;
using Akka.TestKit;
using Xunit;
namespace Akka.MultiNodeTestRunner.Shared.Tests.Persistence
{
public class JsonPersistentTestRunStoreSpec : AkkaSpec
{
[Fact]
public void Should_save_TestRunTree_as_JSON()
{
var testRunStore = new JsonPersistentTestRunStore();
var testRunCoordinator = Sys.ActorOf(Props.Create<TestRunCoordinator>());
var nodeIndexes = Enumerable.Range(1, 4).ToArray();
var nodeTests = NodeMessageHelpers.BuildNodeTests(nodeIndexes);
var beginSpec = new BeginNewSpec(nodeTests.First().TypeName, nodeTests.First().MethodName, nodeTests);
//begin a new spec
testRunCoordinator.Tell(beginSpec);
// create some messages for each node, the test runner, and some result messages
// just like a real MultiNodeSpec
var allMessages = NodeMessageHelpers.GenerateMessageSequence(nodeIndexes, 300);
var runnerMessages = NodeMessageHelpers.GenerateTestRunnerMessageSequence(20);
allMessages.UnionWith(runnerMessages);
foreach (var message in allMessages)
testRunCoordinator.Tell(message);
//end the spec
testRunCoordinator.Tell(new EndTestRun(), TestActor);
var testRunData = ExpectMsg<TestRunTree>();
//save the test run
var file = Path.GetTempFileName();
testRunStore.SaveTestRun(file, testRunData).ShouldBeTrue("Should have been able to save test run");
}
[Fact]
public void Should_load_saved_JSON_TestRunTree()
{
var testRunStore = new JsonPersistentTestRunStore();
var testRunCoordinator = Sys.ActorOf(Props.Create<TestRunCoordinator>());
var nodeIndexes = Enumerable.Range(1, 4).ToArray();
var nodeTests = NodeMessageHelpers.BuildNodeTests(nodeIndexes);
var beginSpec = new BeginNewSpec(nodeTests.First().TypeName, nodeTests.First().MethodName, nodeTests);
//begin a new spec
testRunCoordinator.Tell(beginSpec);
// create some messages for each node, the test runner, and some result messages
// just like a real MultiNodeSpec
var allMessages = NodeMessageHelpers.GenerateMessageSequence(nodeIndexes, 300);
var runnerMessages = NodeMessageHelpers.GenerateTestRunnerMessageSequence(20);
var successMessages = NodeMessageHelpers.GenerateResultMessage(nodeIndexes, true);
var messageFragments = NodeMessageHelpers.GenerateMessageFragmentSequence(nodeIndexes, 100);
allMessages.UnionWith(runnerMessages);
allMessages.UnionWith(successMessages);
allMessages.UnionWith(messageFragments);
foreach (var message in allMessages)
testRunCoordinator.Tell(message);
//end the spec
testRunCoordinator.Tell(new EndTestRun(), TestActor);
var testRunData = ExpectMsg<TestRunTree>();
//save the test run
var file = Path.GetTempFileName();
testRunStore.SaveTestRun(file, testRunData).ShouldBeTrue("Should have been able to save test run");
//retrieve the test run from file
var retrievedFile = testRunStore.FetchTestRun(file);
Assert.NotNull(retrievedFile);
Assert.True(testRunData.Equals(retrievedFile));
}
}
}