<commit_before>﻿// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this 
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

namespace ServiceStack.Documentation.Tests.Enrichers
{
    using System;
    using System.Reflection;
    using Documentation.Enrichers;
    using Documentation.XmlDocumentation;
    using FakeItEasy;
    using FluentAssertions;
    using Xunit;

    public class XmlEnricherTests
    {
        private readonly XmlEnricher nullEnricher = new XmlEnricher(null);
        private readonly IXmlDocumentationLookup lookup = A.Fake<IXmlDocumentationLookup>();
        private static readonly Type Type = typeof(TestClass);

        private XmlEnricher enricher => new XmlEnricher(lookup);

        private static PropertyInfo GetProperty() => Type.GetProperty("TheProp");

        [Fact]
        public void GetTitle_ReturnsNull_IfLookupNull() 
            => nullEnricher.GetTitle(Type).Should().BeNull();

        [Fact]
        public void GetTitle_ReturnsNull_IfMemberNotFound() 
            => enricher.GetTitle(Type).Should().BeNull();

        [Fact]
        public void GetTitle_ReturnsTitle_IfMemberFound()
        {
            const string name = "the sun smells too loud";
            A.CallTo(() => lookup.GetXmlMember(Type)).Returns(new XmlMember { Name = name });
            enricher.GetTitle(Type).Should().Be(name);
        }

        [Fact]
        public void GetDescription_ReturnsNull_IfLookupNull()
            => nullEnricher.GetDescription(Type).Should().BeNull();

        [Fact]
        public void GetDescription_ReturnsNull_IfMemberNotFound()
            => enricher.GetDescription(Type).Should().BeNull();

        [Fact]
        public void GetDescription_ReturnsNull_IfMemberFoundButSummaryNull()
        {
            A.CallTo(() => lookup.GetXmlMember(Type)).Returns(new XmlMember());
            enricher.GetDescription(Type).Should().BeNull();
        }

        [Fact]
        public void GetDescription_ReturnsDescription_IfMemberFound()
        {
            const string description = "mogwai fear satan";
            var summary = new XmlBase { Text = description };
            A.CallTo(() => lookup.GetXmlMember(Type)).Returns(new XmlMember { Summary = summary });
            enricher.GetDescription(Type).Should().Be(description);
        }

        [Fact]
        public void GetNotes_ReturnsNull_IfLookupNull() 
            => nullEnricher.GetNotes(Type).Should().BeNull();

        [Fact]
        public void GetNotes_ReturnsNull_IfMemberNotFound()
            => enricher.GetNotes(Type).Should().BeNull();

        [Fact]
        public void GetNotes_ReturnsNull_IfMemberFoundButRemarksNull()
        {
            A.CallTo(() => lookup.GetXmlMember(Type)).Returns(new XmlMember());
            enricher.GetNotes(Type).Should().BeNull();
        }

        [Fact]
        public void GetNotes_ReturnsDescription_IfMemberFound()
        {
            const string notes = "hunted by a freak";
            var remarks = new XmlBase { Text = notes };
            A.CallTo(() => lookup.GetXmlMember(Type)).Returns(new XmlMember { Remarks = remarks });
            enricher.GetNotes(Type).Should().Be(notes);
        }

        [Fact]
        public void GetDescription_PI_ReturnsNull_IfLookupNull()
            => nullEnricher.GetDescription(GetProperty()).Should().BeNull();

        [Fact]
        public void GetDescription_PI_ReturnsNull_IfMemberNotFound()
            => enricher.GetDescription(GetProperty()).Should().BeNull();

        [Fact]
        public void GetDescription_PI_ReturnsNull_IfMemberFoundButSummaryNull()
        {
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember());
            enricher.GetDescription(GetProperty()).Should().BeNull();
        }

