public async Task WriteInitializeMessage_Default_IsMatch()
        {
            // arrange
            await using var writer = new SocketMessageWriter();

            // act
            writer.WriteInitializeMessage(null);

            // assert
            Encoding.UTF8.GetString(writer.Body.Span).MatchSnapshot();
        }
        public async Task WriteInitializeMessage_CustomObject_IsMatch()
        {
            // arrange
            await using var writer = new SocketMessageWriter();

            // act
            writer.WriteInitializeMessage(new CustomPayload());

            // assert
            Encoding.UTF8.GetString(writer.Body.Span).MatchSnapshot();
        }
Ejemplo n.º 3
0
        public void WriteEndObject_EmptyBuffer_EndObject()
        {
            // arrange
            using var writer = new SocketMessageWriter();

            // act
            writer.WriteEndObject();

            // assert
            Encoding.UTF8.GetString(writer.Body.Span).MatchSnapshot();
        }
        private Task TerminateConnectionAsync(
            ISocketConnection connection,
            CancellationToken cancellationToken = default)
        {
            var messageWriter = new SocketMessageWriter();

            messageWriter.WriteStartObject();
            messageWriter.WriteType(MessageTypes.Connection.Terminate);
            messageWriter.WriteEndObject();

            return(connection.SendAsync(messageWriter.Body, cancellationToken));
        }
        public async Task WriteStopOperationMessage_OperationIdNull_IsMatch()
        {
            // arrange
            await using var writer = new SocketMessageWriter();

            // act
            Exception?ex =
                Record.Exception(() => writer.WriteStopOperationMessage(null !));

            // assert
            Assert.IsType <ArgumentNullException>(ex);
        }
        public async Task WriteStopOperationMessage_WithOperationId_IsMatch()
        {
            // arrange
            await using var writer = new SocketMessageWriter();
            var operationId = "12f90cc5-2905-4d10-b33a-cb6d8f98a810";

            // act
            writer.WriteStopOperationMessage(operationId);

            // assert
            Encoding.UTF8.GetString(writer.Body.Span).MatchSnapshot();
        }
        public async Task WriteInitializeMessage_Dictionary_IsMatch()
        {
            // arrange
            await using var writer = new SocketMessageWriter();

            // act
            writer.WriteInitializeMessage(new Dictionary <string, object> {
                ["Key"] = "Value"
            });

            // assert
            Encoding.UTF8.GetString(writer.Body.Span).MatchSnapshot();
        }
Ejemplo n.º 8
0
        public void Reset_ObjectInBuffer_EmptyBuffer()
        {
            // arrange
            using var writer = new SocketMessageWriter();
            writer.WriteStartObject();
            writer.WriteEndObject();

            // act
            writer.Reset();

            // assert
            Assert.True(writer.Body.IsEmpty);
        }
        public async Task WriteStartOperationMessage_RequestIsNull_IsMatch()
        {
            // arrange
            await using var writer = new SocketMessageWriter();
            var operationId = "12f90cc5-2905-4d10-b33a-cb6d8f98a810";


            // act
            Exception?ex =
                Record.Exception(() => writer.WriteStartOperationMessage(operationId, null !));

            // assert
            Assert.IsType <ArgumentNullException>(ex);
        }
        public async Task WriteStartOperationMessage_OperationIdNull_IsMatch()
        {
            // arrange
            await using var writer = new SocketMessageWriter();
            var request = new OperationRequest("Foo",
                                               GetHeroQueryDocument.Instance,
                                               new Dictionary <string, object?>()
            {
                { "Var1", "Value1" }
            });


            // act
            Exception?ex =
                Record.Exception(() => writer.WriteStartOperationMessage(null !, request));

            // assert
            Assert.IsType <ArgumentNullException>(ex);
        }
        public async Task WriteStartOperationMessage_WithOperation_IsMatch()
        {
            // arrange
            await using var writer = new SocketMessageWriter();
            var operationId = "12f90cc5-2905-4d10-b33a-cb6d8f98a810";
            var request     = new OperationRequest("Foo",
                                                   GetHeroQueryDocument.Instance,
                                                   new Dictionary <string, object?>()
            {
                { "Var1", "Value1" }
            });


            // act
            writer.WriteStartOperationMessage(operationId, request);

            // assert
            Encoding.UTF8.GetString(writer.Body.Span).MatchSnapshot();
        }