[<AutoOpen>]
module FSharpNews.Tests.Core.TypedAssertions

open System
open NUnit.Framework

// taken from ExtCore.Tests

/// Asserts that two values are equal.
let inline assertEqual<'T when 'T : equality> (expected : 'T) (actual : 'T) =
    Assert.AreEqual (expected, actual)

let assertEqualDateWithin (expected : DateTime) (within : TimeSpan) (actual : DateTime) =
    Assert.That(actual, Is.EqualTo(expected).Within(within))


/// Assertion functions for collections.
[<RequireQualifiedAccess>]
module Collection =
    open System.Collections

    /// Asserts that two collections are exactly equal.
    /// The collections must have the same count, and contain the exact same objects in the same order.
    let inline assertEqual<'T, 'U when 'T :> seq<'U>> (expected : 'T) (actual : 'T) =
        CollectionAssert.AreEqual (expected, actual)

    /// Asserts that two collections are not exactly equal.
    let inline assertNotEqual<'T, 'U when 'T :> seq<'U>> (expected : 'T) (actual : 'T) =
        CollectionAssert.AreNotEqual (expected, actual)

    /// Asserts that two collections are exactly equal.
    /// The collections must have the same count, and contain the exact same objects but the match may be in any order.
    let inline assertEquiv<'T, 'U when 'T :> seq<'U>> (expected : 'T) (actual : 'T) =
        CollectionAssert.AreEquivalent (expected, actual)

    /// Asserts that two collections are not exactly equal.
    let inline assertNotEquiv<'T, 'U when 'T :> seq<'U>> (expected : 'T) (actual : 'T) =
        CollectionAssert.AreNotEquivalent (expected, actual)

    let inline assertContains<'T, 'U when 'T :> seq<'U>> (expected: 'U) (collection: 'T) =
        CollectionAssert.Contains (collection, expected)

    let inline assertNotContains<'T, 'U when 'T :> seq<'U>> (expected: 'U) (collection: 'T) =
        CollectionAssert.DoesNotContain (collection, expected)
