Esempio n. 1
0
        public void StringHashHasBestDistributionWithTypeAssemblyQualifiedName()
        {
            var hashes = ExceptionTypes
                         .Select(EventLogAppender.TypeHashAlgorithm)
                         .ToArray();
            var computedHashesCount = hashes.Length;
            var uniqueHashesCount   = hashes.Distinct().Count();
            var hashCollisionsCount = computedHashesCount - uniqueHashesCount;
            var collisionPercentage = decimal.Divide(hashCollisionsCount, computedHashesCount) * 100;

            Assert.That(collisionPercentage, Is.LessThan(1.5));
        }
Esempio n. 2
0
        public void StringHashHasGoodDistributionWithTypeFullName()
        {
            EventLogAppender.TypeNameSelector = t => t.FullName;

            var hashes = ExceptionTypes
                         .Select(EventLogAppender.TypeHashAlgorithm)
                         .ToArray();
            var computedHashesCount = hashes.Length;
            var uniqueHashesCount   = hashes.Distinct().Count();
            var hashCollisionsCount = computedHashesCount - uniqueHashesCount;
            var collisionPercentage = decimal.Divide(hashCollisionsCount, computedHashesCount) * 100;

            Assert.That(collisionPercentage, Is.LessThan(21));
        }
        /// <summary>
        /// Verifies that the type of the exception thrown by the unit test is expected
        /// </summary>
        /// <param name="exception">The exception thrown by the unit test</param>
        protected override void Verify(Exception exception)
        {
            var seleniumException = exception as SeleniumTestFailedException;

            if (seleniumException != null)
            {
                if (AllowDerivedTypes)
                {
                    if (!seleniumException.InnerExceptions.All(s => ExceptionTypes.Any(n => n.IsInstanceOfType(s))))
                    {
                        RethrowIfAssertException(exception);
                        var exp = seleniumException.InnerExceptions
                                  .First(s => ExceptionTypes.Any(n => n.IsInstanceOfType(s)));
                        throw new Exception(string.Format((IFormatProvider)CultureInfo.CurrentCulture, $"Test method threw exception {exp.GetType()}, but exception {string.Join(", ", ExceptionTypes.Select(s => s.FullName))} was expected. Exception message: {exp.Message}"));
                    }
                }

                if (!seleniumException.InnerExceptions.All(s => ExceptionTypes.Any(n => s.GetType() == n)))
                {
                    RethrowIfAssertException(exception);
                    var exp = seleniumException.InnerExceptions.First(s => ExceptionTypes.Any(n => s.GetType() != n));
                    throw new Exception(string.Format((IFormatProvider)CultureInfo.CurrentCulture, $"Test method threw exception {exp.GetType()}, but exception {string.Join(", ", ExceptionTypes.Select(s => s.FullName))} was expected. Exception message: {exp.Message}"));
                }
            }
            else if (seleniumException == null && exception != null)
            {
                RethrowIfAssertException(exception);
                throw new Exception($"Test method threw exception {exception.GetType()}, but exception {string.Join(", ", ExceptionTypes.Select(s => s.FullName))} was expected. Exception message: {exception.Message}", exception);
            }
            else
            {
                RethrowIfAssertException(exception);
                throw new Exception(string.Format((IFormatProvider)CultureInfo.CurrentCulture, NoExceptionMessage ?? "Test method did not throw exception."));
            }
        }