Exploring Randomize.Net

Randomize.Net provides an easy and lightweight extensions for System.Random for creating random instances of any given Type T, with generated random value. This can be highly useful for generating POCO’s to test your sample code, including LINQ queries against. The API has been designed to make it extremely simple and devoid of any complex syntax.

Generating Random Instances

For Example,

// Primitive Types
var _random = new Random();_
var randomString = _random.GenerateInstance<string>();
var randomInt32 = _random.GenerateInstance<Int32>();

// Output
// randomString = OfuQ42CoIe
// randomInt32 = 239016499

Randomize.Net works with User Defined Types as well, including nested User Defined Types.

public class SampleClass
{
public string StringProperty{get;set;}
public int Int32Property {get;set;}
public char CharProperty {get;set;}
}

public class AnotherSampleClass
{
public SampleClass SampleClassProperty{get;set;}
public string StringProperty{get;set;}
}

var sampleClass = _random.GenerateInstance<SampleClass>();
var anotherSampleClass = _random.GenerateInstance<AnotherSampleClass>();

/* Output
* sampleClass.StringProperty = ORCPiyNoy5
* sampleClass.Int32Property = -1461704929
* sampleClass.CharProperty = q
*
* anotherSampleClass.StringProperty = D5wfOfQhAK
* anotherSampleClass.SampleClassProperty.StringProperty = DC7ArGwDj5
* anotherSampleClass.SampleClassProperty.Int32Property = -1311605510
* anotherSampleClass.SampleClassProperty.CharProperty = y
*/

Randomize.Net also supports generation of Collections.

// Method Signature
public static IEnumerable<T> GenerateCollection<T>(this Random source,int count = 1)

//Example
var sampleClassCollection = _random.GenerateCollection<SampleClass>(5);

// sampleClassCollection.Count = 5

Further examples on Randomize.Net would follow soon. If you are interested in looking at the code you can access it my Github.

An Introduction to EcSolvo.RestHelper

This post intends to act as an introductory guide on the EcSolvo.RestHelper Nuget. It takes you through the Main Methods that you would be using in your routine tasks.

RestHelper Constructor and ExecuteAsync

The RestHelper Constructor and ExecuteAsync Method is the heart of RestHelper Library. It is build on ‘Pit of Success’ philosophy, removing possible erroneous steps by the consuming Developer.
The RestHelper Constructor takes a single Parameter, which is the base address of your API.The ExecuteAsync is an Asynchronous Method which take in two Parameters,
a) HTTP Verb (GET,POST)
b) Resource (URL to the exact API Resource)

For GET Request

For Handling URI Parameters, the EcSolvo.RestHelper Library exposes a method called ‘AddURLParameters’, which helps to add parameters to the QueryString dictionary.


private string _BaseAddress = "http://localhost:8888/";
var resourceURL = "api/user/SingleParamStringResponse";
var restHelper = new EcSolvo.RestHelper(_BaseAddress);
string ParameterKey = "VariableStr";
string ParameterValue = "DummyString";
restHelper.AddURLParameters(ParameterKey, ParameterValue);
var result = await restHelper.ExecuteAsync(HttpMethod.Get, resourceURL);

The library works even if the parameter passed is a Complex Parameter (Controller uses FromUri Attribute).

For POST Request

For Handling OnBody Parameter in POST Request, the library exposes a method called ‘AssignMessageBodyParameter’.


restHelper.AssignMessageBodyParameter(Parameter);
var result = await restHelper.ExecuteAsync(HttpMethod.Post, resourceURL);

If the POST Request have additional URI Parameters, it can use the ‘AddURLParameters’ Method to add it to the dictionary.

EcSolvo.RestHelper Nuget

Recently I have started working on a Nuget Package for providing a is a sleek and simple Wrapper library for providing simple access to Rest API, by hiding away the complexities of HTTPClient Class.Named EcSolvo.RestHelper it is particularly designed to work along with Xamarin PCL Projects

You can follow and contribute to the Nuget in Github : Link to GitHub Repository

Follow updates on Nuget : Link To Nuget