Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Add multi-single mapping test touch #179
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Jul 17, 2016
1 parent 207c8d0 commit 81e60f1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/Our.Umbraco.Ditto.Tests/SingularityMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Our.Umbraco.Ditto.Tests
{
using System.Collections.Generic;

[TestFixture]
[Category("Mapping")]
public class SingularityMappingTests
Expand All @@ -14,6 +16,14 @@ public class MyModel
public IPublishedContent MyProperty { get; set; }
}

public class MyModel2
{
public IEnumerable<IPublishedContent> MyProperty { get; set; }
}

/// <summary>
/// Tests to ensure that collections of items are correctly mapped to a single item.
/// </summary>
[Test]
public void Single_PublishedContent_Mapped_From_Collection()
{
Expand All @@ -36,5 +46,31 @@ public void Single_PublishedContent_Mapped_From_Collection()
Assert.That(model.MyProperty, Is.Not.Null);
Assert.That(model.MyProperty, Is.InstanceOf<IPublishedContent>());
}

/// <summary>
/// Tests to ensure that single items are correctly mapped to an enumerable.
/// </summary>
[Test]
public void Collection_PublishedContent_Mapped_From_Single()
{
// make a content node
var item = new MockPublishedContent();

// set the item to a content node's property
var content = new MockPublishedContent
{
Properties = new[] { new MockPublishedContentProperty("myProperty", item) }
};

// map the content node to our model
var model = content.As<MyModel2>();

// check that the model is valid and the property contains a collection (not a single item)
Assert.That(model, Is.Not.Null);
Assert.That(model, Is.TypeOf<MyModel2>());

Assert.That(model.MyProperty, Is.Not.Null);
Assert.That(model.MyProperty, Is.InstanceOf<IEnumerable<IPublishedContent>>());
}
}
}

0 comments on commit 81e60f1

Please sign in to comment.