<commit_before>﻿namespace Sitecore.FakeDb.Tests.Links
{
  using FluentAssertions;
  using NSubstitute;
  using Sitecore.Data;
  using Sitecore.Data.Items;
  using Sitecore.FakeDb.Data.Items;
  using Sitecore.FakeDb.Links;
  using Sitecore.Links;
  using Xunit;

  public class FakeLinkDatabaseTest
  {
    private readonly LinkDatabase behavior;

    private readonly FakeLinkDatabase linkDatabase;

    private readonly Database database = Database.GetDatabase("master");

    private readonly Item item;

    private readonly ItemLink[] links = new ItemLink[0];

    public FakeLinkDatabaseTest()
    {
      this.item = ItemHelper.CreateInstance(this.database);

      this.behavior = Substitute.For<LinkDatabase>();
      this.linkDatabase = new FakeLinkDatabase();
      this.linkDatabase.LocalProvider.Value = this.behavior;
    }

    [Fact]
    public void ShouldReturnEmptyValuesWithoutBehaviorSet()
    {
      // arrange
      var stubLinkDatabase = new FakeLinkDatabase();

      // act & assert
      Assert.DoesNotThrow(() => stubLinkDatabase.Compact(null));
      stubLinkDatabase.GetBrokenLinks(null).Should().BeEmpty();
      stubLinkDatabase.GetReferenceCount(null).Should().Be(0);
      stubLinkDatabase.GetReferences(null).Should().BeEmpty();
      stubLinkDatabase.GetItemReferences(null, false).Should().BeEmpty();
      stubLinkDatabase.GetReferrerCount(null).Should().Be(0);
      stubLinkDatabase.GetReferrers(null).Should().BeEmpty();
      stubLinkDatabase.GetReferrers(null, null).Should().BeEmpty();
      stubLinkDatabase.GetItemReferrers(null, false).Should().BeEmpty();
      stubLinkDatabase.GetItemVersionReferrers(null).Should().BeEmpty();
      stubLinkDatabase.GetReferrers(null, false).Should().BeEmpty();
      stubLinkDatabase.HasExternalReferrers(null, false).Should().BeFalse();
      Assert.DoesNotThrow(() => stubLinkDatabase.Rebuild(null));
      Assert.DoesNotThrow(() => stubLinkDatabase.RemoveReferences(null));
      Assert.DoesNotThrow(() => stubLinkDatabase.UpdateItemVersionReferences(null));
      Assert.DoesNotThrow(() => stubLinkDatabase.UpdateReferences(null));
    }

    [Fact]
    public void ShouldSetBehaviour()
    {
      // assert
      this.linkDatabase.LocalProvider.Value.Should().BeSameAs(this.behavior);
    }

    [Fact]
    public void ShouldCallCompact()
    {
      // act
      this.linkDatabase.Compact(this.database);

      // assert
      this.behavior.Received().Compact(this.database);
    }

    [Fact]
    public void ShouldGetBrokenLinks()
    {
      // arrange
      this.behavior.GetBrokenLinks(this.database).Returns(this.links);

      // act & assert
      this.linkDatabase.GetBrokenLinks(this.database).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetReferenceCount()
    {
      this.behavior.GetReferenceCount(this.item).Returns(1);

      // act
      this.linkDatabase.GetReferenceCount(this.item).Should().Be(1);
    }

    [Fact]
    public void ShouldGetReferences()
    {
      // arrange
      this.behavior.GetReferences(this.item).Returns(this.links);

      // act & assert
      this.linkDatabase.GetReferences(this.item).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetItemReferences()
    {
      // arrange
      this.behavior.GetItemReferences(this.item, false).Returns(this.links);

      // act & assert
      this.linkDatabase.GetItemReferences(this.item, false).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetReferrerCount()
    {
      this.behavior.GetReferrerCount(this.item).Returns(1);

      // act
      this.linkDatabase.GetReferrerCount(this.item).Should().Be(1);
    }

    [Fact]
    public void ShouldGetReferrers()
    {
      // arrange
      this.behavior.GetReferrers(this.item).Returns(this.links);

      // act & assert
      this.linkDatabase.GetReferrers(this.item).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetReferrersByFieldId()
    {
      // arrange
      this.behavior.GetReferrers(this.item, ID.Null).Returns(this.links);

      // act & assert
      this.linkDatabase.GetReferrers(this.item, ID.Null).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetItemReferrers()
    {
      // arrange
      this.behavior.GetItemReferrers(this.item, false).Returns(this.links);

      // act & assert
      this.linkDatabase.GetItemReferrers(this.item, false).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetItemVersionReferrers()
    {
      // arrange
      this.behavior.GetItemVersionReferrers(this.item).Returns(this.links);

      // act & assert
      this.linkDatabase.GetItemVersionReferrers(this.item).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetReferrersDeep()
    {
      // arrange
      this.behavior.GetReferrers(this.item, false).Returns(this.links);

      // act & assert
      this.linkDatabase.GetReferrers(this.item, false).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldCallHasExternalReferrers()
    {
      // arrange
      this.behavior.HasExternalReferrers(this.item, false).Returns(true);

      // act & assert
      this.linkDatabase.HasExternalReferrers(this.item, false).Should().BeTrue();
    }
<commit_msg>Fixed annoying warnings<commit_after>﻿namespace Sitecore.FakeDb.Tests.Links
{
  using FluentAssertions;
  using NSubstitute;
  using Sitecore.Data;
  using Sitecore.Data.Items;
  using Sitecore.FakeDb.Data.Items;
  using Sitecore.FakeDb.Links;
  using Sitecore.Links;
  using System;
  using Xunit;

  public class FakeLinkDatabaseTest
  {
    private readonly LinkDatabase behavior;

    private readonly FakeLinkDatabase linkDatabase;

    private readonly Database database = Database.GetDatabase("master");

    private readonly Item item;

    private readonly ItemLink[] links = new ItemLink[0];

    public FakeLinkDatabaseTest()
    {
      this.item = ItemHelper.CreateInstance(this.database);

      this.behavior = Substitute.For<LinkDatabase>();
      this.linkDatabase = new FakeLinkDatabase();
      this.linkDatabase.LocalProvider.Value = this.behavior;
    }

    [Fact]
    public void ShouldReturnEmptyValuesWithoutBehaviorSet()
    {
      // arrange
      var stubLinkDatabase = new FakeLinkDatabase();

      // act & assert
      Assert.DoesNotThrow(() => stubLinkDatabase.Compact(null));
      stubLinkDatabase.GetBrokenLinks(null).Should().BeEmpty();
      stubLinkDatabase.GetReferenceCount(null).Should().Be(0);
      stubLinkDatabase.GetReferences(null).Should().BeEmpty();
      stubLinkDatabase.GetItemReferences(null, false).Should().BeEmpty();
      stubLinkDatabase.GetReferrerCount(null).Should().Be(0);
      stubLinkDatabase.GetReferrers(null).Should().BeEmpty();
      stubLinkDatabase.GetReferrers(null, null).Should().BeEmpty();
      stubLinkDatabase.GetItemReferrers(null, false).Should().BeEmpty();
      stubLinkDatabase.GetItemVersionReferrers(null).Should().BeEmpty();
      stubLinkDatabase.GetReferrers(null).Should().BeEmpty();
      stubLinkDatabase.HasExternalReferrers(null, false).Should().BeFalse();
      Assert.DoesNotThrow(() => stubLinkDatabase.Rebuild(null));
      Assert.DoesNotThrow(() => stubLinkDatabase.RemoveReferences(null));
      Assert.DoesNotThrow(() => stubLinkDatabase.UpdateItemVersionReferences(null));
      Assert.DoesNotThrow(() => stubLinkDatabase.UpdateReferences(null));
    }

    [Fact]
    public void ShouldSetBehaviour()
    {
      // assert
      this.linkDatabase.LocalProvider.Value.Should().BeSameAs(this.behavior);
    }

    [Fact]
    public void ShouldCallCompact()
    {
      // act
      this.linkDatabase.Compact(this.database);

      // assert
      this.behavior.Received().Compact(this.database);
    }

    [Fact]
    public void ShouldGetBrokenLinks()
    {
      // arrange
      this.behavior.GetBrokenLinks(this.database).Returns(this.links);

      // act & assert
      this.linkDatabase.GetBrokenLinks(this.database).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetReferenceCount()
    {
      this.behavior.GetReferenceCount(this.item).Returns(1);

      // act
      this.linkDatabase.GetReferenceCount(this.item).Should().Be(1);
    }

    [Fact]
    public void ShouldGetReferences()
    {
      // arrange
      this.behavior.GetReferences(this.item).Returns(this.links);

      // act & assert
      this.linkDatabase.GetReferences(this.item).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetItemReferences()
    {
      // arrange
      this.behavior.GetItemReferences(this.item, false).Returns(this.links);

      // act & assert
      this.linkDatabase.GetItemReferences(this.item, false).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetReferrerCount()
    {
      this.behavior.GetReferrerCount(this.item).Returns(1);

      // act
      this.linkDatabase.GetReferrerCount(this.item).Should().Be(1);
    }

    [Fact]
    public void ShouldGetReferrers()
    {
      // arrange
      this.behavior.GetReferrers(this.item).Returns(this.links);

      // act & assert
      this.linkDatabase.GetReferrers(this.item).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetReferrersByFieldId()
    {
      // arrange
      this.behavior.GetReferrers(this.item, ID.Null).Returns(this.links);

      // act & assert
      this.linkDatabase.GetReferrers(this.item, ID.Null).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetItemReferrers()
    {
      // arrange
      this.behavior.GetItemReferrers(this.item, false).Returns(this.links);

      // act & assert
      this.linkDatabase.GetItemReferrers(this.item, false).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldGetItemVersionReferrers()
    {
      // arrange
      this.behavior.GetItemVersionReferrers(this.item).Returns(this.links);

      // act & assert
      this.linkDatabase.GetItemVersionReferrers(this.item).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    [Obsolete]
    public void ShouldGetReferrersDeep()
    {
      // arrange
      this.behavior.GetReferrers(this.item, false).Returns(this.links);

      // act & assert
      this.linkDatabase.GetReferrers(this.item, false).ShouldBeEquivalentTo(this.links);
    }

    [Fact]
    public void ShouldCallHasExternalReferrers()
    {
      // arrange
      this.behavior.HasExternalReferrers(this.item, false).Returns(true);

      // act & assert
      this.linkDatabase.HasExternalReferrers(this.item, false).Should().BeTrue();
    }

{'fraction_non_alphanumeric': 0.12251033446072905, 'fraction_numerical': 0.0013152950018789928, 'mean_word_length': 3.1925955100433243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '978012', 'n_tokens_mistral': 3276, 'n_tokens_neox': 3123, 'n_words': 426}