title: Generating JavaScript in C# and subsequent testing
body: <p>We are currently developing an ASP.NET MVC application which makes heavy use of attribute-based metadata to drive the generation of JavaScript.</p>
  
  <p>Below is a sample of the type of methods we are writing:</p>
  
  <pre><code>function string GetJavascript&lt;T&gt;(string javascriptPresentationFunctionName,
                                   string inputId,
                                   T model)
  {
      return @"function updateFormInputs(value){
          $('#" + inputId + @"_SelectedItemState').val(value);
          $('#" + inputId + @"_Presentation').val(value);
       }
  
      function clearInputs(){
          " + helper.ClearHiddenInputs&lt;T&gt;(model) + @"
          updateFormInputs('');
      }
  
      function handleJson(json){
          clearInputs();
          " + helper.UpdateHiddenInputsWithJson&lt;T&gt;("json", model) + @"
          updateFormInputs(" + javascriptPresentationFunctionName + @"());
          " + model.GetCallBackFunctionForJavascript("json") + @"
      }";
  }
  </code></pre>
  
  <p>This method generates some boilerplace and hands off to various other methods which return strings. The whole lot is then returned as a string and written to the output.</p>
  
  <p>The question(s) I have are:</p>
  
  <p>1) Is there a nicer way to do this other than using large string blocks?</p>
  
  <p>We've considered using a StringBuilder or the Response Stream but it seems quite 'noisy'. Using string.format starts to become difficult to comprehend.</p>
  
  <p>2) How would you go about unit testing this code? It seems a little amateur just doing a string comparison looking for particular output in the string.</p>
  
  <p>3) What about actually testing the eventual JavaScript output?</p>
  
  <p>Thanks for your input!</p>