title: C#, xunit, fscheck, writing a simple property based test using a custom generator or constrained random string
body: <p>I am trying to solve the <strong>diamond kata</strong> in order to learn how to write property based tests with the fscheck library. I want to write the tests with C# and I am using Visual Studio 2017.</p>
  
  <p><strong>I want to write a property based test that does not generate any random chars as input, but letters only. I'm not sure how to write the generator fscheck requires to do this and in which file to put the code?</strong></p>
  
  <p>I searched everywhere and read documentation, but am having trouble (partly because I cannot translate F# into C# very well).</p>
  
  <p><strong>How is <code>[Property]</code> used to constrain the input data to only letters?</strong></p>
  
  <p>If there is a better approach please let me know.</p>
  
  <p>[Edit:]</p>
  
  <p>I edited my code examples, which now contain one working solution by Kurt Schelfthout .</p>
  
  <hr>
  
  <hr>
  
  <p><strong>Tests</strong></p>
  
  <pre><code>using DiamondKata;
  using FsCheck;
  using FsCheck.Xunit;
  using Xunit;
  
  namespace DiamondKataTests
  {
      public static class Arbitraries
      {
          private static readonly string upperAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
          private static readonly string lowerAlphabet = ""; //upperAlphabet.ToLower();
          private static readonly char[] wholeAlphabet = (lowerAlphabet + upperAlphabet).ToCharArray();
          public static Arbitrary&lt;char&gt; LetterGenerator()
          {
              return Gen.Elements(wholeAlphabet).ToArbitrary();
          }
      }
  
      public class DiamondKataTests
      {
          // THIS WORKS and is apparently the preferred way of doing things
          // also see here: https://stackoverflow.com/questions/32811322/fscheck-in-c-generate-a-list-of-two-dimension-arrays-with-the-same-shape
          [Property()]
          public Property shouldReturnStringAssumesValidCharWasProvided()
          {
              return Prop.ForAll(Arbitraries.LetterGenerator(), letter =&gt;
  
                  // test here
                  Assert.NotNull(Diamond.Create(letter))
              );
          }
  
          // Second solution ...
          // Error here: Arbitraries is a type not valid in the given context
          [Property(Arbitrary = new[] { typeof&lt;Arbitraries&gt; })]
          public void testThatAssumesValidCharWasProvided(char lettersOnlyHERE)
          {
              // ?
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Class To Test</strong></p>
  
  <pre><code>namespace DiamondKata
  {
      public class Diamond
      {
          public static string Create(char turningPointCharacter)
          {
              return "";
          }
      }
  }
  </code></pre>