Esempio n. 1
0
 internal static string GetDescriptionString(this DiceErrorCode code)
 {
     return(typeof(DiceErrorCode)
            .GetMember(code.ToString())[0]
            .GetCustomAttributes(typeof(DescriptionAttribute), false)
            .Cast <DescriptionAttribute>()
            .Single()
            .Description);
 }
Esempio n. 2
0
 protected static void EatExceptions(DiceErrorCode errorCode, Action action)
 {
     try
     {
         action();
     }
     catch (DiceException e)
     {
         if (e.ErrorCode != errorCode)
         {
             throw;
         }
     }
 }
Esempio n. 3
0
 protected static void EvaluateRoll(string diceExpr, RollerConfig conf, DiceErrorCode error)
 {
     try
     {
         Roller.Roll(diceExpr, conf);
         Assert.Fail("Expected DiceException with error code {0}, but did not receive an exception.", error.ToString());
     }
     catch (DiceException e)
     {
         if (e.ErrorCode != error)
         {
             Assert.Fail("Expected DiceException with error code {0}, but got error code {1}.", error.ToString(), e.ErrorCode.ToString());
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Evaluates the node and asserts that a DiceException was thrown with the specified error code.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="conf"></param>
 /// <param name="error"></param>
 protected static void EvaluateNode(DiceAST node, RollData data, DiceErrorCode error)
 {
     try
     {
         Roller.Roll(node, data);
         Assert.Fail("Expected DiceException with error code {0}, but did not receive an exception.", error.ToString());
     }
     catch (DiceException e)
     {
         if (e.ErrorCode != error)
         {
             Assert.Fail("Expected DiceException with error code {0}, but got error code {1}.", error.ToString(), e.ErrorCode.ToString());
         }
     }
 }
Esempio n. 5
0
        private static void EvaluatePost(string roll, DiceErrorCode error, RollPost post = null)
        {
            post = post ?? new RollPost();

            try
            {
                post.AddRoll(roll);
                Assert.Fail("Expected DiceException with error code {0}, but did not receive an exception.", error.ToString());
            }
            catch (DiceException e)
            {
                if (e.ErrorCode != error)
                {
                    Assert.Fail("Expected DiceException with error code {0}, but got error code {1}.", error.ToString(), e.ErrorCode.ToString());
                }
            }
        }
Esempio n. 6
0
 protected DiceException(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     ErrorCode = (DiceErrorCode)info.GetValue("ErrorCode", typeof(int));
 }
Esempio n. 7
0
 public DiceException(DiceErrorCode error, object param, Exception innerException)
     : base(String.Format(error.GetDescriptionString(), param), innerException)
 {
     ErrorCode = error;
 }
Esempio n. 8
0
 public DiceException(DiceErrorCode error, Exception innerException)
     : base(error.GetDescriptionString(), innerException)
 {
     ErrorCode = error;
 }
Esempio n. 9
0
 public DiceException(DiceErrorCode error)
     : base(error.GetDescriptionString())
 {
     ErrorCode = error;
 }