コード例 #1
0
        public static void Throws <TException>(Action action, params string[] possibleMessages)
            where TException : Exception
        {
            try
            {
                action();

                Assert.Fail("Exception of type {0} expected. No exception thrown.", typeof(TException).Name);
            }
            catch (TException ex)
            {
                if (possibleMessages != null && possibleMessages.Length > 0)
                {
                    bool match = false;
                    foreach (string possibleMessage in possibleMessages)
                    {
                        if (StringAssert.Equals(possibleMessage, ex.Message))
                        {
                            match = true;
                            break;
                        }
                    }

                    if (!match)
                    {
                        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, 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(ICollection <string> oneOfExpected, string actual)
        {
            bool match = oneOfExpected.Any(s => s == actual);

            if (!match)
            {
                Assert.Fail("Could not find match for actual value: {0}", actual);
            }
        }
コード例 #3
0
        public void RegisterLicense_Sample()
        {
            try
            {
                string licenseKey = "your-license-key";

                License.RegisterLicense(licenseKey);
            }
            catch (JSchemaException)
            {
                return;
            }

            Assert.Fail();
        }
コード例 #4
0
        private void GenerateSchemaAndSerializeFromType <T>(T value)
        {
            LicenseHelpers.ResetCounts(null);

            JSchemaGenerator generator = new JSchemaGenerator();

            generator.SchemaIdGenerationHandling = SchemaIdGenerationHandling.AssemblyQualifiedName;
            JSchema typeSchema = generator.Generate(typeof(T));
            string  schema     = typeSchema.ToString();

            string json  = JsonConvert.SerializeObject(value, Formatting.Indented);
            JToken token = JToken.ReadFrom(new JsonTextReader(new StringReader(json)));

            List <string> errors = new List <string>();

            token.Validate(typeSchema, (sender, args) => { errors.Add(args.Message); });

            if (errors.Count > 0)
            {
                Assert.Fail("Schema generated for type '{0}' is not valid." + Environment.NewLine + string.Join(Environment.NewLine, errors.ToArray()), typeof(T));
            }
        }