Skip to content
DataMiner DoJo

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages
Search in posts
Search in pages
Log in
Menu
  • Blog
  • Questions
  • Learning
    • E-learning Courses
    • Open Classroom Training
    • Certification
      • DataMiner Fundamentals
      • DataMiner Configurator
      • DataMiner Automation
      • Scripts & Connectors Developer: HTTP Basics
      • Scripts & Connectors Developer: SNMP Basics
      • Visual Overview – Level 1
      • Verify a certificate
    • Tutorials
    • Video Library
    • Books We Like
    • >> Go to DataMiner Docs
  • Expert Center
    • Solutions & Use Cases
      • Solutions
      • Use Case Library
    • Markets & Industries
      • Media production
      • Government & defense
      • Content distribution
      • Service providers
      • Partners
      • OSS/BSS
    • DataMiner Insights
      • Security
      • Integration Studio
      • System Architecture
      • DataMiner Releases & Updates
      • DataMiner Apps
    • Agile
      • Agile Webspace
      • Everything Agile
        • The Agile Manifesto
        • Best Practices
        • Retro Recipes
      • Methodologies
        • The Scrum Framework
        • Kanban
        • Extreme Programming
      • Roles
        • The Product Owner
        • The Agile Coach
        • The Quality & UX Coach (QX)
    • DataMiner DevOps Professional Program
  • Downloads
  • More
    • Feature Suggestions
    • Climb the leaderboard!
    • Swag Shop
    • Contact
      • General Inquiries
      • DataMiner DevOps Support
      • Commercial Requests
    • Global Feedback Survey
  • PARTNERS
    • All Partners
    • Technology Partners
    • Strategic Partner Program
    • Deal Registration
  • >> Go to dataminer.services

Unit Testing Mocking for Protocols

Solved1.78K views7th July 2023protocol development Unit Tests
11
Rebecca Kelsall [DevOps Advocate]670 8th March 2023 0 Comments

Has anyone had success in building a Mocking Library to mimic the SLProtocol/SLProtocolExt for unit testing for protocol development?

Marieke Goethals [SLC] [DevOps Catalyst] Selected answer as best 7th July 2023

3 Answers

  • Active
  • Voted
  • Newest
  • Oldest
9
Ana Pinho [SLC] [DevOps Advocate]1.32K Posted 8th March 2023 1 Comment

Hi Rebecca!

We have some videos explaining how to do unit tests and in this part we go through the process of mocking the SLProtocol.

You can watch the video or read a bit of the explanation.
Mainly, I use the Moq library as the example here:

[TestMethod()]
public void Rewrite_PathWithItemsToAbbreviate_ReturnsAbbreviatedPath()
{
    // Arrange
    PathRewriter pathRewriter = new PathRewriter();
    string path = @"Visios\Customers\Skyline\Protocols\Test";
    string expected = @"V\C\Skyline\P\Test";

    var fakeSlProtocol = new Mock<SLProtocol>();

    // Act
    string result = pathRewriter.Rewrite(fakeSlProtocol.Object, path);

    // Assert
    Assert.AreEqual(expected, result);
}

Hope that helps!

Marieke Goethals [SLC] [DevOps Catalyst] Selected answer as best 7th July 2023
Rebecca Kelsall [DevOps Advocate] commented 10th March 2023

Thank you for your answer. We are already using Moq similar to the above but, we were hoping somebody had already built an independant helper library that mocked things like the NotifyProtocol to help with validating table calls that are represented as object arrays which can be hard to write mocks for.

7
Laurens Moutton [SLC] [DevOps Enabler]8.68K Posted 8th March 2023 2 Comments

Hi,

Since DataMiner 10.0, the SLProtocol/SLProtocolExt classes have been changed into interfaces. That makes it possible to mock it for unit testing.

If a Nuget with a mocking framework, like Moq, is being used then it's possible to write unit tests and mock the SLProtocol calls.

For example:

Mock<SLProtocol> protocolMock = new Mock<SLProtocol>();
protocolMock.Setup(p => p.DataMinerID).Returns(dmaId);
protocolMock.Setup(p => p.ElementID).Returns(elementId);
protocolMock.Setup(p => p.ElementName).Returns("Dummy Element Name");
protocolMock.Setup(p => p.GetParameter(testParameterId1)).Returns("DummyValue1");
protocolMock.Setup(p => p.GetParameter(testParameterId2)).Returns("DummyValue2");

