Skip to content

Commit

Permalink
Fix LinkIt.Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentlbm-rc committed Dec 18, 2017
1 parent f3e3cc8 commit 16d58fc
Show file tree
Hide file tree
Showing 54 changed files with 1,852 additions and 1,461 deletions.
16 changes: 16 additions & 0 deletions LinkIt.TestHelpers/ContentContextualization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#region copyrigh// Copyright (c) CBC/Radio-Canada. All rights reserved.

// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#endregion


namespace LinkIt.TestHelpers
{
public class ContentContextualization
{
public string ContentType { get; set; }
public object Id { get; set; }
public string Title { get; set; }
}
}
16 changes: 16 additions & 0 deletions LinkIt.TestHelpers/ImageWithContextualizationLinkedSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#region copyrigh// Copyright (c) CBC/Radio-Canada. All rights reserved.

// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#endregion

using LinkIt.PublicApi;

namespace LinkIt.TestHelpers
{
public class ImageWithContextualizationLinkedSource : IPolymorphicSource, ILinkedSource<Image>
{
public ContentContextualization ContentContextualization { get; set; }
public Image Model { get; set; }
}
}
9 changes: 9 additions & 0 deletions LinkIt.TestHelpers/NestedContent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace LinkIt.TestHelpers
{
public class NestedContent
{
public int Id { get; set; }
public string AuthorDetailId { get; set; }
public string ClientSummaryId { get; set; }
}
}
11 changes: 11 additions & 0 deletions LinkIt.TestHelpers/NestedLinkedSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using LinkIt.PublicApi;

namespace LinkIt.TestHelpers
{
public class NestedLinkedSource : ILinkedSource<NestedContent>
{
public PersonLinkedSource AuthorDetail { get; set; }
public Person ClientSummary { get; set; }
public NestedContent Model { get; set; }
}
}
10 changes: 10 additions & 0 deletions LinkIt.TestHelpers/PersonLinkedSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using LinkIt.PublicApi;

namespace LinkIt.TestHelpers
{
public class PersonLinkedSource : ILinkedSource<Person>
{
public Image SummaryImage { get; set; }
public Person Model { get; set; }
}
}
109 changes: 44 additions & 65 deletions LinkIt.Tests/Core/Exploratory/ContextualizationByIdTests.cs
Original file line number Diff line number Diff line change
@@ -1,92 +1,71 @@
using ApprovalTests.Reporters;
using LinkIt.ConfigBuilders;
using LinkIt.ConfigBuilders;
using LinkIt.PublicApi;
using LinkIt.Tests.TestHelpers;
using NUnit.Framework;
using LinkIt.TestHelpers;
using Xunit;

