コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        public void WriteEndObject_EmptyBuffer_EndObject()
        {
            // arrange
            using var writer = new SocketMessageWriter();

            // act
            writer.WriteEndObject();

            // assert
            Encoding.UTF8.GetString(writer.Body.Span).MatchSnapshot();
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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();
        }
コード例 #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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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();
        }