/// <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; }
/// <summary> /// Retrieves a list of random blob values /// </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">Build of common character sets that are allowed to occur in the random strings</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 IEnumerable<string> GenerateStrings(int numberOfItemsToReturn, int length, CharactersAllowed charactersAllowed, bool allowDuplicates = true) { IParameters requestParameters = StringParameters.Create(numberOfItemsToReturn, length, charactersAllowed, allowDuplicates); IMethodCallBroker broker = new MethodCallBroker(RequestBuilder, RandomService, BeforeRequestCommandFactory, ResponseHandlerFactory); broker.Generate(requestParameters); return (ResponseParser.ResponseInfo as DataResponseInfo<string>)?.Data; }
/// <summary> /// Retrieve the usage information /// </summary> /// <returns>Usage information</returns> public UsageResponseInfo GetUsage() { IParameters requestParameters = UsageParameters.Create(); IMethodCallBroker broker = new MethodCallBroker(null, _randomService, null, _responseHandlerFactory); broker.Generate(requestParameters); return _responseParser.ResponseInfo as UsageResponseInfo; }
/// <summary> /// Retrieves a list of random blob values /// </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 IEnumerable<int> GenerateIntegers(int numberOfItemsToReturn, int minimumValue, int maximumValue, bool allowDuplicates = false) { IParameters requestParameters = IntegerParameters.Create(numberOfItemsToReturn, minimumValue, maximumValue, allowDuplicates); IMethodCallBroker broker = new MethodCallBroker(RequestBuilder, RandomService, BeforeRequestCommandFactory, ResponseHandlerFactory); broker.Generate(requestParameters); return (ResponseParser.ResponseInfo as DataResponseInfo<int>)?.Data; }
/// <summary> /// Retrieves a list of random blob values /// </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 IEnumerable<decimal> GenerateDecimalsFractions(int numberOfItemsToReturn, int numberOfDecimalPlaces, bool allowDuplicates = false) { IParameters requestParameters = DecimalParameters.Create(numberOfItemsToReturn, numberOfDecimalPlaces, allowDuplicates); IMethodCallBroker broker = new MethodCallBroker(RequestBuilder, RandomService, BeforeRequestCommandFactory, ResponseHandlerFactory); broker.Generate(requestParameters); return (ResponseParser.ResponseInfo as DataResponseInfo<decimal>)?.Data; }
/// <summary> /// Retrieves a list of random blob values /// </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 IEnumerable<string> GenerateBlobs(int numberOfItemsToReturn, int size, BlobFormat format = BlobFormat.Base64) { IParameters requestParameters = BlobParameters.Create(numberOfItemsToReturn, size, format); IMethodCallBroker broker = new MethodCallBroker(RequestBuilder, RandomService, BeforeRequestCommandFactory, ResponseHandlerFactory); broker.Generate(requestParameters); return (ResponseParser.ResponseInfo as DataResponseInfo<string>)?.Data; }
/// <summary> /// Retrieves a list of random blob values /// </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 IEnumerable<decimal> GenerateGuassians(int numberOfItemsToReturn, int mean, int standardDeviation, int significantDigits) { IParameters requestParameters = GuassianParameters.Create(numberOfItemsToReturn, mean, standardDeviation, significantDigits); IMethodCallBroker broker = new MethodCallBroker(RequestBuilder, RandomService, BeforeRequestCommandFactory, ResponseHandlerFactory); broker.Generate(requestParameters); return (ResponseParser.ResponseInfo as DataResponseInfo<decimal>)?.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 void Generate_WhenCalledWithResponseHandlerThatReturnsTrue_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.SendRequest(request)); Mock<IResponseHandlerFactory> responseHandlerMock = new Mock<IResponseHandlerFactory>(); responseHandlerMock.Setup(m => m.Execute(parameters.Object, It.IsAny<string>())).Returns(true); // Act MethodCallBroker target = new MethodCallBroker(requestBuilderMock.Object, randomServiceMock.Object); var actual = target.Generate(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(); }