protected static RpcError GetRpcError(IDictionary <string, object> properties) { if (properties["RpcErrorIdentifier"] == null && properties["RpcErrorCode"] == null) { return(null); } else { return(RpcError.FromIdentifier(( string )properties["RpcErrorIdentifier"], ( int? )properties["RpcErrorCode"])); } }
public void TestFromIdentifier_Known_SameAsKnown() { foreach (var prop in typeof(RpcError).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(item => item.PropertyType == typeof(RpcError))) { var target = prop.GetValue(null, null) as RpcError; var viaIdentifier = RpcError.FromIdentifier(target.Identifier, null); Assert.That(viaIdentifier, Is.SameAs(target)); var viaErrorCode = RpcError.FromIdentifier(null, target.ErrorCode); Assert.That(viaErrorCode, Is.SameAs(target)); } }
public void TestFromIdentifier_Unknown_AsCustom() { foreach (var prop in typeof(RpcError).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(item => item.PropertyType == typeof(RpcError))) { var target = prop.GetValue(null, null) as RpcError; var viaIdentifier = RpcError.FromIdentifier(target.Identifier, target.ErrorCode * -1); Assert.That(viaIdentifier, Is.Not.Null); Assert.That(viaIdentifier, Is.SameAs(target)); var viaErrorCode = RpcError.FromIdentifier(target.Identifier + "A", target.ErrorCode); Assert.That(viaErrorCode, Is.Not.Null); Assert.That(viaErrorCode, Is.SameAs(target)); var custom = RpcError.FromIdentifier(target.Identifier + "A", Math.Abs(target.ErrorCode) % 1000); Assert.That(custom, Is.Not.Null); Assert.That(custom, Is.Not.SameAs(target)); Assert.That(custom.Identifier, Is.EqualTo(target.Identifier + "A")); Assert.That(custom.ErrorCode, Is.EqualTo(Math.Abs(target.ErrorCode) % 1000)); } }