        [Fact]
        public void GetDescription_PI_ReturnsDescription_IfSummaryFound()
        {
            const string description = "travel is dangerious";
            var summary = new XmlBase { Text = description };
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember { Summary = summary });
            enricher.GetDescription(GetProperty()).Should().Be(description);
        }

        [Fact]
        public void GetDescription_PI_ReturnsDescription_IfValueFound()
        {
            const string description = "travel is dangerious";
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember { Value = description });
            enricher.GetDescription(GetProperty()).Should().Be(description);
        }

        [Fact]
        public void GetDescription_PI_ReturnsDescription_IfSummaryAndValueFound()
        {
            const string value = "travel is dangerious";
            const string summary = "a brief history of seven killings";
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember
            {
                Value = value,
                Summary = new XmlBase { Text = summary }
            });
            enricher.GetDescription(GetProperty()).Should().Be($"{summary} {value}");
        }

        [Fact]
        public void GetNotes_PI_ReturnsNull_IfLookupNull() 
            => nullEnricher.GetNotes(GetProperty()).Should().BeNull();

        [Fact]
        public void GetNotes_PI_ReturnsNull_IfMemberNotFound()
            => enricher.GetNotes(GetProperty()).Should().BeNull();

        [Fact]
        public void GetNotes_PI_ReturnsNull_IfMemberFoundButRemarksNull()
        {
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember());
            enricher.GetNotes(GetProperty()).Should().BeNull();
        }

        [Fact]
        public void GetNotes_PI_ReturnsDescription_IfMemberFound()
        {
            const string notes = "how to be a werewolf";
            var remarks = new XmlBase { Text = notes };
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember { Remarks = remarks });
            enricher.GetNotes(GetProperty()).Should().Be(notes);
        }

        [Fact]
        public void GetTitle_PI_ReturnsNull_IfLookupNull()
            => nullEnricher.GetTitle(GetProperty()).Should().BeNull();

        [Fact]
        public void GetTitle_PI_ReturnsNull_IfMemberNotFound()
            => enricher.GetTitle(GetProperty()).Should().BeNull();

        [Fact]
        public void GetTitle_PI_ReturnsNull_IfMemberFoundButNameNull()
        {
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember());
            enricher.GetTitle(GetProperty()).Should().BeNull();
        }

        [Fact]
        public void GetTitle_PI_ReturnsDescription_IfMemberFound()
        {
            const string name = "mr November";
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember { Name = name });
            enricher.GetTitle(GetProperty()).Should().Be(name);
        }
    }

    public class TestClass
    {
        public string TheProp { get; set; }
    }
}<commit_msg>Updated tests to match new logic<commit_after>﻿// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this 
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

namespace ServiceStack.Documentation.Tests.Enrichers
{
    using System;
    using System.Reflection;
    using Documentation.Enrichers;
    using Documentation.XmlDocumentation;
    using FakeItEasy;
    using FluentAssertions;
    using Xunit;

    public class XmlEnricherTests
    {
        private readonly XmlEnricher nullEnricher = new XmlEnricher(null);
        private readonly IXmlDocumentationLookup lookup = A.Fake<IXmlDocumentationLookup>();
        private static readonly Type Type = typeof(TestClass);

        private XmlEnricher enricher => new XmlEnricher(lookup);

        private static PropertyInfo GetProperty() => Type.GetProperty("TheProp");

        [Fact]
        public void GetTitle_ReturnsNull_IfLookupNull() 
            => nullEnricher.GetTitle(Type).Should().BeNull();

        [Fact]
        public void GetTitle_ReturnsNull_IfMemberNotFound() 
            => enricher.GetTitle(Type).Should().BeNull();

        [Fact]
        public void GetTitle_ReturnsNull()
        {
            const string name = "the sun smells too loud";
            A.CallTo(() => lookup.GetXmlMember(Type)).Returns(new XmlMember { Name = name });
            enricher.GetTitle(Type).Should().BeNull();
        }

        [Fact]
        public void GetDescription_ReturnsNull_IfLookupNull()
            => nullEnricher.GetDescription(Type).Should().BeNull();

        [Fact]
        public void GetDescription_ReturnsNull_IfMemberNotFound()
            => enricher.GetDescription(Type).Should().BeNull();

        [Fact]
        public void GetDescription_ReturnsNull_IfMemberFoundButSummaryNull()
        {
            A.CallTo(() => lookup.GetXmlMember(Type)).Returns(new XmlMember());
            enricher.GetDescription(Type).Should().BeNull();
        }

        [Fact]
        public void GetDescription_ReturnsDescription_IfMemberFound()
        {
            const string description = "mogwai fear satan";
            var summary = new XmlBase { Text = description };
            A.CallTo(() => lookup.GetXmlMember(Type)).Returns(new XmlMember { Summary = summary });
            enricher.GetDescription(Type).Should().Be(description);
        }

        [Fact]
        public void GetNotes_ReturnsNull_IfLookupNull() 
            => nullEnricher.GetNotes(Type).Should().BeNull();

