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.79K 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
7
Laurens Moutton [SLC] [DevOps Enabler]8.73K 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.

You are viewing 1 out of 3 answers, click here to view all answers.
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

Web Applications exception in Cube due to invalid certificate 0 Answers | 0 Votes
Redundancy Groups and Alarming – Duplicate Alarms 0 Answers | 0 Votes
Correlation Engine: “Test rule” doesn’t result in a hit, despite functional rule 1 Answer | 3 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 (109) Correlation (69) Correlation rule (52) Cube (151) Dashboard (194) Dashboards (188) database (83) DataMiner Cube (57) DIS (81) DMS (71) DOM (140) driver (65) DVE (56) 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) 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