コード例 #1
0
        public BaseMethodTest()
        {
            Random = new Random();

            AdvisoryDelayHandler = new AdvisoryDelayHandler(new DateTimeWrap());

            if (new ConfigurationManagerWrap().GetAppSettingValue<bool>("useEmulator"))
                Service = new RandomOrgApiEmulator();
        }
コード例 #2
0
        public void Process_WhenAdvisoryIsZero_ShouldReturnTrue()
        {
            // Arrange

            // Act
            AdvisoryDelayHandler target = new AdvisoryDelayHandler();
            var actual = target.Process(null);

            // Assert
            actual.Should().Be.True();
        }
コード例 #3
0
        /// <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
            );
        }
コード例 #4
0
        /// <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
            );
        }
コード例 #5
0
        /// <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 UuidBasicMethod(AdvisoryDelayHandler advisoryDelayHandler, IRandomService randomService = null)
        {
            RandomService = randomService ?? new RandomOrgApiService();
            RequestBuilder = new JsonRequestBuilder(new UuidJsonRequestBuilder());

            BeforeRequestCommandFactory = new BeforeRequestCommandFactory(advisoryDelayHandler);

            // We need to keep this separate so we can retrieve the list of values that are returned from to the caller
            ResponseParser = new JsonResponseParserFactory(new UuidResponseParser());

            ResponseHandlerFactory = new ResponseHandlerFactory(
                new ErrorHandlerThrowException(new ErrorParser()),
                advisoryDelayHandler,
                new VerifyIdResponseHandler(),
                ResponseParser
            );
        }
コード例 #6
0
        public void Process_WhenWaitTimeLessThanZero_ShouldReturnQuickly()
        {
            // Arrange
            const long delayTime = 100;
            Mock<IDateTime> dateTimeMock = new Mock<IDateTime>();
            dateTimeMock.Setup(m => m.UtcNow).Returns(new DateTimeWrap(2016, 2, 1));
            long advisoryDelay = new DateTime(2016, 2, 1).Ticks + delayTime;

            // Act
            AdvisoryDelayHandler target = new AdvisoryDelayHandler(dateTimeMock.Object);
            UnitTestHelper.SetPrivateProperty(target, "_advisoryDelay", advisoryDelay);

            Stopwatch stopwatch = Stopwatch.StartNew();
            var actual = target.Process(null);
            stopwatch.Stop();

            // Assert
            actual.Should().Be.True();
            stopwatch.ElapsedMilliseconds.Should().Be.LessThan(delayTime);
        }
コード例 #7
0
 public static void CleanupTest()
 {
     _random = null;
     _advisoryDelayHandler = null;
 }
コード例 #8
0
 public static void InitializeTests(TestContext context)
 {
     _random = new Random();
     _advisoryDelayHandler = new AdvisoryDelayHandler(new DateTimeWrap());
 }
コード例 #9
0
 public void CleanupTest()
 {
     _advisoryDelayHandler = null;
 }
コード例 #10
0
 public void InitializeTest()
 {
     _advisoryDelayHandler = new AdvisoryDelayHandler(new DateTimeWrap());
 }
コード例 #11
0
        public void Handle_WhenAdvisoryDelayGreaterThanZero_ShouldSetAdvisoryDelay()
        {
            // Arrange
            const int delayTime = 100;
            Mock<IDateTime> dateTimeMock = new Mock<IDateTime>();
            dateTimeMock.Setup(m => m.UtcNow).Returns(new DateTimeWrap(2016, 2, 1));
            long expected = new DateTime(2016, 2, 1).Ticks + delayTime;

            var input =
                new JObject(
                    new JProperty(
                        "result",
                        new JObject(
                            new JProperty(JsonRpcConstants.ADVISORY_DELAY_PARAMETER_NAME, delayTime)
                         )
                     )
                 );

            // Act
            AdvisoryDelayHandler target = new AdvisoryDelayHandler(dateTimeMock.Object);
            var actual = target.Handle(null, input.ToString());
            long advisoryDelay = UnitTestHelper.GetPrivateProperty<long>(target, "_advisoryDelay");

            // Assert
            actual.Should().Be.True();
            advisoryDelay.Should().Equal(expected);
        }
コード例 #12
0
        public void CanHandlee_WhenVerifySignatureMethodType_ShouldReturnFalse()
        {
            // Arrange
            Mock<IParameters> parametersMock = new Mock<IParameters>();
            parametersMock.Setup(m => m.MethodType).Returns(MethodType.VerifySignature);

            // Act
            AdvisoryDelayHandler target = new AdvisoryDelayHandler();
            var actual = target.CanHandle(parametersMock.Object);

            // Assert
            actual.Should().Be.False();
        }
コード例 #13
0
        public void CanHandle_WhenStringMethodType_ShouldReturnTrue()
        {
            // Arrange
            Mock<IParameters> parametersMock = new Mock<IParameters>();
            parametersMock.Setup(m => m.MethodType).Returns(MethodType.String);

            // Act
            AdvisoryDelayHandler target = new AdvisoryDelayHandler();
            var actual = target.CanHandle(parametersMock.Object);

            // Assert
            actual.Should().Be.True();
        }
コード例 #14
0
        public void CanProcess_WhenCalled_ShouldAlwaysReturnTrue()
        {
            // Arrange

            // Act
            AdvisoryDelayHandler target = new AdvisoryDelayHandler(null);
            var actual = target.CanProcess(null);

            // Assert
            actual.Should().Be.True();
        }
コード例 #15
0
        public void Handle_WhenAdvisoryDelayIsZero_ShouldSetAdvisoryDelayToZero()
        {
            // Arrange
            const long expected = 0;

            var input = new JObject(
                new JProperty("result",
                    new JObject(
                        new JProperty(JsonRpcConstants.ADVISORY_DELAY_PARAMETER_NAME, expected)
                        ))
                );

            // Act
            AdvisoryDelayHandler target = new AdvisoryDelayHandler();
            var actual = target.Handle(null, input.ToString());
            long advisoryDelay = UnitTestHelper.GetPrivateProperty<long>(target, "_advisoryDelay");

            // Assert
            actual.Should().Be.True();
            advisoryDelay.Should().Equal(expected);
        }