anchor.diff:              testCase "message (binary)" <| fun _ ->
                   testPacketToBinary (Message(Binary([|1uy;2uy;3uy|] |> Segment.ofArray))) [4;1;2;3] "message (binary)"
   
  -            testCase "close" <| fun _ ->
  -                testPacketToBinary (Upgrade) [5] "close"
  +            testCase "upgrade" <| fun _ ->
  +                testPacketToBinary (Upgrade) [5] "upgrade"
   
               testCase "noop" <| fun _ ->
                   testPacketToBinary (Noop) [6] "noop"
  +        ]
  +
  +        testList "payload to string" [
  +            testCase "empty" <| fun _ ->
  +                testPayloadToString [] "0:" "empty"
  +            testCase "single message" <| fun _ ->
  +                testPayloadToString [Message(String("Hello world"))] "12:4Hello world" "message"
  +            testCase "two messages" <| fun _ ->
  +                testPayloadToString [Message(String("Hello"));Message(String("world"))] "6:4Hello6:4world" "2 messages"
  +            testCase "single binary message" <| fun _ ->
  +                testPayloadToString [Message(Binary([|1uy;2uy;3uy|] |> Segment.ofArray))] "6:b4AQID" "message"
  +        ]
  +
  +        testList "payload to binary" [
  +            testCase "empty" <| fun _ ->
  +                testPayloadToBinary [] [] "empty"
  +            testCase "close" <| fun _ ->
  +                testPayloadToBinary [Close] [0x00; 0x01; 0xFF; 0x31] "[close]"
  +            testCase "ping" <| fun _ ->
  +                testPayloadToBinary [Ping(String("abc"))] [0x00; 0x04; 0xff; 0x32; 0x61; 0x62; 0x63] "[ping text]"
  +            testCase "ping (binary)" <| fun _ ->
  +                testPayloadToBinary [Ping(Binary([|1uy;2uy;3uy|] |> Segment.ofArray))] [0x01; 0x04; 0xff; 2; 1; 2; 3] "[ping binary]"
  +            testCase "pong" <| fun _ ->
  +                testPayloadToBinary [Pong(String("abc"))] [0x00; 0x04; 0xff; 0x33; 0x61; 0x62; 0x63] "[pong text]"
  +            testCase "pong (binary)" <| fun _ ->
  +                testPayloadToBinary [Pong(Binary([|1uy;2uy;3uy|] |> Segment.ofArray))] [0x01; 0x04; 0xff; 3; 1; 2; 3] "[pong binary]"
  +            testCase "message" <| fun _ ->
  +                testPayloadToBinary [Message(String("abc"))] [0x00; 0x04; 0xff; 0x34; 0x61; 0x62; 0x63] "[message text]"
  +            testCase "message (binary)" <| fun _ ->
  +                testPayloadToBinary [Message(Binary([|1uy;2uy;3uy|] |> Segment.ofArray))] [0x01; 0x04; 0xff; 4; 1; 2; 3] "[message binary]"
  +            testCase "upgrade" <| fun _ ->
  +                testPayloadToBinary [Upgrade] [0x00; 0x01; 0xFF; 0x35] "[upgrade]"
  +            testCase "noop" <| fun _ ->
  +                testPayloadToBinary [Noop] [0x00; 0x01; 0xFF; 0x36] "[noop]"
  +            testCase "multiple" <| fun _ ->
  +                testPayloadToBinary [Noop; Message(Binary([|1uy;2uy;3uy|] |> Segment.ofArray)); Close] [0x00; 0x01; 0xFF; 0x36; 0x01; 0x04; 0xff; 4; 1; 2; 3; 0x00; 0x01; 0xFF; 0x31] "[noop;message binary;close]"
           ]
       ]
   
  
positive.code: let appendUtf8 s (arr: int seq) = Seq.concat [arr; utf8 s |> Seq.ofArray]
  
  [<Tests>]
  let tests =
      testList "encode" [
          testList "packet to string" [
              testCase "open" <| fun _ ->
  
negative.code: let private testPacketToString message expected format =
      Expect.equal (message |> PacketMessage.encodeToString) expected format
  
  let private testPayloadToBinary messages (expected: int seq) format =
      let expected = expected |> Seq.map(byte) |> Seq.toArray
      Expect.equal (Payload(messages) |> Payload.encodeToBinary) expected format
  
  let private testPayloadToString messages expected format =
      Expect.equal (Payload(messages) |> Payload.encodeToString) expected format
  
  