public void TryDeserializeFromValueSet_should_deserialize_an_error()
        {
            var valueSet = new Dictionary <string, object>
            {
                [ParamName.CommandName.ToString()]   = ServiceCommandName.RegistryReadIntValue,
                [ParamName.CommandResult.ToString()] = null,
                [ParamName.ErrorCode.ToString()]     = ServiceCommandErrorCode.InternalError,
                [ParamName.ErrorMessage.ToString()]  = "Error",
            };

            ServiceCommandResponse.TryDeserializeFromValueSet(
                valueSet,
                out IServiceCommandResponse response,
                out IServiceCommandResponse errorResponse)
            .Should()
            .BeTrue();

            response.Should().NotBeNull();
            errorResponse.Should().BeNull();

            response.CommandName.Should().Be(ServiceCommandName.RegistryReadIntValue);
            response.Result.Should().BeNull();
            response.ErrorCode.Should().Be(ServiceCommandErrorCode.InternalError);
            response.ErrorMessage.Should().Be("Error");

            response.IsError.Should().BeTrue();
            response.IsSuccess.Should().BeFalse();
        }
示例#2
0
        //// ===========================================================================================================
        //// Methods
        //// ===========================================================================================================

        public async Task <IServiceCommandResponse> SendCommandAsync(IServiceCommand command)
        {
            var valueSet = new ValueSet();

            command.SerializeToValueSet(valueSet);
            AppServiceResponse bridgeResponse = await _connection.SendMessageAsync(valueSet);

            AppServiceResponseStatus status = bridgeResponse.Status;

            IServiceCommandResponse response;

            if (status == AppServiceResponseStatus.Success)
            {
                if (!ServiceCommandResponse.TryDeserializeFromValueSet(
                        bridgeResponse.Message,
                        out response,
                        out IServiceCommandResponse errorResponse))
                {
                    response = errorResponse;
                }
            }
            else
            {
                response = ServiceCommandResponse.CreateError(command.CommandName,
                                                              ServiceErrorInfo.InternalError($"AppServiceConnection failed with status '{status}'"));
            }

            return(response);
        }
        public void TryDeserializeFromValueSet_should_fail_if_missing_a_command_name()
        {
            var valueSet = new Dictionary <string, object>
            {
                [ParamName.CommandResult.ToString()] = 123,
                [ParamName.ErrorCode.ToString()]     = ServiceCommandErrorCode.Success,
            };

            ServiceCommandResponse.TryDeserializeFromValueSet(
                valueSet,
                out IServiceCommandResponse response,
                out IServiceCommandResponse errorResponse)
            .Should()
            .BeFalse();

            response.Should().BeNull();
            errorResponse.Should().NotBeNull();

            errorResponse.CommandName.Should().Be(ServiceCommandName.Unknown);
            errorResponse.Result.Should().BeNull();
            errorResponse.ErrorCode.Should().Be(ServiceCommandErrorCode.MissingRequiredMessageValue);
            errorResponse.ErrorMessage.Should().Contain(ParamName.CommandName.ToString());
        }