Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/PropertyCollectionTests.cs
Paul Johnson 00133e880d Move test projects from src/ to tests/ (#11357)
* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
2021-10-18 08:14:04 +01:00

95 lines
3.4 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Tests.Common.Builders;
using Umbraco.Cms.Tests.UnitTests.TestHelpers;
using Umbraco.Extensions;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models.Collections
{
[TestFixture]
public class PropertyCollectionTests
{
[Test]
public void Property_Adds_Case_Insensitive_Compare()
{
var collection = new PropertyCollection
{
new Property(new PropertyType(TestHelper.ShortStringHelper, "propEditor", ValueStorageType.Nvarchar, "test")),
new Property(new PropertyType(TestHelper.ShortStringHelper, "propEditor", ValueStorageType.Nvarchar, "Test"))
};
Assert.AreEqual(1, collection.Count);
}
[Test]
public void Property_Contains_Case_Insensitive_Compare()
{
var collection = new PropertyCollection
{
new Property(new PropertyType(TestHelper.ShortStringHelper, "propEditor", ValueStorageType.Nvarchar, "test"))
};
Assert.IsTrue(collection.Contains("Test"));
}
[Test]
public void SimpleOrder_Returns_Null_On_FirstOrDefault_When_Empty()
{
var orders = new SimpleOrder();
var item = orders.FirstOrDefault();
Assert.That(item == null, Is.True);
}
[Test]
public void PropertyCollection_Returns_Null_On_FirstOrDefault_When_Empty()
{
var list = new List<Property>();
var collection = new PropertyCollection(list);
var first = collection.FirstOrDefault();
var second = collection.FirstOrDefault(x => x.Alias.InvariantEquals("Test"));
Assert.That(first, Is.Null);
Assert.That(first == null, Is.True);
Assert.That(second == null, Is.True);
}
[Test]
public void PropertyTypeCollection_Returns_Null_On_FirstOrDefault_When_Empty()
{
var list = new List<PropertyType>();
var collection = new PropertyTypeCollection(false, list);
Assert.That(collection.FirstOrDefault(), Is.Null);
Assert.That(collection.FirstOrDefault(x => x.Alias.InvariantEquals("Test")) == null, Is.True);
}
[Test]
public void PropertyGroupCollection_Returns_Null_On_FirstOrDefault_When_Empty()
{
var list = new List<PropertyGroup>();
var collection = new PropertyGroupCollection(list);
Assert.That(collection.FirstOrDefault(), Is.Null);
Assert.That(collection.FirstOrDefault(x => x.Name.InvariantEquals("Test")) == null, Is.True);
}
[Test]
public void PropertyGroups_Collection_FirstOrDefault_Returns_Null()
{
var contentType = ContentTypeBuilder.CreateTextPageContentType();
Assert.That(contentType.PropertyGroups, Is.Not.Null);
Assert.That(contentType.PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals("Content")) == null, Is.False);
Assert.That(contentType.PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals("Test")) == null, Is.True);
Assert.That(contentType.PropertyGroups.Any(x => x.Name.InvariantEquals("Test")), Is.False);
}
}
}