public int ClaimDevice(int Timeout) { if (_props.ByName.Claimed) { return(SetResultCode(ResultCodeConstants.Success)); } if (Timeout < -1) { return(SetResultCode(ResultCodeConstants.Illegal)); } try { if (_device.CanClaimDevice()) { if (_device.ClaimDevice(TimeSpan.FromMilliseconds(Timeout))) { _props.SetIntProperty(PropertyConstants.PIDX_Claimed, 1); return(SetResultCode(ResultCodeConstants.Success)); } return(SetResultCode(ResultCodeConstants.Timeout)); } return(SetResultCode(ResultCodeConstants.Illegal)); } catch (Exception e) { Console.WriteLine(e); return(SetResultCode(ResultCodeConstants.Failure)); } }
public void WhenSettingIntValue_AndValidationFails_PropertyIsNotSet_And_ResultCodeIsSet_ToIllegal() { _props.SetPropertyValidator(FakeIntPropertyIndex, x => (int)x > 0 ? ResultCodeConstants.Success : ResultCodeConstants.Illegal); var resultCode = _props.SetIntProperty(FakeIntPropertyIndex, -1); _props.GetIntProperty(FakeIntPropertyIndex) .Should() .Be(FakeIntPropertyValue, "because the value should not have been set"); resultCode .Should() .Be(ResultCodeConstants.Illegal, "because when setting an illegal value to a property, the result code is set to Illegal"); }