anchor.diff:        Uri : string
         Querystring : string
         Requestbody : string option
  -      TestCases : ResizeArray<Test>
         Output : ResizeArray<string>
         OutputResponse : ResizeArray<string> }
   
  
positive.code: open FlexSearch.Api
  open FlexSearch.Api.Message
  open FlexSearch.Core
  open FsUnit
  open Fuchu
  open Newtonsoft.Json
  open Newtonsoft.Json.Linq
  open System
  
negative.code:     result
  
  // ----------------------------------------------------------------------------
  // Test server initialization
  // ----------------------------------------------------------------------------
  /// <summary>
  /// Test setup fixture to use with Xunit IUseFixture
  /// </summary>
  type IntegrationIndexFixture() = 
      let mutable serverRunning = false
      member this.Setup() = 
          if serverRunning <> true then 
              let serverSettings = new ServerSettings()
              let container = Main.GetContainer(serverSettings, true)
              let indexService = container.Resolve<IIndexService>()
              let index = Helpers.MockIndexSettings()
              index.IndexName <- "contact"
              AddTestDataToIndex
                  (index, Helpers.MockTestData, container.Resolve<IDocumentService>(), container.Resolve<IIndexService>())
              let httpFactory = container.Resolve<IFlexFactory<HttpModuleBase>>()
              let httpServer = new Owin.Server(indexService, httpFactory) :> IServer
              httpServer.Start()
              serverRunning <- true
  
  /// <summary>
  /// Base for creating all Xunit based indexing integration tests
  /// </summary>
  [<AbstractClass>]
  type IntegrationTestBase() = 
      interface IUseFixture<IntegrationIndexFixture> with
          member this.SetFixture(data) = data.Setup()
  
  type ``REST Service Tests``() = 
      inherit IntegrationTestBase()
      
      [<Fact>]
      let ``Index creation test 1``() = 
          example "post-index-1" "Create index without any field"
          |> ofResource "Index"
          |> withDescription """
      The newly created index will be offline as the Online parameter is set to false as default. An index has to be opened after creation to enable indexing.
      """
          |> request "POST" "/test1"
          |> execute
          |> responseStatusEquals HttpStatusCode.OK
          |> responseBodyIsNull
          |> document
      
      [<Fact>]
      let ``Index creation test 2``() = 
          example "post-index-1" "Create index without any field"
          |> ofResource "Index"
          |> withDescription """
      The newly created index will be offline as the Online parameter is set to false as default. An index has to be opened after creation to enable indexing.
      """
          |> request "POST" "/test101"
          |> execute
          |> responseStatusEquals HttpStatusCode.OK
          |> responseBodyIsNull
          |> ignore
          example "post-index-2" "Duplicate index cannot be created."
          |> ofResource "Index"
          |> withDescription """
      The newly created index will be offline as the Online parameter is set to false as default. An index has to be opened after creation to enable indexing.
      """
          |> request "POST" "/test101"
          |> execute
          |> responseStatusEquals HttpStatusCode.BadRequest
          |> responseMatches "ErrorCode" "1002"
          |> document
      
      [<Fact>]
      let ``Index creation test 3``() = 
          example "post-index-3" "Create index with two field 'firstname' & 'lastname'"
          |> ofResource "Index"
          |> withDescription """
      All field names should be lower case and should not contain any spaces. This is to avoid case based mismatching on field names. Fields have many 
      other configurable properties but Field Type is the only mandatory parameter. Refer to Index Field for more information about field properties.
      """
          |> request "POST" "/test2"
          |> withBody """
          {
              "Fields" : {
                  "firstname" : { FieldType : "Text" },
                  "lastname" : { FieldType : "Text" }
              }
          }
          """
          |> execute
          |> responseStatusEquals HttpStatusCode.OK
          |> responseBodyIsNull
          |> document
      
      [<Fact>]
      let ``Create update and delete an index``() = 
          example "post-index-4" "Create index with computed field"
          |> ofResource "Index"
          |> withDescription """
      Fields can be dynamic in nature and can be computed at index time from the passed data. Computed field requires custom scripts which defines the 
      field data creation logic. Let’s create an index field called fullname which is a concatenation of ‘firstname’ and ‘lastname’.
  
      Computed fields requires ScriptName property to be set in order load a custom script. FlexSearch scripts are 
      dynamically compiled to .net dlls so performance wise they are similar to native .net code. Scripts are written 
      in C#. But it would be difficult to write complex scripts in single line to pass to the Script source, that 
      is why Flex supports Multi-line and File based scripts. Refer to Script for more information about scripts.
      """
          |> request "POST" "/test3"
          |> withBody """
          {
              "Fields" : {
                  "firstname" : { FieldType : "Text" },
                  "lastname" : { FieldType : "Text" },
                  "fullname" : {FieldType : "Text", ScriptName : "fullnamescript"}
              },
              "Scripts" : {
                  fullnamescript : {
                      ScriptType : "ComputedField",
                      Source : "return fields[\"firstname\"] + \" \" + fields[\"lastname\"];"
                  }
              }
          }
          """
          |> execute
          |> responseStatusEquals HttpStatusCode.OK
          |> responseBodyIsNull
          |> document
          |> ignore
          example "put-index-1" "Updating an existing index"
          |> ofResource "Index"
          |> withDescription """
      There are a number of parameters which can be set for a given index. For more information about each parameter please refer to Glossary.
      """
          |> request "PUT" "/test3"
          |> withBody """
      {
          "Fields" : {
              "firstname" : { FieldType : "Text" },
              "lastname" : { FieldType : "Text" },
              "fullname" : {FieldType : "Text", ScriptName : "fullnamescript"},
              "desc" : { FieldType : "Stored" },
          },
          "Scripts" : {
              fullnamescript : {
  