Skip to content

Commit

Permalink
Repeated testing
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-andersson-at-westermo committed Jun 11, 2024
1 parent 2fa2910 commit 2c64be0
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions YangSourceTests/RpcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class RpcTests(ITestOutputHelper outputHelper)
{
private class TestChannel : IChannel, IAsyncDisposable
{
public string? LastXML => Encoding.UTF8.GetString(((MemoryStream)WriteStream).GetBuffer()).Replace("\0","");
public string? LastWritten => Encoding.UTF8.GetString(((MemoryStream)ReadStream).GetBuffer()).Replace("\0","");
public string? LastXML => Encoding.UTF8.GetString(((MemoryStream)WriteStream).GetBuffer()).Replace("\0", "");
public string? LastWritten => Encoding.UTF8.GetString(((MemoryStream)ReadStream).GetBuffer()).Replace("\0", "");
private ExampleYangServer server = new();

public async Task Send()
Expand Down Expand Up @@ -46,8 +46,7 @@ public async ValueTask DisposeAsync()
public async Task RpcSend()
{
await using var channel = new TestChannel();
var id = Random.Shared.Next();
var reply = await Ietf.Connection.Oriented.Oam.YangNode.Traceroute(channel, id,
var reply = await Ietf.Connection.Oriented.Oam.YangNode.Traceroute(channel, 1,
new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput
{
MaNameStringValue = new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.MaNameString(),
Expand Down Expand Up @@ -75,12 +74,35 @@ public async Task RpcSend()
using var ms = new MemoryStream();
await using var writer = XmlWriter.Create(ms, SerializationHelper.GetStandardWriterSettings());
await writer.WriteStartElementAsync(null, "rpc-reply", "urn:ietf:params:xml:ns:netconf:base:1.0");
await writer.WriteAttributeStringAsync(null, "message-id", null, id.ToString());
await writer.WriteAttributeStringAsync(null, "message-id", null, 1.ToString());
await reply.WriteXMLAsync(writer);
await writer.WriteEndElementAsync();
await writer.FlushAsync();
var replyString = Encoding.UTF8.GetString(ms.GetBuffer());
Assert.Equal(channel.LastWritten, replyString);

reply = await Ietf.Connection.Oriented.Oam.YangNode.Traceroute(channel, 2,
new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput
{
MaNameStringValue = new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.MaNameString(),
MdNameStringValue = new Ietf.Connection.Oriented.Oam.YangNode.TracerouteInput.MdNameString(),
Ttl = 2,
Count = 4,
Interval = 6,
CosId = 2,
DestinationMep = new()
{
MepAddress = new()
{
IpAddressCaseValue = new()
{
IpAddress = new(new YangNode.Ipv4Address("1.2.3.4"))
}
}
},
SourceMepValue = new(),
CommandSubType = Ietf.Connection.Oriented.Oam.YangNode.CommandSubTypeIdentity.Proactive
});
// Assert.Equal(
// reply.Response![0].Mip!.MipAddress!.IpAddressCaseValue!.IpAddress!.Ipv4AddressValue!
// .WrittenValue,
Expand Down Expand Up @@ -135,7 +157,6 @@ public async Task RpcSend()
[Fact]
public async Task ActionSend()
{

await using var channel = new TestChannel();
await root.AlarmList!.Alarm![0].SetOperatorState(channel, Random.Shared.Next(), root,
new Ietf.Alarms.YangNode.AlarmsContainer.AlarmListContainer.AlarmEntry.SetOperatorStateInput
Expand All @@ -152,14 +173,14 @@ public async Task ActionSend()
[Fact]
public async Task NotificationSend()
{

await using var channel = new TestChannel();
await root.AlarmList!.Alarm![1].OperatorActionInstance!.Send(channel, root);

outputHelper.WriteLine(channel.LastXML);
outputHelper.WriteLine("_____________________________________");
outputHelper.WriteLine(channel.LastWritten);
}

[Fact]
public async Task TopLevelNotificationSend()
{
Expand All @@ -174,12 +195,12 @@ public async Task TopLevelNotificationSend()
outputHelper.WriteLine("_____________________________________");
outputHelper.WriteLine(channel.LastWritten);
}

[Fact]
public async Task ExceptionGeneratingTest()
{

await using var channel = new TestChannel();
var notification = new Ietf.Alarms.YangNode.AlarmNotification
var notification = new Ietf.Alarms.YangNode.AlarmNotification
{
Resource = "a",
Time = "2015-01-23T12:23:34Z",
Expand All @@ -197,11 +218,11 @@ public async Task ExceptionGeneratingTest()
[Fact]
public async Task ExceptionThrowingTest()
{

await using var channel = new TestChannel();
try
{
var result = await Ietf.Subscribed.Notifications.YangNode.EstablishSubscription(channel, Random.Shared.Next(),
var result = await Ietf.Subscribed.Notifications.YangNode.EstablishSubscription(channel,
Random.Shared.Next(),
new Ietf.Subscribed.Notifications.YangNode.EstablishSubscriptionInput
{
Target = new Ietf.Subscribed.Notifications.YangNode.EstablishSubscriptionInput.TargetChoice
Expand Down Expand Up @@ -241,6 +262,7 @@ public async Task ExceptionThrowingTest()
outputHelper.WriteLine(channel.LastWritten);
throw;
}

Assert.Fail();
}
}

0 comments on commit 2c64be0

Please sign in to comment.