public void Handle_WhenAuthenticityIsTrue_ShouldReturnTrue() { // Arrange var verifiedResponse = new JObject( new JProperty("jsonrpc", "2.0"), new JProperty("result", new JObject( new JProperty("authenticity", true)) ), new JProperty("id", 1234) ); Mock<IRandomService> serviceMock = new Mock<IRandomService>(); serviceMock.Setup(m => m.SendRequest(It.IsAny<string>())).Returns(verifiedResponse.ToString); var input = new JObject( new JProperty("jsonrpc", "2.0"), new JProperty("result", new JObject( new JProperty("random", new JObject())) ) ); // Act VerifySignatureHandler target = new VerifySignatureHandler(serviceMock.Object); var actual = target.Handle(null, input.ToString()); // Assert actual.Should().Be.True(); }
/// <summary> /// Constructor /// </summary> /// <param name="advisoryDelayHandler"> /// Class which handles the apprioriate delay before the request is called. /// It is required that this class be passed into the method because the same instance of the <see cref="AdvisoryDelayHandler"/> must be passed in on every request. /// </param> /// <param name="randomService"><see cref="IRandomService"/> to use to get random values. Defaults to <see cref="RandomOrgApiService"/></param> public StringSignedMethod(AdvisoryDelayHandler advisoryDelayHandler, IRandomService randomService = null) : base(advisoryDelayHandler, randomService) { var verifySignatureHandler = new VerifySignatureHandler(RandomService); BeforeRequestCommandFactory = new BeforeRequestCommandFactory(advisoryDelayHandler, verifySignatureHandler); ResponseHandlerFactory = new ResponseHandlerFactory( new ErrorHandlerThrowException(new ErrorParser()), verifySignatureHandler, advisoryDelayHandler, new VerifyIdResponseHandler(), ResponseParser ); }
/// <summary> /// Constructor /// </summary> /// <param name="advisoryDelayHandler"> /// Class which handles the apprioriate delay before the request is called. /// It is required that this class be passed into the method because the same instance of the <see cref="AdvisoryDelayHandler"/> must be passed in on every request. /// </param> /// <param name="randomService"><see cref="IRandomService"/> to use to get random values. Defaults to <see cref="RandomOrgApiService"/></param> public BlobSignedMethod(AdvisoryDelayHandler advisoryDelayHandler, IRandomService randomService = null) : base(advisoryDelayHandler, randomService) { // We just need to setup the Verification Signature class, other than that everything else is the same. var verifySignatureHandler = new VerifySignatureHandler(RandomService); BeforeRequestCommandFactory = new BeforeRequestCommandFactory(advisoryDelayHandler, verifySignatureHandler); ResponseHandlerFactory = new ResponseHandlerFactory( new ErrorHandlerThrowException(new ErrorParser()), verifySignatureHandler, advisoryDelayHandler, new VerifyIdResponseHandler(), ResponseParser ); }
public void Handle_WhenResultNodeNotFoundInJson_ShouldThrowException() { // Arrange string verifiedResponse = string.Empty; Mock<IRandomService> serviceMock = new Mock<IRandomService>(); serviceMock.Setup(m => m.SendRequest(It.IsAny<string>())).Returns(verifiedResponse); var input = new JObject( new JProperty("jsonrpc", "2.0"), new JProperty("notResultNode") ); // Act VerifySignatureHandler target = new VerifySignatureHandler(); target.Handle(null, input.ToString()); // Assert }
public void CanProcess_WhenCalled_ShouldAlwaysReturnTrue() { // Arrange Mock<IParameters> parametersMock = new Mock<IParameters>(); parametersMock.Setup(p => p.VerifyOriginator).Returns(true); // Act VerifySignatureHandler target = new VerifySignatureHandler(); var actual = target.CanProcess(parametersMock.Object); // Assert actual.Should().Be.True(); }
public void CanHandle_WhenVerifyOriginatorIsFalse_ShouldReturnFalse() { // Arrange Mock<IParameters> parametersMock = new Mock<IParameters>(); parametersMock.Setup(p => p.VerifyOriginator).Returns(false); // Act VerifySignatureHandler target = new VerifySignatureHandler(); var actual = target.CanHandle(parametersMock.Object); // Assert actual.Should().Be.False(); }
public void Process_WhenCalled_ShouldSetVerifyOriginatorToTrueAndReturnTrue() { // Arrange Mock<IParameters> parametersMock = new Mock<IParameters>(); parametersMock.SetupProperty(p => p.VerifyOriginator, false); // Act VerifySignatureHandler target = new VerifySignatureHandler(); var actual = target.Process(parametersMock.Object); // Assert parametersMock.Object.VerifyOriginator.Should().Be.True(); actual.Should().Be.True(); }