internal RegistryReadValueCommand(BridgeMessageDeserializer deserializer) : base(deserializer.CommandName) { BaseKey = deserializer.GetEnumValue <RegistryBaseKey>(ParamName.RegistryBaseKey); Key = deserializer.GetStringValue(ParamName.RegistryKey); ValueName = deserializer.GetStringValue(ParamName.RegistryValueName); DefaultValue = (T)Convert.ChangeType(deserializer.GetValue(ParamName.RegistryDefaultValue), typeof(T)); }
internal RegistryWriteValueCommand(BridgeMessageDeserializer deserializer) : base(deserializer.CommandName) { BaseKey = deserializer.GetEnumValue <RegistryBaseKey>(ParamName.RegistryBaseKey); Key = deserializer.GetStringValue(ParamName.RegistryKey); ValueName = deserializer.GetStringValue(ParamName.RegistryValueName); Value = (T)deserializer.GetValue(ParamName.RegistryValue); }
public void TryCreateFromJsonString_should_return_an_error_if_missing_a_command_name() { BridgeMessageDeserializer.TryCreateFromJsonString( $"{{ Something: 10 }}", out BridgeMessageDeserializer deserializer, out IServiceCommandResponse errorResponse) .Should() .BeFalse(); deserializer.Should().BeNull(); errorResponse.Should().NotBeNull(); errorResponse.CommandName.Should().Be(ServiceCommandName.Unknown); errorResponse.ErrorCode.Should().Be(ServiceCommandErrorCode.MissingRequiredMessageValue); errorResponse.ErrorMessage.Should().Contain(ParamName.CommandName.ToString()); }
public void HadError_should_be_false_initially() { var valueSet = new Dictionary <string, object> { [ParamName.CommandName.ToString()] = ServiceCommandName.RegistryReadIntValue }; BridgeMessageDeserializer.TryCreateFromValueSet( valueSet, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse _) .Should() .BeTrue(); deserializer.HadError.Should().BeFalse(); }
public void LastError_should_be_null_on_a_new_instance() { var valueSet = new Dictionary <string, object> { [ParamName.CommandName.ToString()] = ServiceCommandName.RegistryReadIntValue }; BridgeMessageDeserializer.TryCreateFromValueSet( valueSet, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse _) .Should() .BeTrue(); deserializer.LastError.Should().BeNull(); }
public void TryCreateFromJsonString_should_return_an_error_if_the_json_contains_nested_objects() { BridgeMessageDeserializer.TryCreateFromJsonString( "{ invalidJson: { nested: 123 } }", out BridgeMessageDeserializer deserializer, out IServiceCommandResponse errorResponse) .Should() .BeFalse(); deserializer.Should().BeNull(); errorResponse.Should().NotBeNull(); errorResponse.CommandName.Should().Be(ServiceCommandName.Unknown); errorResponse.ErrorCode.Should().Be(ServiceCommandErrorCode.InternalError); errorResponse.ErrorMessage.Should().Contain("Unable to cast object of type"); }
public void TryCreateFromJsonString_should_return_an_error_if_the_json_is_invalid() { BridgeMessageDeserializer.TryCreateFromJsonString( "invalidJson: 123", out BridgeMessageDeserializer deserializer, out IServiceCommandResponse errorResponse) .Should() .BeFalse(); deserializer.Should().BeNull(); errorResponse.Should().NotBeNull(); errorResponse.CommandName.Should().Be(ServiceCommandName.Unknown); errorResponse.ErrorCode.Should().Be(ServiceCommandErrorCode.InternalError); errorResponse.ErrorMessage.Should().StartWith("Internal error: Unexpected character"); }
public void TryCreateFromJsonString_should_return_an_error_if_command_name_is_not_the_right_type() { BridgeMessageDeserializer.TryCreateFromJsonString( $"{{ {ParamName.CommandName}: \"NotRight\" }}", out BridgeMessageDeserializer deserializer, out IServiceCommandResponse errorResponse) .Should() .BeFalse(); deserializer.Should().BeNull(); errorResponse.Should().NotBeNull(); errorResponse.CommandName.Should().Be(ServiceCommandName.Unknown); errorResponse.ErrorCode.Should().Be(ServiceCommandErrorCode.WrongMessageValueType); errorResponse.ErrorMessage.Should().Contain(ParamName.CommandName.ToString()); }
public void GetValue_should_return_the_deserialized_value() { var valueSet = new Dictionary <string, object> { [ParamName.CommandName.ToString()] = ServiceCommandName.RegistryReadIntValue, [ParamName.RegistryKey.ToString()] = "Key" }; BridgeMessageDeserializer.TryCreateFromValueSet( valueSet, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse _) .Should() .BeTrue(); deserializer.GetValue(ParamName.RegistryKey).Should().Be("Key"); deserializer.LastError.Should().BeNull(); }
public void TryCreateFromValueSet_should_return_an_error_if_missing_a_command_name() { var valueSet = new Dictionary <string, object>(); BridgeMessageDeserializer.TryCreateFromValueSet( valueSet, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse errorResponse) .Should() .BeFalse(); deserializer.Should().BeNull(); errorResponse.Should().NotBeNull(); errorResponse.CommandName.Should().Be(ServiceCommandName.Unknown); errorResponse.ErrorCode.Should().Be(ServiceCommandErrorCode.MissingRequiredMessageValue); errorResponse.ErrorMessage.Should().Contain(ParamName.CommandName.ToString()); }
public void TryCreateFromValueSet_should_correctly_deserialize() { var valueSet = new Dictionary <string, object> { [ParamName.CommandName.ToString()] = ServiceCommandName.RegistryReadIntValue }; BridgeMessageDeserializer.TryCreateFromValueSet( valueSet, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse errorResponse) .Should() .BeTrue(); deserializer.Should().NotBeNull(); errorResponse.Should().BeNull(); deserializer.CommandName.Should().Be(ServiceCommandName.RegistryReadIntValue); }
public void TryGetOptionalEnumValue_should_return_false_if_the_value_is_not_present() { var valueSet = new Dictionary <string, object> { [ParamName.CommandName.ToString()] = ServiceCommandName.RegistryReadIntValue, }; BridgeMessageDeserializer.TryCreateFromValueSet( valueSet, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse _) .Should() .BeTrue(); deserializer.TryGetOptionalEnumValue(ParamName.RegistryBaseKey, out RegistryBaseKey hive).Should().BeFalse(); hive.Should().Be(default(RegistryBaseKey)); deserializer.LastError.Should().BeNull(); }
public void TryCreateFromValueSet_should_return_an_error_if_command_name_is_not_the_right_type() { var valueSet = new Dictionary <string, object> { [ParamName.CommandName.ToString()] = "NotRight" }; BridgeMessageDeserializer.TryCreateFromValueSet( valueSet, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse errorResponse) .Should() .BeFalse(); deserializer.Should().BeNull(); errorResponse.Should().NotBeNull(); errorResponse.CommandName.Should().Be(ServiceCommandName.Unknown); errorResponse.ErrorCode.Should().Be(ServiceCommandErrorCode.WrongMessageValueType); errorResponse.ErrorMessage.Should().Contain(ParamName.CommandName.ToString()); }
public void GetValue_should_set_LastError_if_the_parameter_is_not_present() { var valueSet = new Dictionary <string, object> { [ParamName.CommandName.ToString()] = ServiceCommandName.RegistryReadIntValue, }; BridgeMessageDeserializer.TryCreateFromValueSet( valueSet, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse _) .Should() .BeTrue(); deserializer.GetValue(ParamName.RegistryKey).Should().BeNull(); deserializer.LastError.Should().NotBeNull(); deserializer.LastError.CommandName.Should().Be(ServiceCommandName.RegistryReadIntValue); deserializer.LastError.ErrorCode.Should().Be(ServiceCommandErrorCode.MissingRequiredMessageValue); deserializer.LastError.ErrorMessage.Should().Contain(ParamName.RegistryKey.ToString()); }
public void TryGetOptionalEnumValue_should_return_true_when_correctly_deserializing() { var valueSet = new Dictionary <string, object> { [ParamName.CommandName.ToString()] = ServiceCommandName.RegistryReadIntValue, [ParamName.RegistryBaseKey.ToString()] = RegistryBaseKey.CurrentUser }; BridgeMessageDeserializer.TryCreateFromValueSet( valueSet, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse _) .Should() .BeTrue(); deserializer.TryGetOptionalEnumValue(ParamName.RegistryBaseKey, out RegistryBaseKey hive).Should().BeTrue(); hive.Should().Be(RegistryBaseKey.CurrentUser); deserializer.LastError.Should().BeNull(); }
public void TryCreateFromJsonString_should_correctly_deserialize() { string json = $@" {{ {ParamName.CommandName}: ""{ServiceCommandName.Echo}"", {ParamName.EchoMessage}: ""Test"", }}"; BridgeMessageDeserializer.TryCreateFromJsonString( json, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse errorResponse) .Should() .BeTrue(); deserializer.Should().NotBeNull(); errorResponse.Should().BeNull(); deserializer.CommandName.Should().Be(ServiceCommandName.Echo); deserializer.GetStringValue(ParamName.EchoMessage).Should().Be("Test"); }
public void GetIntValue_should_set_LastError_if_the_parameter_is_not_the_right_type() { var valueSet = new Dictionary <string, object> { [ParamName.CommandName.ToString()] = ServiceCommandName.RegistryReadIntValue, [ParamName.ErrorCode.ToString()] = "NotValid" }; BridgeMessageDeserializer.TryCreateFromValueSet( valueSet, out BridgeMessageDeserializer deserializer, out IServiceCommandResponse _) .Should() .BeTrue(); deserializer.GetIntValue(ParamName.ErrorCode).Should().Be(default(int)); deserializer.LastError.Should().NotBeNull(); deserializer.LastError.CommandName.Should().Be(ServiceCommandName.RegistryReadIntValue); deserializer.LastError.ErrorCode.Should().Be(ServiceCommandErrorCode.WrongMessageValueType); deserializer.LastError.ErrorMessage.Should().Contain(ParamName.ErrorCode.ToString()); }
internal RegistryReadStringValueCommand(BridgeMessageDeserializer deserializer) : base(deserializer) { }
internal EchoCommand(BridgeMessageDeserializer deserializer) : base(ServiceCommandName.Echo) { EchoMessage = deserializer.GetStringValue(ParamName.EchoMessage); }
public void TryCreateFromJsonString_should_throw_on_null_params() { Action action = () => BridgeMessageDeserializer.TryCreateFromJsonString(null, out _, out _); action.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("jsonString"); }
internal RegistryWriteIntValueCommand(BridgeMessageDeserializer deserializer) : base(deserializer) { }