<commit_before>﻿using Ploeh.AutoFixture;
using Ploeh.AutoFixture.Idioms;
using Ploeh.AutoFixture.Xunit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Extensions;

namespace Grean.AtomEventStore.UnitTests
{
    public class TypeResolutionTableTests
    {
        [Fact]
        public void SutIsTypeResolver()
        {
            var sut = new TypeResolutionTable();
            Assert.IsAssignableFrom<ITypeResolver>(sut);
        }

        [Theory, AutoAtomData]
        public void VerifyGuardClauses(GuardClauseAssertion assertion)
        {
            assertion.Verify(typeof(TypeResolutionTable));
        }

        [Theory, AutoAtomData]
        public void EntriesIsCorrectWhenInitializedWithArray(
            [Frozen]TypeResolutionEntry[] expected,
            [FavorArrays]TypeResolutionTable sut)
        {
            var actual = sut.Entries;
            Assert.True(expected.SequenceEqual(actual));
        }

        [Theory, AutoAtomData]
        public void EntriesIsCorrectWhenInitializedWithEnumerable(
            [Frozen]IReadOnlyCollection<TypeResolutionEntry> expected,
            [FavorEnumerables]TypeResolutionTable sut)
        {
            var actual = sut.Entries;
            Assert.True(expected.SequenceEqual(actual));
        }

        [Theory, AutoAtomData]
        public void ResolveReturnsCorrectResult(
            [FavorArrays]TypeResolutionTable sut)
        {
            var entry = sut.Entries.ToArray().PickRandom();
            var expected = entry.ResolvedType;

            var actual = sut.Resolve(entry.LocalName, entry.XmlNamespace);

            Assert.Equal(expected, actual);
        }

        [Theory, AutoAtomData]
        public void ResolveThrowsWhenInputCanNotBeMappedToProperType(
            TypeResolutionTable sut)
        {
            var dummyType = typeof(Version);
            var notMapped =
                new TypeResolutionEntry("not", "mapped", dummyType);
            Assert.False(sut.Entries.Any(x =>
                x.LocalName == notMapped.LocalName &&
                x.XmlNamespace == notMapped.XmlNamespace));

            Assert.Throws<ArgumentException>(() =>
                sut.Resolve(notMapped.LocalName, notMapped.XmlNamespace));
        }
    }
}<commit_msg>Added a test case, asking for an unmapped local name and a mapped XML namespace.<commit_after>﻿using Ploeh.AutoFixture;
using Ploeh.AutoFixture.Idioms;
using Ploeh.AutoFixture.Xunit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Extensions;

namespace Grean.AtomEventStore.UnitTests
{
    public class TypeResolutionTableTests
    {
        [Fact]
        public void SutIsTypeResolver()
        {
            var sut = new TypeResolutionTable();
            Assert.IsAssignableFrom<ITypeResolver>(sut);
        }

        [Theory, AutoAtomData]
        public void VerifyGuardClauses(GuardClauseAssertion assertion)
        {
            assertion.Verify(typeof(TypeResolutionTable));
        }

        [Theory, AutoAtomData]
        public void EntriesIsCorrectWhenInitializedWithArray(
            [Frozen]TypeResolutionEntry[] expected,
            [FavorArrays]TypeResolutionTable sut)
        {
            var actual = sut.Entries;
            Assert.True(expected.SequenceEqual(actual));
        }

        [Theory, AutoAtomData]
        public void EntriesIsCorrectWhenInitializedWithEnumerable(
            [Frozen]IReadOnlyCollection<TypeResolutionEntry> expected,
            [FavorEnumerables]TypeResolutionTable sut)
        {
            var actual = sut.Entries;
            Assert.True(expected.SequenceEqual(actual));
        }

        [Theory, AutoAtomData]
        public void ResolveReturnsCorrectResult(
            [FavorArrays]TypeResolutionTable sut)
        {
            var entry = sut.Entries.ToArray().PickRandom();
            var expected = entry.ResolvedType;

            var actual = sut.Resolve(entry.LocalName, entry.XmlNamespace);

            Assert.Equal(expected, actual);
        }

        [Theory, AutoAtomData]
        public void ResolveThrowsWhenInputCanNotBeMappedToProperType(
            TypeResolutionTable sut)
        {
            var dummyType = typeof(Version);
            var notMapped =
                new TypeResolutionEntry("not", "mapped", dummyType);
            Assert.False(sut.Entries.Any(x =>
                x.LocalName == notMapped.LocalName &&
                x.XmlNamespace == notMapped.XmlNamespace));

            Assert.Throws<ArgumentException>(() =>
                sut.Resolve(notMapped.LocalName, notMapped.XmlNamespace));
        }

        [Theory, AutoAtomData]
        public void ResolveThrowsForUnmappedLocalNameAndMappedXmlNamespace(
            [FavorArrays]TypeResolutionTable sut)
        {
            var dummyType = typeof(Version);
            var notMapped =
                new TypeResolutionEntry("not", "mapped", dummyType);
            Assert.False(sut.Entries.Any(x =>
                x.LocalName == notMapped.LocalName &&
                x.XmlNamespace == notMapped.XmlNamespace));
            var mapped = sut.Entries.ToArray().PickRandom();

            Assert.Throws<ArgumentException>(() =>
                sut.Resolve(notMapped.LocalName, mapped.XmlNamespace));
        }
    }
}
{'fraction_non_alphanumeric': 0.0865561694290976, 'fraction_numerical': 0.0, 'mean_word_length': 2.2855414398064124, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 16, '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': '130675', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1470, 'n_words': 261}