2017-03-17 2 views
0

私の上司は、私たちのASP.NETアプリケーション用のこのライセンスコントローラを単体テストすることを望んでいます。新しい公開鍵と秘密鍵を呼び出すたびにそれを作成するコントローラをユニットテストする方法は?

私が問題になっている問題は、通常 アプリケーションに行って、そのライセンスが現在のkeygeneratorとkeypair(portable = license libraryから)のインスタンスに結びついているライセンスを作成することです。LicenseServiceという静的クラスがあります。 keygeneratorとkeypairが呼び出されたときに呼び出されます。したがって、ライセンスを生成してから、鍵生成者と鍵ペアの同じインスタンスにある検証ページに移動します。したがって、検証は完了します。ライセンスが別のインスタンスで作成された場合、これを検証することはできません(異なる公開鍵/秘密鍵)。

有効なライセンスと無効なライセンスをテストしているので、事前にライセンスを作成しておく必要がありますが、各ライセンスは一意のインスタンスに関連付けられているため、鍵ペア)は無効になります(ライセンス自体が無効であっても)。ここ

は、(それが問題のあまりにも多くはずのように、ローカル・イム・テスト)私は、キー

  1. ハードコードを持っているいくつかのアイデアですが、私はこの

  2. とセキュリティ上の欠陥があると感じます何とか(これは非常に難しいと思われると、それにアプローチする方法としては不明IM)複数の鍵ペアを有しながら発電機の一つの特定のインスタンスを使用するコントローラと、コントローラのすべての後続のインスタンスを強制

これはところで

http://dev.nauck-it.de/projects/portable-licensing/wiki/GettingStarted

+0

これはhttp://stackoverflow.com/questions/5503702/patterns-or-practices-for-unit-testing-methods-that-c​​all-a-static-methodの複製のようです – Fran

答えて

0

コードがいいだろうライブラリですが、それなし。

ライセンスジェネレータクラスを変更することができない場合は、このライセンス・ジェネレータは

その後、
1. don't make you LicenseService static. 
    2. have this LicenseService inherit from an interface. define the interface with whatever the public methods of the current 
service are. 
    3. pass the interface to the constructor of your controller 
    4. use IoC to pass an instance of the class that implements the interface or create a new constructor that instantiates the class 
for the constructor 

あなたのクラスである場合。

1. define the interface with whatever the public methods of the current 
service are. 
    2. create a wrapper class that passes through to the static methods 
    3. pass the interface to the constructor of your controller 
    4. use IoC to pass an instance of the class that implements the interface or create a new constructor that instantiates the class 
for the constructor 

いくつか一緒に投げコード

public interface IGenerateLicenseKeys 
{ 
    SomeType GenerateKeys(); 
} 

public class LicenseKeyGenerator : IGenerateLicenseKeys 
{ 
    public SomeType GenerateKeys() 
    { 
     //Generate your keys or pass through to the other component with the static method. 
     throw new NotImplementedException();       
    } 
} 

あなたがLicenseKeyGeneratorをモックと嘲笑の方法の中からお好きな値を返す、ということしたら。

関連する問題