        [Fact]
        public void GetNotes_ReturnsNull_IfMemberNotFound()
            => enricher.GetNotes(Type).Should().BeNull();

        [Fact]
        public void GetNotes_ReturnsNull_IfMemberFoundButRemarksNull()
        {
            A.CallTo(() => lookup.GetXmlMember(Type)).Returns(new XmlMember());
            enricher.GetNotes(Type).Should().BeNull();
        }

        [Fact]
        public void GetNotes_ReturnsDescription_IfMemberFound()
        {
            const string notes = "hunted by a freak";
            var remarks = new XmlBase { Text = notes };
            A.CallTo(() => lookup.GetXmlMember(Type)).Returns(new XmlMember { Remarks = remarks });
            enricher.GetNotes(Type).Should().Be(notes);
        }

        [Fact]
        public void GetDescription_PI_ReturnsNull_IfLookupNull()
            => nullEnricher.GetDescription(GetProperty()).Should().BeNull();

        [Fact]
        public void GetDescription_PI_ReturnsNull_IfMemberNotFound()
            => enricher.GetDescription(GetProperty()).Should().BeNull();

        [Fact]
        public void GetDescription_PI_ReturnsNull_IfMemberFoundButSummaryNull()
        {
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember());
            enricher.GetDescription(GetProperty()).Should().BeNull();
        }

        [Fact]
        public void GetDescription_PI_ReturnsDescription_IfSummaryFound()
        {
            const string description = "travel is dangerious";
            var summary = new XmlBase { Text = description };
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember { Summary = summary });
            enricher.GetDescription(GetProperty()).Should().Be(description);
        }

        [Fact]
        public void GetDescription_PI_ReturnsDescription_IfValueFound()
        {
            const string description = "travel is dangerious";
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember { Value = description });
            enricher.GetDescription(GetProperty()).Should().Be(description);
        }

        [Fact]
        public void GetDescription_PI_ReturnsDescription_IfSummaryAndValueFound()
        {
            const string value = "travel is dangerious";
            const string summary = "a brief history of seven killings";
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember
            {
                Value = value,
                Summary = new XmlBase { Text = summary }
            });
            enricher.GetDescription(GetProperty()).Should().Be($"{summary} {value}");
        }

        [Fact]
        public void GetNotes_PI_ReturnsNull_IfLookupNull() 
            => nullEnricher.GetNotes(GetProperty()).Should().BeNull();

        [Fact]
        public void GetNotes_PI_ReturnsNull_IfMemberNotFound()
            => enricher.GetNotes(GetProperty()).Should().BeNull();

        [Fact]
        public void GetNotes_PI_ReturnsNull_IfMemberFoundButRemarksNull()
        {
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember());
            enricher.GetNotes(GetProperty()).Should().BeNull();
        }

        [Fact]
        public void GetNotes_PI_ReturnsDescription_IfMemberFound()
        {
            const string notes = "how to be a werewolf";
            var remarks = new XmlBase { Text = notes };
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember { Remarks = remarks });
            enricher.GetNotes(GetProperty()).Should().Be(notes);
        }

        [Fact]
        public void GetTitle_PI_ReturnsNull_IfLookupNull()
            => nullEnricher.GetTitle(GetProperty()).Should().BeNull();

        [Fact]
        public void GetTitle_PI_ReturnsNull_IfMemberNotFound()
            => enricher.GetTitle(GetProperty()).Should().BeNull();

        [Fact]
        public void GetTitle_PI_ReturnsNull_IfMemberFoundButNameNull()
        {
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember());
            enricher.GetTitle(GetProperty()).Should().BeNull();
        }

        [Fact]
        public void GetTitle_PI_ReturnsNull()
        {
            const string name = "mr November";
            A.CallTo(() => lookup.GetXmlMember(GetProperty())).Returns(new XmlMember { Name = name });
            enricher.GetTitle(GetProperty()).Should().BeNull();
        }
    }

    public class TestClass
    {
        public string TheProp { get; set; }
    }
}
{'fraction_non_alphanumeric': 0.11346817957572768, 'fraction_numerical': 0.0005638170413700754, 'mean_word_length': 2.4933530280649925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, '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': '3961738', 'n_tokens_mistral': 3842, 'n_tokens_neox': 3668, 'n_words': 725}