AnsweredAssumed Answered

Are There Any Code Examples Available of Mocking Up the PI SDK for .NET Unit Tests?

Question asked by pmmcann on Jun 24, 2016
Latest reply on Nov 7, 2017 by ernstamort

I am curious if anyone has any, or is currently using means of mocking PI access for unit testing.

 

My need stems from writing an application that I need to have relatively high code coverage. The application is using the PI SDK, and is a .NET Web API which allows iPads to remotely input data into our PI system and relational SQL databases. Some of the functionality can be relatively easily unit tested because it is SQL only entities that I have implemented as POCOs, which then have IQueryable repositories used to handle DAL logic, and then using dependency injection and Inversion of Control to pass things cleanly to the controller. This makes those controllers that respond to simple things like GET requests for a asset in the SQL database relatively painless, and testing the logic in those methods or the underlying data store relatively painless.

 

My problem now stems from some of my fatter controllers that currently have PI SDK code executing business based logic along side transactions for my entity framework database context data access. Unit testing these has so far evaded me.

 

One such method takes in an object with several CLR properties. These are then used to determine what actions should be taken, and if necessary, find a the correct Pi Unit, and create a PI Unit Batch as well as update records in several tables.

 

How might I effectively unit test where I need to write data to the PI system without modifying the underlying PI Data?

 

Actions like updating a tag and checking if the resulting performance equation activated properly with an expected result seem reasonable candidates for this kind of application test, do they not?

 

I would appreciate any help anyone has on this. Also, unfortunately I am still limited to the PI-SDK, and cannot use the AF-SDK, Event Frames or PI Web API.

 

Thanks!

Outcomes