コード例 #1
0
        public static async Task <TException> ThrowsAsync <TException>(Func <Task> action, params string[] possibleMessages)
            where TException : Exception
        {
            try
            {
                await action();

                Assert.Fail("Exception of type {0} expected. No exception thrown.", typeof(TException).Name);
                return(null);
            }
            catch (TException ex)
            {
                if (possibleMessages == null || possibleMessages.Length == 0)
                {
                    return(ex);
                }
                foreach (string possibleMessage in possibleMessages)
                {
                    if (StringAssert.Equals(possibleMessage, ex.Message))
                    {
                        return(ex);
                    }
                }

                throw new Exception("Unexpected exception message." + Environment.NewLine + "Expected one of: " + string.Join(Environment.NewLine, possibleMessages) + Environment.NewLine + "Got: " + ex.Message + Environment.NewLine + Environment.NewLine + ex);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Exception of type {0} expected; got exception of type {1}.", typeof(TException).Name, ex.GetType().Name), ex);
            }
        }
コード例 #2
0
        public static void AreEqual(string expected, string actual)
        {
            expected = Normalize(expected);
            actual   = Normalize(actual);

            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public static void Contains(IList collection, object value, string message)
        {
#if !(DNXCORE50)
            Assert.Contains(value, collection, message);
#else
            if (!collection.Cast <object>().Any(i => i.Equals(value)))
            {
                throw new Exception(message ?? "Value not found in collection.");
            }
#endif
        }
コード例 #4
0
 public static void IsInstanceOfType(Type t, object instance)
 {
     Assert.IsInstanceOf(t, instance);
 }