// Using the mocked SLProtocol
SLProtocol protocol = protocolMock.Object;
string param1 = Convert.ToString(protocol.GetParameter(testParameterId1));
protocol.SetParameter(testSetParameterId, "DummyValue")

// Asserting
Assert.AreEqual(param1, "DummyValue1");
protocolMock.Verify(p => p.SetParameter(testSetParameterId, It.Is<string>(incomingValue => VerifyIncomingValue(incomingValue)))); // verify that a setparameter has been called with the expected value

// For larger collections, FluentAssertions can be used to have a more easy verification when asserting.

Regards,

Laurens Moutton [SLC] [DevOps Enabler] Posted new comment 10th March 2023
Reza Biglari [DevOps Advocate] commented 10th March 2023

Thanks Laurens, we’ve been able to mock both setting and getting of standalone parameters and tables however, for tables it has proven to be quite an involved process as we’ve been required to mock the NotifyProtocol method which depends on an object array representation of tables that is hard to mimic in code. Are there any wrappers or libraries built from Skyline which can aid in mocking table manipulation behaviour in a more object-oriented manner?

Alternatively, should we be using other methods to read and write into tables?

Laurens Moutton [SLC] [DevOps Enabler] commented 10th March 2023

Hi,
Mocking the NotifyProtocol calls is indeed a bit more work.
If the unit test can run against a more recent DataMiner version (10.1.1 (RN 27995) onwards, then some notifies can be mocked with the alternative method. For example NotifyProtocol(149 /*NT_ADD_ROW*/) has an alternative method protocol.AddRow(). NotifyProtocol(220 /*NT_FILL_ARRAY_WITH_COLUMN*/) has as alternative protocol.FillArrayWithColumn(). These methods used to be extension methods that could not be mocked, but since 10.1.1 this has become part of the SLProtocol interface.
Of course some of these methods and the NotifyProtocol method still could rely on object arrays as input or return value and then one still needs to create these objects.
For example to simulate the response of a NotifyProtocol 321, it could then look like this:
object[] tableInputCols = new object[4];
tableInputCols[0] = pkCol;
tableInputCols[1] = inputLabelCol;
tableInputCols[2] = stateCol;
tableInputCols[3] = lockedCol;
protocolMock.Setup(p => p.NotifyProtocol(321, inputsTableParameterId, It.Is(ui => ui.Length == 4 && ui[0] == 0 && ui[1] == 1 && ui[2] == 2 && ui[3] == 3))).Returns(tableInputCols);

If the assertion of the executed calls is a bit larger, then custom created methods could be created to make it more readable.
protocolMock.Verify(p => p.NotifyProtocol(220, It.Is(tablePids => VerifyTablePidInfo(tablePids, expectedTablePids)), It.Is(tableContent => VerifyTableInfo(tableContent, expectedTableContent))));
The methods VerifyTablePidInfo() and VerifyTableInfo() then validate the content of the objects that were used to execute that notify 220 and return a boolean if it was as expected or not.

An alternative for the verification of the content of received object arrays is to use the FluentAssertions NuGet package in the unit test. Then it’s possible to execute something like expectedDataObjectArray.Should().BeEquivalentTo(receivedDataObjectArray); , if the content is not equal then the unit test will fail.

As far as I’m aware there are no wrappers or libraries yet available to help mock or validate the table manipulation calls.

2
Avatar photo
Jan Staelens [SLC] [DevOps Advocate]889 Posted 27th April 2023 1 Comment

There does exist a framework that allows writing unit tests and mocking SLProtocol in a way that you just provide what your expected end-result should be. It doesn't care if you used setcolumn, setrow, fillarray and will just check if your 'final table data' matches what you expect.

This was being worked on by several devops engineers when they encountered the same difficulties after we introduced unit testing for QActions.

I believe this will likely help. You'll lose some details on how you perform sets, which can also be important! But it does help a lot to avoid regression when refactoring and writing tests quicker.

That library is currently a NuGet that's still internal and in beta. But it's going through the last few steps to make it public.

I can check with our PO and the developers of the library to give it a little push.

Example

```csharp
[TestMethod()] [DeploymentItem(@"TestFiles\response_content.xml")] public void TestCallback()
{
// Arrange
var protocolModel = new ProtocolModelExt(path);
var protocolMock = new SLProtocolMock(protocolModel);

string responseContent = File.ReadAllText("response_content.xml");
var response = new HttpResponse("uri", "HTTP1.1 200 OK", responseContent);
var callback = new GetMediaUsageByUtRangeResponse();

// Act
callback.Run(protocolMock.Object, response);

// Assert
mock.Assert()
.Table(Parameter.Mediainstancesusagetable.tablePid)
.Column(Parameter.Mediainstancesusagetable.Pid.mediainstancesusagetableid_2401)
.Should()
.Contain("test");
}
```

another example:

```csharp
# AddRow
// Create a new Protocol Model
var protocolModel = new ProtocolModelExt(path);

// Create a new SLProtocolMock and pass it the Protocol Model
var mock = new SLProtocolMock(protocolModel);

// The row to be set
object[] row1 = new object[] { "one.1", "two.1", "three.1", "four.1", "five.1" };
object[] row2 = new object[] { "one.2", "two.2", "three.2", "four.2", "five.2" };

// Make a call using the mock object, here in this example we are adding two rows, row1 and row2, to the table with ID 900
mock.Object.AddRow(900, row1);
mock.Object.AddRow(900, row2);

// Define the expected column values
string[] expectedColumn1 = { "one.1", "one.2" };
string[] expectedColumn2 = { "two.1", "two.2" };
string[] expectedColumn3 = { "three.1", "three.2" };
string[] expectedColumn4 = { "four.1", "four.2" };
string[] expectedColumn5 = { "five.1", "five.2" };

// Invoke the mock assert method, select the ID of the Table and the column to check, and then compare it with the expected column
mock.Assert().Table(900).Column(901).Should().Equal(expectedColumn1);
mock.Assert().Table(900).Column(901).Should().Equal(expectedColumn2);
mock.Assert().Table(900).Column(901).Should().Equal(expectedColumn3);
mock.Assert().Table(900).Column(901).Should().Equal(expectedColumn4);
mock.Assert().Table(900).Column(901).Should().Equal(expectedColumn5);
```

Thijs Vanovenacker [SLC] [DevOps Advocate] Posted new comment 13th June 2024
Thijs Vanovenacker [SLC] [DevOps Advocate] commented 13th June 2024

Hi, Any update on this? Where can community users find the NuGet? Thank you

Please login to be able to comment or post an answer.

My DevOps rank

DevOps Members get more insights on their profile page.

My user earnings

0 Dojo credits

Spend your credits in our swag shop.

0 Reputation points

Boost your reputation, climb the leaderboard.

Promo banner DataMiner DevOps Professiona Program
DataMiner Integration Studio (DIS)
Empower Katas

Recent questions

DOM Definition relations returned in Definition query 0 Answers | 0 Votes
Alarm Dashboard PDF/CSV Export 1 Answer | 0 Votes
Is the Microsoft SharePoint Connector Still Usable 0 Answers | 0 Votes

Question Tags

adl2099 (115) alarm (62) Alarm Console (82) alarms (100) alarm template (83) Automation (223) automation scipt (111) Automation script (167) backup (71) Cassandra (180) Connector (108) Correlation (68) Cube (150) Dashboard (194) Dashboards (188) database (83) DataMiner Cube (57) DIS (81) DMS (71) DOM (140) driver (65) DVE (55) Elastic (83) Elasticsearch (115) elements (80) Failover (104) GQI (159) HTTP (76) IDP (74) LCA (152) low code app (166) low code apps (93) lowcodeapps (75) MySQL (53) protocol (203) QAction (83) security (88) services (51) SNMP (86) SRM (337) table (54) trending (87) upgrade (62) Visio (539) Visual Overview (345)
Privacy Policy • Terms & Conditions • Contact

© 2025 Skyline Communications. All rights reserved.

DOJO Q&A widget

Can't find what you need?

? Explore the Q&A DataMiner Docs

[ Placeholder content for popup link ] WordPress Download Manager - Best Download Management Plugin