简体   繁体   English

我们如何使用 C# 编程语言为 MIP(Microsoft Information Protection)编写单元测试?

[英]How do we write unit tests for MIP (Microsoft Information Protection) using C# programming language?

Requirement : If any file has protection(Sensitivity label) then we are throwing an error message.要求:如果任何文件具有保护(敏感度标签),那么我们将抛出一条错误消息。

Before we go and do our actual implementation, I want to achieve this using TDD approach.在我们 go 并进行实际实施之前,我想使用 TDD 方法来实现这一点。

Please let me clarify whether the below steps can we achieve using unit test with C#?请让我澄清一下我们是否可以使用 C# 进行单元测试来实现以下步骤?

  1. Is it possible to write unit test on this MIP?是否可以在此 MIP 上编写单元测试? If yes,如是,
    • Through program, I want to read the file(.pdf or office app files) and apply sensitivity label before using MIP Code.通过程序,我想在使用 MIP 代码之前读取文件(.pdf 或 office 应用程序文件)并应用灵敏度 label。
    • Once it reaches MIP code snippet,this should detect this file and it has protection.一旦它到达 MIP 代码片段,这应该会检测到该文件并且它具有保护。
    • If it is protected then should throw an error message or else skip the execution.如果它受到保护,则应抛出错误消息或跳过执行。

I never used the MIP SDK, but you are in the wrong path if you want to test the file information using MIP.我没用过MIP SDK,但是如果你想用MIP测试文件信息,你走错了路径。

1. Use double testing 1.使用双重测试

First you will have to use Double Testing (a stub or a fake) to be sure that you business rules are applied correctly in your algorithme (throwing the exception if the sensitivity level is bad for example)首先,您必须使用双重测试(存根或伪造)来确保您的业务规则在您的算法中正确应用(例如,如果敏感度级别不好则抛出异常)

The stub or the fake will allow you to control the sensitivity level return, It's also means that you will have to wrap the "MIP Library" inside a class or using IOC存根或假货将允许您控制灵敏度级别返回,这也意味着您必须将“MIP 库”包装在 class 中或使用 IOC

2. Use integration testing 2.使用集成测试

When you will have a first working scenario with you unit test, you will be able to make the same with Integration Testing.当您的单元测试有了第一个工作场景时,您将能够通过集成测试实现同样的效果。 You will add to your project the material to have a "production environnement" adding files with differents sentivities to your test project您将向您的项目添加具有“生产环境”的材料,将具有不同敏感度的文件添加到您的测试项目

Conclusion结论

Of course, I know that my answer is not a working solution but your needs is not simple and cannot be set in a stackoverflow post.当然,我知道我的答案不是一个可行的解决方案,但您的需求并不简单,无法在 stackoverflow 帖子中设置。 You will need to investigate about double testing & integration testing before making any development if you want to have reliable unit tests.如果您想进行可靠的单元测试,则需要在进行任何开发之前调查双重测试和集成测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM