<commit_before>﻿namespace Sitecore.FakeDb.Tests
{
  using System.Linq;
  using FluentAssertions;
  using Sitecore.Data;
  using Xunit;

  public class DbTemplateTest
  {
    [Fact]
    public void ShouldBeAnItem()
    {
      // arrange
      var template = new DbTemplate();

      // assert
      template.Should().BeAssignableTo<DbItem>();
    }

    [Fact]
    public void ShouldInstantiateStandardValuesCollection()
    {
      // arrange & act
      var template = new DbTemplate();

      // assert
      template.StandardValues.Should().NotBeNull();
    }

    // TODO:[High] The test below states that we cannot get fake item fields by id.

    [Fact]
    public void ShouldCreateTemplateFieldsUsingNamesAsLowercaseKeys()
    {
      // arrange
      var template = new DbTemplate { "Title", "Description" };

      // assert
      template.Fields.Where(f => !f.Name.StartsWith("__")).Select(f => f.Name).ShouldBeEquivalentTo(new[] { "Title", "Description" });
    }

    [Fact]
    public void ShouldSetStandardValues()
    {
      // arrange & act
      var template = new DbTemplate { { "Title", "$name" } };

      // assert
      var id = template.Fields.Single(f => f.Name == "Title").ID;

      template.Fields[id].Value.Should().Be(string.Empty);
      template.StandardValues[id].Value.Should().Be("$name");
    }

    [Fact]
    public void ShouldAddFieldById()
    {
      // arrange
      var fieldId = ID.NewID;

      // act
      var template = new DbTemplate { fieldId };

      // assert
      template.Fields[fieldId].Should().NotBeNull();
      template.Fields[fieldId].Name.Should().Be(fieldId.ToShortID().ToString());
    }

    [Fact]
    public void ShouldAddStandardSharedFields()
    {
      // arrange & act
      var template = new DbTemplate();

      // assert
      template.Fields[FieldIDs.BaseTemplate].Shared.Should().BeTrue("__Base template");
      template.Fields[FieldIDs.Lock].Shared.Should().BeTrue("__Lock");
      template.Fields[FieldIDs.Security].Shared.Should().BeTrue("__Security");
    }
  }
}<commit_msg>Add Template.OwnFields test #44<commit_after>﻿namespace Sitecore.FakeDb.Tests
{
  using System.Linq;
  using FluentAssertions;
  using Sitecore.Data;
  using Xunit;

  public class DbTemplateTest
  {
    [Fact]
    public void ShouldBeAnItem()
    {
      // arrange
      var template = new DbTemplate();

      // assert
      template.Should().BeAssignableTo<DbItem>();
    }

    [Fact]
    public void ShouldInstantiateStandardValuesCollection()
    {
      // arrange & act
      var template = new DbTemplate();

      // assert
      template.StandardValues.Should().NotBeNull();
    }

    // TODO:[High] The test below states that we cannot get fake item fields by id.

    [Fact]
    public void ShouldCreateTemplateFieldsUsingNamesAsLowercaseKeys()
    {
      // arrange
      var template = new DbTemplate { "Title", "Description" };

      // assert
      template.Fields.Where(f => !f.Name.StartsWith("__")).Select(f => f.Name).ShouldBeEquivalentTo(new[] { "Title", "Description" });
    }

    [Fact]
    public void ShouldSetStandardValues()
    {
      // arrange & act
      var template = new DbTemplate { { "Title", "$name" } };

      // assert
      var id = template.Fields.Single(f => f.Name == "Title").ID;

      template.Fields[id].Value.Should().Be(string.Empty);
      template.StandardValues[id].Value.Should().Be("$name");
    }

    [Fact]
    public void ShouldAddFieldById()
    {
      // arrange
      var fieldId = ID.NewID;

      // act
      var template = new DbTemplate { fieldId };

      // assert
      template.Fields[fieldId].Should().NotBeNull();
      template.Fields[fieldId].Name.Should().Be(fieldId.ToShortID().ToString());
    }

    [Fact]
    public void ShouldAddStandardSharedFields()
    {
      // arrange & act
      var template = new DbTemplate();

      // assert
      template.Fields[FieldIDs.BaseTemplate].Shared.Should().BeTrue("__Base template");
      template.Fields[FieldIDs.Lock].Shared.Should().BeTrue("__Lock");
      template.Fields[FieldIDs.Security].Shared.Should().BeTrue("__Security");
    }

    [Fact]
    public void ShouldGetOwnFields()
    {
      // arrange
      var templateId = ID.NewID;

      using (var db = new Db
                        {
                          new DbTemplate(templateId) { "expected own field" },
                          new DbItem("home", ID.NewID, templateId)
                        })
      {
        var item = db.GetItem("/sitecore/content/home");

        // assert
        item.Template.OwnFields.Count().Should().Be(1, string.Join("\n\r", item.Template.OwnFields.Select(f => f.Name)));
        item.Template.OwnFields.Single().Name.Should().Be("expected own field");
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.13827781269641734, 'fraction_numerical': 0.0006285355122564425, 'mean_word_length': 2.4027084818246616, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '5516004', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1362, 'n_words': 276}