namespace LinkIt.Tests.Core.Exploratory {
public class ContextualizationByIdTests{
private ILoadLinkProtocol _sut;

[SetUp]
public void SetUp() {
namespace LinkIt.Tests.Core.Exploratory
{
public class ContextualizationByIdTests
{
public ContextualizationByIdTests()
{
var loadLinkProtocolBuilder = new LoadLinkProtocolBuilder();
loadLinkProtocolBuilder.For<WithContextualizedReferenceLinkedSource>()
.LoadLinkNestedLinkedSourceById(
linkedSource => linkedSource.Model.PersonContextualization.Id,
linkedSource => linkedSource.Person,
(linkedSource, childLinkedSource) =>
(linkedSource, childLinkedSource) =>
childLinkedSource.Contextualization = linkedSource.Model.PersonContextualization
);
loadLinkProtocolBuilder.For<PersonContextualizedLinkedSource>()
.LoadLinkReferenceById(
linkedSource =>
linkedSource.Contextualization.SummaryImageId ??
linkedSource =>
linkedSource.Contextualization.SummaryImageId ??
linkedSource.Model.SummaryImageId,
linkedSource => linkedSource.SummaryImage
);
linkedSource => linkedSource.SummaryImage);

_sut = loadLinkProtocolBuilder.Build(() => new ReferenceLoaderStub());
}

private readonly ILoadLinkProtocol _sut;

[Fact]
public void LoadLink_WithoutContextualization_ShouldLinkDefaultImage()
public void LoadLink_WithContextualization_ShouldLinkOverriddenImage()
{
var actual = _sut.LoadLink<WithContextualizedReferenceLinkedSource>().FromModel(
new WithContextualizedReference {
Id = "1",
PersonContextualization = new PersonContextualization {
Id = "32",
Name = "Altered named",
SummaryImageId = null
}
var model = new WithContextualizedReference
{
Id = "1",
PersonContextualization = new PersonContextualization
{
Id = "32",
Name = "Altered named",
SummaryImageId = "overriden-image"
}
);
};
var actual = _sut.LoadLink<WithContextualizedReferenceLinkedSource>().FromModel(model);

Assert.That(actual.Person.Contextualization.SummaryImageId, Is.Null);
Assert.That(actual.Person.SummaryImage.Id, Is.EqualTo("person-img-32"));
Assert.Same(model.PersonContextualization, actual.Person.Contextualization);
Assert.Equal(model.PersonContextualization.Id, actual.Person.Model.Id);
Assert.Same(model.PersonContextualization.SummaryImageId, actual.Person.SummaryImage.Id);
}

[Fact]
public void LoadLink_WithContextualization_ShouldLinkOverriddenImage() {
var actual = _sut.LoadLink<WithContextualizedReferenceLinkedSource>().FromModel(
new WithContextualizedReference {
Id = "1",
PersonContextualization = new PersonContextualization {
Id = "32",
Name = "Altered named",
SummaryImageId = "overriden-image"
}
public void LoadLink_WithoutContextualization_ShouldLinkDefaultImage()
{
var model = new WithContextualizedReference
{
Id = "1",
PersonContextualization = new PersonContextualization
{
Id = "32",
Name = "Altered named",
SummaryImageId = null
}
);
};
var actual = _sut.LoadLink<WithContextualizedReferenceLinkedSource>().FromModel(model);

Assert.That(actual.Person.Contextualization.SummaryImageId, Is.EqualTo("overriden-image"));
Assert.That(actual.Person.SummaryImage.Id, Is.EqualTo("overriden-image"));
Assert.Same(model.PersonContextualization, actual.Person.Contextualization);
Assert.Equal($"person-img-{model.PersonContextualization.Id}", actual.Person.SummaryImage.Id);
}

}

public class WithContextualizedReferenceLinkedSource : ILinkedSource<WithContextualizedReference>
{
public WithContextualizedReference Model { get; set; }
public PersonContextualizedLinkedSource Person { get; set; }
}

public class PersonContextualizedLinkedSource: ILinkedSource<Person>
{
public Person Model { get; set; }
public PersonContextualization Contextualization { get; set; }
public Image SummaryImage { get; set; }
}

public class WithContextualizedReference {
public string Id { get; set; }
public PersonContextualization PersonContextualization { get; set; }
}

public class PersonContextualization{
public string Id { get; set; }
public string Name { get; set; }
public string SummaryImageId { get; set; }
}
}
}
91 changes: 49 additions & 42 deletions LinkIt.Tests/Core/Exploratory/ContextualizationFromModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,87 +1,94 @@
using ApprovalTests.Reporters;
using LinkIt.ConfigBuilders;
using LinkIt.ConfigBuilders;
using LinkIt.PublicApi;
using LinkIt.Tests.TestHelpers;
using NUnit.Framework;
using LinkIt.TestHelpers;
using Xunit;

namespace LinkIt.Tests.Core.Exploratory {
public class ContextualizationFromModelTests {
private ILoadLinkProtocol _sut;

[SetUp]
public void SetUp() {
namespace LinkIt.Tests.Core.Exploratory
{
public class ContextualizationFromModelTests
{
public ContextualizationFromModelTests()
{
var loadLinkProtocolBuilder = new LoadLinkProtocolBuilder();
loadLinkProtocolBuilder.For<LinkedSource>()
.LoadLinkNestedLinkedSourceFromModel(
linkedSource => linkedSource.Model.Person,
linkedSource => linkedSource.Person,
(linkedSource, childLinkedSource) =>
(linkedSource, childLinkedSource) =>
childLinkedSource.Contextualization = linkedSource.Model.PersonContextualization
);
loadLinkProtocolBuilder.For<PersonContextualizedLinkedSource>()
.LoadLinkReferenceById(
linkedSource =>
linkedSource.Contextualization?.SummaryImageId ??
linkedSource =>
linkedSource.Contextualization?.SummaryImageId ??
linkedSource.Model.SummaryImageId,
linkedSource => linkedSource.SummaryImage
);
linkedSource => linkedSource.SummaryImage);

_sut = loadLinkProtocolBuilder.Build(() => new ReferenceLoaderStub());
}

private readonly ILoadLinkProtocol _sut;

public class LinkedSource : ILinkedSource<Model>
{
public PersonContextualizedLinkedSource Person { get; set; }
public Model Model { get; set; }
}

public class Model
{
public Person Person { get; set; }
public PersonContextualization PersonContextualization { get; set; }
}

[Fact]
public void LoadLink_WithoutContextualization_ShouldLinkDefaultImage()
public void LoadLink_WithContextualization_ShouldLinkOverriddenImage()
{
var actual = _sut.LoadLink<LinkedSource>().FromModel(
new Model {
Person = new Person {
new Model
{
Person = new Person
{
Id = "32",
Name = "dont-care",
SummaryImageId = "defaultSummaryImageId"
},
PersonContextualization = new PersonContextualization {
PersonContextualization = new PersonContextualization
{
Id = "32",
Name = "dont-care",
SummaryImageId = null
SummaryImageId = "overriddenSummaryImageId"
}
}
);

Assert.That(actual.Person.Contextualization.SummaryImageId, Is.Null);
Assert.That(actual.Person.SummaryImage.Id, Is.EqualTo("defaultSummaryImageId"));
Assert.Equal("overriddenSummaryImageId", actual.Person.Contextualization.SummaryImageId);
Assert.Equal("overriddenSummaryImageId", actual.Person.SummaryImage.Id);
}

[Fact]
public void LoadLink_WithContextualization_ShouldLinkOverriddenImage() {
public void LoadLink_WithoutContextualization_ShouldLinkDefaultImage()
{
var actual = _sut.LoadLink<LinkedSource>().FromModel(
new Model {
Person = new Person {
new Model
{
Person = new Person
{
Id = "32",
Name = "dont-care",
SummaryImageId = "defaultSummaryImageId"
},
PersonContextualization = new PersonContextualization {
PersonContextualization = new PersonContextualization
{
Id = "32",
Name = "dont-care",
SummaryImageId = "overriddenSummaryImageId"
SummaryImageId = null
}
}
);

Assert.That(actual.Person.Contextualization.SummaryImageId, Is.EqualTo("overriddenSummaryImageId"));
Assert.That(actual.Person.SummaryImage.Id, Is.EqualTo("overriddenSummaryImageId"));
}

public class LinkedSource : ILinkedSource<Model> {
public Model Model { get; set; }
public PersonContextualizedLinkedSource Person { get; set; }
}

public class Model {
public Person Person { get; set; }
public PersonContextualization PersonContextualization { get; set; }
Assert.Null(actual.Person.Contextualization.SummaryImageId);
Assert.Equal("defaultSummaryImageId", actual.Person.SummaryImage.Id);
}
}


}
}
Loading

0 comments on commit 16d58fc

Please sign in to comment.