public void ShouldNotThrowExceptionWhenKeyPairIsValid(CipherType cipherType) { var command = new VerifyKeyPairCommand { PrivateKey = Mock.Of <IAsymmetricKey>(k => k.CipherType == cipherType), PublicKey = Mock.Of <IAsymmetricKey>(k => k.CipherType == cipherType) }; Assert.DoesNotThrow(() => { commandHandler.Execute(command); }); }
public void ShouldThrowExceptionWhenKeyTypeIsNotValid(CipherType cipherType) { var command = new VerifyKeyPairCommand { PrivateKey = Mock.Of <IAsymmetricKey>(k => k.CipherType == cipherType), PublicKey = Mock.Of <IAsymmetricKey>(k => k.CipherType == cipherType) }; Assert.Throws <InvalidOperationException>(() => { commandHandler.Execute(command); }); }
public void ShouldThrowExceptionWhenPublicKeyAndPrivateKeyAreNotOfSameType() { var command = new VerifyKeyPairCommand { PrivateKey = Mock.Of <IAsymmetricKey>(k => k.CipherType == CipherType.Rsa), PublicKey = Mock.Of <IAsymmetricKey>(k => k.CipherType == CipherType.Dsa) }; Assert.Throws <InvalidOperationException>(() => { decorator.Execute(command); }); }
public void ShouldExecuteDecoratedCommandHandler() { var command = new VerifyKeyPairCommand { PrivateKey = Mock.Of <IAsymmetricKey>(k => k.CipherType == CipherType.Dsa), PublicKey = Mock.Of <IAsymmetricKey>(k => k.CipherType == CipherType.Dsa) }; Assert.DoesNotThrow(() => { decorator.Execute(command); }); commandHandler.Verify(c => c.Execute(command)); }
public void ShouldThrowExceptionWhenKeyPairIsNotValid(CipherType cipherType) { var command = new VerifyKeyPairCommand { PrivateKey = Mock.Of <IAsymmetricKey>(k => k.CipherType == cipherType), PublicKey = Mock.Of <IAsymmetricKey>(k => k.CipherType == cipherType) }; rsaKeyProvider.Setup(kp => kp.VerifyKeyPair(It.IsAny <IAsymmetricKeyPair>())) .Returns(false); dsaKeyProvider.Setup(kp => kp.VerifyKeyPair(It.IsAny <IAsymmetricKeyPair>())) .Returns(false); ecKeyProvider.Setup(kp => kp.VerifyKeyPair(It.IsAny <IAsymmetricKeyPair>())) .Returns(false); Assert.Throws <CryptographicException>(() => { commandHandler.Execute(command); }); }