Skip to content

Commit

Permalink
Merge pull request #183 from SurferJeffAtGoogle/randomName
Browse files Browse the repository at this point in the history
Move RandomBucketName() to RandomName().
  • Loading branch information
SurferJeffAtGoogle committed Feb 24, 2017
2 parents 0ce87d8 + 9a92717 commit c9cb2a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
15 changes: 1 addition & 14 deletions testutil/TestBucket.cs
Expand Up @@ -50,20 +50,7 @@ public void Dispose()

private static string RandomBucketName()
{
using (RandomNumberGenerator rng = new RNGCryptoServiceProvider())
{
string legalChars = "abcdefhijklmnpqrstuvwxyz";
byte[] randomByte = new byte[1];
var randomChars = new char[20];
int nextChar = 0;
while (nextChar < randomChars.Length)
{
rng.GetBytes(randomByte);
if (legalChars.Contains((char)randomByte[0]))
randomChars[nextChar++] = (char)randomByte[0];
}
return new string(randomChars);
}
return TestUtil.RandomName();
}

public string BucketName { get; private set; }
Expand Down
21 changes: 21 additions & 0 deletions testutil/TestUtil.cs
Expand Up @@ -18,11 +18,32 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Threading;
using Xunit;

namespace GoogleCloudSamples
{
public class TestUtil
{
public static string RandomName()
{
using (RandomNumberGenerator rng = new RNGCryptoServiceProvider())
{
string legalChars = "abcdefhijklmnpqrstuvwxyz";
byte[] randomByte = new byte[1];
var randomChars = new char[20];
int nextChar = 0;
while (nextChar < randomChars.Length)
{
rng.GetBytes(randomByte);
if (legalChars.Contains((char)randomByte[0]))
randomChars[nextChar++] = (char)randomByte[0];
}
return new string(randomChars);
}
}
}
public class RetryRobot
{
public int FirstRetryDelayMs { get; set; } = 1000;
Expand Down

0 comments on commit c9cb2a1

Please sign in to comment.