Exemplo n.º 1
0
        /// <summary>
        /// Retrieve the usage information in an asynchronous manners
        /// </summary>
        /// <returns>Usage information</returns>
        public async Task<UsageResponseInfo> GetUsageAsync()
        {
            IParameters requestParameters = UsageParameters.Create();
            MethodCallBroker broker = new MethodCallBroker(null, _randomService, null, _responseHandlerFactory);
            await broker.GenerateAsync(requestParameters);

            return _responseParser.ResponseInfo as UsageResponseInfo;
        }
        /// <summary>
        /// Retrieves a list of random blob values in an asynchronous manners
        /// </summary>
        /// <param name="numberOfItemsToReturn">How many random decimal fractions you need. Must be between 1 and 10,000.</param>
        /// <returns>List of random blob values</returns>
        public virtual async Task<IEnumerable<Guid>> GenerateUuidsAsync(int numberOfItemsToReturn)
        {
            IParameters requestParameters = UuidParameters.Create(numberOfItemsToReturn);
            MethodCallBroker broker = new MethodCallBroker(RequestBuilder, RandomService, BeforeRequestCommandFactory, ResponseHandlerFactory);
            await broker.GenerateAsync(requestParameters);

            return (ResponseParser.ResponseInfo as DataResponseInfo<Guid>)?.Data;
        }
        public async Task GenerateAsync_WhenCalledWithNoResponseHandlers_ShouldReturnTrue()
        {
            // Arrange
            const string request = "SomeRequest";

            Mock<IParameters> parameters = new Mock<IParameters>();
            Mock<IRequestBuilder> requestBuilderMock = new Mock<IRequestBuilder>();
            requestBuilderMock.Setup(m => m.Build(parameters.Object)).Returns(request);

            Mock<IRandomService> randomServiceMock = new Mock<IRandomService>();
            randomServiceMock.Setup(m => m.SendRequestAsync(request)).ReturnsAsync(string.Empty);

            // Act
            MethodCallBroker target = new MethodCallBroker(requestBuilderMock.Object, randomServiceMock.Object);
            var actual = await target.GenerateAsync(parameters.Object);

            // Assert
            actual.Should().Be.True();
        }
        public async Task GenerateAsync_WhenCalledWithResponseHandlerThatReturnsFalse_ShouldReturnFalse()
        {

            // Arrange
            const string request = "SomeRequest";

            Mock<IParameters> parameters = new Mock<IParameters>();
            Mock<IRequestBuilder> requestBuilderMock = new Mock<IRequestBuilder>();
            requestBuilderMock.Setup(m => m.Build(parameters.Object)).Returns(request);

            Mock<IRandomService> randomServiceMock = new Mock<IRandomService>();
            randomServiceMock.Setup(m => m.SendRequest(request));

            Mock<IBeforeRequestCommandFactory> requestCommandMock = new Mock<IBeforeRequestCommandFactory>();
            requestCommandMock.Setup(m => m.Execute(parameters.Object));

            Mock<IResponseHandler> responseHandlerMock = new Mock<IResponseHandler>();
            responseHandlerMock.Setup(m => m.CanHandle(parameters.Object)).Returns(true);
            responseHandlerMock.Setup(m => m.Handle(parameters.Object, It.IsAny<string>())).Returns(false);

            ResponseHandlerFactory responseHandlerFactory = new ResponseHandlerFactory(responseHandlerMock.Object);

            // Act
            MethodCallBroker target = new MethodCallBroker(requestBuilderMock.Object, randomServiceMock.Object, requestCommandMock.Object, responseHandlerFactory);
            var actual = await target.GenerateAsync(parameters.Object);

            // Assert
            actual.Should().Be.False();
        }
        /// <summary>
        /// Retrieves a list of random blob values in an asynchronous manners
        /// </summary>
        /// <param name="numberOfItemsToReturn">How many random string values you need. Must be between 1 and 10,000.</param>
        /// <param name="length">The length of each string. Must be within the [1,20] range. All strings will be of the same length</param>
        /// <param name="charactersAllowed">A string that contains the set of characters that are allowed to occur in the random strings. The maximum number of characters is 80.</param>
        /// <param name="allowDuplicates">True if duplicate values are allowed in the random values, default to <c>true</c></param>
        /// <returns>List of random blob values</returns>
        public virtual async Task<IEnumerable<string>> GenerateStringsAsync(int numberOfItemsToReturn, int length, string charactersAllowed, bool allowDuplicates = true)
        {
            IParameters requestParameters = StringParameters.Create(numberOfItemsToReturn, length, charactersAllowed, allowDuplicates);
            MethodCallBroker broker = new MethodCallBroker(RequestBuilder, RandomService, BeforeRequestCommandFactory, ResponseHandlerFactory);
            await broker.GenerateAsync(requestParameters);

            return (ResponseParser.ResponseInfo as DataResponseInfo<string>)?.Data;
        }
        /// <summary>
        /// Retrieves a list of random blob values in an asynchronous manners
        /// </summary>
        /// <param name="numberOfItemsToReturn">How many random integer values you need. Must be between 1 and 10,000.</param>
        /// <param name="minimumValue">The lower boundary for the range from which the random numbers will be picked. Must be between -1,000,000,000 and 1,000,000,000.</param>
        /// <param name="maximumValue">The upper boundary for the range from which the random numbers will be picked. Must be between -1,000,000,000a and 1,000,000,000.</param>
        /// <param name="allowDuplicates">True if duplicate values are allowed in the random values, default to <c>true</c></param>
        /// <returns>List of random blob values</returns>
        public virtual async Task<IEnumerable<int>> GenerateIntegersAsync(int numberOfItemsToReturn, int minimumValue, int maximumValue, bool allowDuplicates = false)
        {
            IParameters requestParameters = IntegerParameters.Create(numberOfItemsToReturn, minimumValue, maximumValue, allowDuplicates);
            MethodCallBroker broker = new MethodCallBroker(RequestBuilder, null, BeforeRequestCommandFactory, ResponseHandlerFactory);
            await broker.GenerateAsync(requestParameters);

            return (ResponseParser.ResponseInfo as DataResponseInfo<int>)?.Data;
        }
        /// <summary>
        /// Retrieves a list of random blob values in an asynchronous manners
        /// </summary>
        /// <param name="numberOfItemsToReturn">How many random decimal fractions you need. Must be between 1 and 10,000.</param>
        /// <param name="numberOfDecimalPlaces">The number of decimal places to use. Must be between 1 and 20</param>
        /// <param name="allowDuplicates">True if duplicate values are allowed in the random values, default to <c>true</c></param>
        /// <returns>List of random blob values</returns>
        public virtual async Task<IEnumerable<decimal>> GenerateDecimalsFractionsAsync(int numberOfItemsToReturn, int numberOfDecimalPlaces, bool allowDuplicates = false)
        {
            IParameters requestParameters = DecimalParameters.Create(numberOfItemsToReturn, numberOfDecimalPlaces, allowDuplicates);
            MethodCallBroker broker = new MethodCallBroker(RequestBuilder, RandomService, BeforeRequestCommandFactory, ResponseHandlerFactory);
            await broker.GenerateAsync(requestParameters);

            return (ResponseParser.ResponseInfo as DataResponseInfo<decimal>)?.Data;
        }
        /// <summary>
        /// Retrieves a list of random blob values in an asynchronous manners
        /// </summary>
        /// <param name="numberOfItemsToReturn">How many random blob values you need. Must be between 1 and 100.</param>
        /// <param name="size">The size of each blob, measured in bits. Must be between 1 and 1048576 and must be divisible by 8.</param>
        /// <param name="format">Specifies the format in which the blobs will be returned, default value is Base64</param>
        /// <returns>List of random blob values</returns>
        public virtual async Task<IEnumerable<string>> GenerateBlobsAsync(int numberOfItemsToReturn, int size, BlobFormat format = BlobFormat.Base64)
        {
            IParameters requestParameters = BlobParameters.Create(numberOfItemsToReturn, size, format);
            MethodCallBroker broker = new MethodCallBroker(RequestBuilder, RandomService, BeforeRequestCommandFactory, ResponseHandlerFactory);
            await broker.GenerateAsync(requestParameters);

            return (ResponseParser.ResponseInfo as DataResponseInfo<string>)?.Data;
        }
        /// <summary>
        /// Retrieves a list of random blob values in an asynchronous manners
        /// </summary>
        /// <param name="numberOfItemsToReturn">How many random guassian values you need. Must be between 1 and 10,000.</param>
        /// <param name="mean">The distribution's mean. Must be between -1,000,000 and 1,000,000.</param>
        /// <param name="standardDeviation">The distribution's standard deviation. Must be between -1,000,000 and 1,000,000</param>
        /// <param name="significantDigits">The number of significant digits to use. Must be between 2 and 20.</param>
        /// <returns>List of random blob values</returns>
        public virtual async Task<IEnumerable<decimal>> GenerateGuassiansAsync(int numberOfItemsToReturn, int mean, int standardDeviation, int significantDigits)
        {
            IParameters requestParameters = GuassianParameters.Create(numberOfItemsToReturn, mean, standardDeviation, significantDigits);
            MethodCallBroker broker = new MethodCallBroker(RequestBuilder, RandomService, BeforeRequestCommandFactory, ResponseHandlerFactory);
            await broker.GenerateAsync(requestParameters);

            return (ResponseParser.ResponseInfo as DataResponseInfo<decimal>)?.Data;
        }