public void ParseMessage_TypeIsNull_ThrowException() { // arrange ReadOnlySequence <byte> message = GetBytes($@"{{""type"": null, ""Foo"":1}}"); // act Exception?ex = Record.Exception(() => GraphQLWebSocketMessageParser.Parse(message)); // assert Assert.IsType <SerializationException>(ex).Message.MatchSnapshot(); }
public void ParseMessage_OnlyId_ThrowException() { // arrange ReadOnlySequence <byte> message = GetBytes(@"{""id"": ""123""}"); // act Exception?ex = Record.Exception(() => GraphQLWebSocketMessageParser.Parse(message)); // assert Assert.IsType <SerializationException>(ex).Message.MatchSnapshot(); }
public void ParseMessage_KeepAlive_ParseMessage() { // arrange ReadOnlySequence <byte> message = GetBytes(@"{""type"": ""ka""}"); // act GraphQLWebSocketMessage parsed = GraphQLWebSocketMessageParser.Parse(message); // assert Assert.Equal(GraphQLWebSocketMessageType.KeepAlive, parsed.Type); }
public void ParseMessage_UnknownType_ThrowException(string type) { // arrange ReadOnlySequence <byte> message = GetBytes($@"{{""type"": ""{type}"", ""Foo"":1}}"); // act Exception?ex = Record.Exception(() => GraphQLWebSocketMessageParser.Parse(message)); // assert Assert.IsType <SerializationException>(ex) .Message.MatchSnapshot(new SnapshotNameExtension(type)); }
public void ParseMessage_IncompleteDocument_ThrowException() { // arrange ReadOnlySequence <byte> message = GetBytes(@"{""id"": ""123"""); // act Exception?ex = Record.Exception(() => GraphQLWebSocketMessageParser.Parse(message)); // assert Assert.NotNull(ex); ex.Message.MatchSnapshot(); }
public void ParseMessage_ConnectionTerminate_ParseMessage() { // arrange ReadOnlySequence <byte> message = GetBytes(@"{""type"": ""connection_terminate"" }"); // act GraphQLWebSocketMessage parsed = GraphQLWebSocketMessageParser.Parse(message); // assert Assert.Equal(GraphQLWebSocketMessageType.ConnectionTerminate, parsed.Type); }
public void ParseMessage_ConnectionError_ParseMessage() { // arrange ReadOnlySequence <byte> message = GetBytes(@"{""type"": ""connection_error"", ""payload"": ""payload""}"); // act GraphQLWebSocketMessage parsed = GraphQLWebSocketMessageParser.Parse(message); // assert Assert.Equal(GraphQLWebSocketMessageType.ConnectionError, parsed.Type); Assert.Equal("payload", parsed.Payload.RootElement.ToString()); }
public void ParseMessage_Complete_ParseMessage() { // arrange ReadOnlySequence <byte> message = GetBytes(@"{""type"": ""complete"", ""id"":""123""}"); // act GraphQLWebSocketMessage parsed = GraphQLWebSocketMessageParser.Parse(message); // assert Assert.Equal(GraphQLWebSocketMessageType.Complete, parsed.Type); Assert.Equal("123", parsed.Id); }
public void ParseMessage_Start_ParseMessage() { // arrange ReadOnlySequence <byte> message = GetBytes(@"{""type"": ""start"", ""id"":""123"", ""payload"": ""payload""}"); // act GraphQLWebSocketMessage parsed = GraphQLWebSocketMessageParser.Parse(message); // assert Assert.Equal(GraphQLWebSocketMessageType.Start, parsed.Type); Assert.Equal("123", parsed.Id); Assert.Equal("payload", parsed.Payload.RootElement.ToString()); }
private ValueTask ProcessAsync( ReadOnlySequence <byte> slice, CancellationToken cancellationToken) { try { GraphQLWebSocketMessage message = GraphQLWebSocketMessageParser.Parse(slice); if (message.Id is { } id) { return(message.Type switch { GraphQLWebSocketMessageType.Data => Notify( id, new DataDocumentOperationMessage <JsonDocument>(message.Payload), cancellationToken), GraphQLWebSocketMessageType.Complete => Notify( id, CompleteOperationMessage.Default, cancellationToken), GraphQLWebSocketMessageType.Error => Notify( id, ErrorOperationMessage.UnexpectedServerError, cancellationToken), GraphQLWebSocketMessageType.ConnectionError => Notify( id, ErrorOperationMessage.ConnectionInitializationError, cancellationToken), _ => CloseSocketOnProtocolError( "Invalid message type received: " + message.Type, cancellationToken) }); }