<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq.Expressions;
using System.IO;

namespace Signum.Test
{
    public static class Assert2
    {
        //for MSTest
        public static void Throws<E>(Action action)
            where E : Exception
        {
            try
            {
                action();
            }
            catch (E)
            {
                return;
            }

            throw new AssertFailedException("No {0} has been thrown".FormatWith(typeof(E).Name));
        }

        public static void Throws<E>(string messageToContain, Action action)
           where E : Exception
        {
            try
            {
                action();
            }
            catch (E ex)
            {
                if(!ex.Message.Contains(messageToContain))
                    throw new AssertFailedException("No {0} has been thrown with message {0}".FormatWith(typeof(E).Name, ex.Message));

                return;
            }

            throw new AssertFailedException("No {0} has been thrown".FormatWith(typeof(E).Name));
        }

        public static void Throws<E>(Func<E, bool> exceptionCondition, Action action)
          where E : Exception
        {
            try
            {
                action();
            }
            catch (E ex)
            {
                if (!exceptionCondition(ex))
                    throw new AssertFailedException("No {0} has been thrown that satisfies the condition".FormatWith(typeof(E).Name));

                return;
            }

            throw new AssertFailedException("No {0} has been thrown".FormatWith(typeof(E).Name));
        }

        public static void AssertAll<T>(this IEnumerable<T> collection, Expression<Func<T, bool>> predicate)
        {
            var func = predicate.Compile();

            foreach (var item in collection)
            {
                if (!func(item))
                    Assert.Fail("'{0}' fails on '{1}'".FormatWith(item, predicate.ToString())); 
            }
        }

        public static void AssertContains<T>(this IEnumerable<T> collection, params T[] elements)
        {
            var hs = collection.ToHashSet();

            string notFound = elements.Where(a => !hs.Contains(a)).CommaAnd();

            if (notFound.HasText())
                Assert.Fail("{0} not found".FormatWith(notFound)); 
        }

        public static void AssertNotContains<T>(this IEnumerable<T> collection, params T[] elements)
        {
            var hs = collection.ToHashSet();

            string found = elements.Where(a => hs.Contains(a)).CommaAnd();

            if (found.HasText())
                Assert.Fail("{0}  found".FormatWith(found));
        }

        public static void AssertExactly<T>(this IEnumerable<T> collection, params T[] elements)
        {
            var hs = collection.ToHashSet();

            string notFound = elements.Where(a => !hs.Contains(a)).CommaAnd();
            string exceeded = hs.Where(a => !elements.Contains(a)).CommaAnd(); ;

            if (notFound.HasText() && exceeded.HasText())
                Assert.Fail("{0} not found and {1} exceeded".FormatWith(notFound, exceeded));

            if(notFound.HasText())
                Assert.Fail("{0} not found".FormatWith(notFound));

            if (exceeded.HasText())
                Assert.Fail("{0} exceeded".FormatWith(exceeded));

        }

        public static new bool Equals(object obj, object obj2)
        {
            throw new NotSupportedException("Use Assert.AreEquals instead");
        }

        //for NUnit
        public static void AreEqual<T>(T expected, T value, string message = null)
        {
            if ((expected == null && value != null) || !expected.Equals(value))
                throw new InvalidOperationException(message ?? "Expected is {0}, but value is {1}".FormatWith(expected.TryToString() ?? "null", value.TryToString() ?? "null"));
        }
    }
}<commit_msg>remove AreEqual<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq.Expressions;
using System.IO;

namespace Signum.Test
{
    public static class Assert2
    {
        //for MSTest
        public static void Throws<E>(Action action)
            where E : Exception
        {
            try
            {
                action();
            }
            catch (E)
            {
                return;
            }

            throw new AssertFailedException("No {0} has been thrown".FormatWith(typeof(E).Name));
        }

        public static void Throws<E>(string messageToContain, Action action)
           where E : Exception
        {
            try
            {
                action();
            }
            catch (E ex)
            {
                if(!ex.Message.Contains(messageToContain))
                    throw new AssertFailedException("No {0} has been thrown with message {0}".FormatWith(typeof(E).Name, ex.Message));

                return;
            }

            throw new AssertFailedException("No {0} has been thrown".FormatWith(typeof(E).Name));
        }

        public static void Throws<E>(Func<E, bool> exceptionCondition, Action action)
          where E : Exception
        {
            try
            {
                action();
            }
            catch (E ex)
            {
                if (!exceptionCondition(ex))
                    throw new AssertFailedException("No {0} has been thrown that satisfies the condition".FormatWith(typeof(E).Name));

                return;
            }

            throw new AssertFailedException("No {0} has been thrown".FormatWith(typeof(E).Name));
        }

        public static void AssertAll<T>(this IEnumerable<T> collection, Expression<Func<T, bool>> predicate)
        {
            var func = predicate.Compile();

            foreach (var item in collection)
            {
                if (!func(item))
                    Assert.Fail("'{0}' fails on '{1}'".FormatWith(item, predicate.ToString())); 
            }
        }

        public static void AssertContains<T>(this IEnumerable<T> collection, params T[] elements)
        {
            var hs = collection.ToHashSet();

            string notFound = elements.Where(a => !hs.Contains(a)).CommaAnd();

            if (notFound.HasText())
                Assert.Fail("{0} not found".FormatWith(notFound)); 
        }

        public static void AssertNotContains<T>(this IEnumerable<T> collection, params T[] elements)
        {
            var hs = collection.ToHashSet();

            string found = elements.Where(a => hs.Contains(a)).CommaAnd();

            if (found.HasText())
                Assert.Fail("{0}  found".FormatWith(found));
        }

        public static void AssertExactly<T>(this IEnumerable<T> collection, params T[] elements)
        {
            var hs = collection.ToHashSet();

            string notFound = elements.Where(a => !hs.Contains(a)).CommaAnd();
            string exceeded = hs.Where(a => !elements.Contains(a)).CommaAnd(); ;

            if (notFound.HasText() && exceeded.HasText())
                Assert.Fail("{0} not found and {1} exceeded".FormatWith(notFound, exceeded));

            if(notFound.HasText())
                Assert.Fail("{0} not found".FormatWith(notFound));

            if (exceeded.HasText())
                Assert.Fail("{0} exceeded".FormatWith(exceeded));

        }

        public static new bool Equals(object obj, object obj2)
        {
            throw new NotSupportedException("Use Assert.AreEquals instead");
        }
    }
}
{'fraction_non_alphanumeric': 0.11440623801610636, 'fraction_numerical': 0.004346158762623034, 'mean_word_length': 1.7725017717930547, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1642073', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1960, 'n_words': 496}