-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/simplify-n-refactor' into simpli…
…fy-n-refactor
- Loading branch information
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Machine.Specifications; | ||
using Moq; | ||
using Serilog; | ||
using ISession = Opc.Ua.Client.ISession; | ||
|
||
namespace RaaLabs.Edge.Connectors.OPCUA.for_Reader.given; | ||
|
||
public class a_reader | ||
{ | ||
protected static Reader reader; | ||
protected static Mock<ISession> connection; | ||
protected static CancellationTokenSource cts; | ||
protected static List<NodeValue> handled_values; | ||
protected static Func<NodeValue, Task> handler; | ||
|
||
Establish context = () => | ||
{ | ||
connection = new(); | ||
reader = new(Mock.Of<ILogger>()); | ||
cts = new(); | ||
|
||
var values = handled_values = []; | ||
|
||
handler = _ => | ||
{ | ||
handled_values.Add(_); | ||
return Task.CompletedTask; | ||
}; | ||
}; | ||
|
||
Cleanup after = () => | ||
{ | ||
cts.Dispose(); | ||
}; | ||
} |
31 changes: 31 additions & 0 deletions
31
Specifications/for_Reader/when_reading_nodes_forever/and_datavalue_found.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Machine.Specifications; | ||
using Opc.Ua; | ||
|
||
namespace RaaLabs.Edge.Connectors.OPCUA.for_Reader.when_reading_nodes_forever; | ||
|
||
public class and_datavalue_found : given.a_reader | ||
{ | ||
static IEnumerable<(NodeId node, TimeSpan readInterval)> nodes; | ||
static Task forever_reading_task; | ||
|
||
Establish context = () => | ||
{ | ||
nodes = new[] | ||
{ | ||
(new NodeId(1), TimeSpan.FromSeconds(1)) | ||
}; | ||
connection | ||
.Setup(_ => _.ReadValueAsync(new NodeId(1), cts.Token)) | ||
.Returns(Task.FromResult(new DataValue(("reading value")))); | ||
}; | ||
|
||
Because of = () => | ||
{ | ||
forever_reading_task = reader.ReadNodesForever(connection.Object, nodes, handler, cts.Token); | ||
}; | ||
|
||
It should_have_read_the_values = () => handled_values.ShouldContainOnly(new NodeValue(new (1), new ("reading value"))); | ||
} |