IntToGuid
Converts an integer to a Guid. This could be used within a unit test to mock objects.
Source
public static Guid ToGuid(this int value)
{
byte[] bytes = new byte[16];
BitConverter.GetBytes(value).CopyTo(bytes, 0);
return new Guid(bytes);
}
Example
class Customer
{
public Guid Id { get; set; }
public string Name { get; set; }
}
public IEnumerable<Customer> GetCustomers()
{
for (int i = 0; i < 10; i++)
{
yield return new Customer
{
Id = i.ToGuid(),
Name = "Name " + i
};
}
}