jeudi 3 mars 2016

Trying to obtain ServerCertificateValidation value for unit test

I have a method that I am trying to write a unit test for. I want to see that it returns true or false accordingly....a seemingly simple test that has me at a loss. See the note in the second code snippet to understand when the code gets run.

The code:

public void SetSSSPolicyFlag()
{
   if (_ignoreSSSPolicy)
   ServicePointManager.ServerCertificateValidationCallback +=
   (sender, certificate, chain, sslPolicyErrors) => true;
}

The test:

[TestMethod]
public void Ignore_SSPolicy_Test()
{
    //Arrange
    BaseController baseController = new BaseControllerBuilder()
                                    .WithSSSPolicy(true) //this executes the method above
                                    .Build();

   //Act
   var val = ServicePointManager.ServerCertificateValidationCallback;

   //Assert
   Assert.IsTrue(val.??);

}

Aucun commentaire:

Enregistrer un commentaire