public SingleValueLinkTargetTests() { _actual = new LinkedSource(); _sut = (SingleValueLinkTarget <LinkedSource, Image>)LinkTargetFactory.Create <LinkedSource, Image>( linkedSource => linkedSource.Image); }
/// <summary> /// Load and link polymorphic references or linked sources. /// </summary> public LoadLinkProtocolForLinkedSourceBuilder <TLinkedSource> LoadLinkPolymorphicList <TAbstractLinkTarget, TLink, TDiscriminant>( Func <TLinkedSource, IEnumerable <TLink> > getLinks, Expression <Func <TLinkedSource, List <TAbstractLinkTarget> > > getLinkTarget, Func <TLink, TDiscriminant> getDiscriminant, Action <IncludeSetBuilder <TLinkedSource, TAbstractLinkTarget, TLink, TDiscriminant> > includes, bool ignoreUnhandledCases = false) { if (getLinks == null) { throw new ArgumentNullException(nameof(getLinks)); } if (getLinkTarget == null) { throw new ArgumentNullException(nameof(getLinkTarget)); } if (getDiscriminant == null) { throw new ArgumentNullException(nameof(getDiscriminant)); } if (includes == null) { throw new ArgumentNullException(nameof(includes)); } return(LoadLinkPolymorphic( getLinks, LinkTargetFactory.Create(getLinkTarget), getDiscriminant, includes, ignoreUnhandledCases )); }
/// <summary> /// Load and link a polymorphic reference or linked source. /// </summary> public LoadLinkProtocolForLinkedSourceBuilder <TLinkedSource> LoadLinkPolymorphic <TAbstractLinkTarget, TLink, TDiscriminant>( Func <TLinkedSource, TLink> getLink, Expression <Func <TLinkedSource, TAbstractLinkTarget> > getLinkTarget, Func <TLink, TDiscriminant> getDiscriminant, Action <IncludeSetBuilder <TLinkedSource, TAbstractLinkTarget, TLink, TDiscriminant> > includes) { if (getLink == null) { throw new ArgumentNullException(nameof(getLink)); } if (getLinkTarget == null) { throw new ArgumentNullException(nameof(getLinkTarget)); } if (getDiscriminant == null) { throw new ArgumentNullException(nameof(getDiscriminant)); } if (includes == null) { throw new ArgumentNullException(nameof(includes)); } return(LoadLinkPolymorphic( ToGetLookupIdsForSingleValue(getLink), LinkTargetFactory.Create(getLinkTarget), getDiscriminant, includes )); }
public void Create_WithNestedGetter_ShouldThrow() { Action act = () => LinkTargetFactory.Create <ForLinkedTargetLinkedSource, string>( linkedSource => linkedSource.SummaryImage.Alt); var exception = Assert.Throws <LinkItException>(act); Assert.Contains("ForLinkedTargetLinkedSource", exception.Message); Assert.Contains("direct getter", exception.Message); }
public void Test_WithReadOnlyProperty_ShouldThrow() { Action act = () => LinkTargetFactory.Create <ForLinkedTargetLinkedSource, Image>( linkedSource => linkedSource.AReadOnlyImage); var exception = Assert.Throws <ArgumentException>(act); Assert.Contains("ForLinkedTargetLinkedSource/AReadOnlyImage", exception.Message); Assert.Contains("read-write", exception.Message); }
public void Test_WithPrivateSetter_ShouldThrow() { Action act = () => LinkTargetFactory.Create <ForLinkedTargetLinkedSource, Image>( linkedSource => linkedSource.APrivateSetterImage); var exception = Assert.Throws <LinkItException>(act); Assert.Contains("ForLinkedTargetLinkedSource", exception.Message); Assert.Contains("APrivateSetterImage", exception.Message); Assert.Contains("read-write", exception.Message); }
public void Test_WithFunc_ShouldThrow() { Action act = () => LinkTargetFactory.Create <ForLinkedTargetLinkedSource, Image>( linkedSource => linkedSource.AnImageFunc() ); var exception = Assert.Throws <LinkItException>(act); Assert.Contains("ForLinkedTargetLinkedSource", exception.Message); Assert.Contains("direct getter", exception.Message); }
public void Test_WithExpression_ShouldThrow() { Action act = () => LinkTargetFactory.Create <ForLinkedTargetLinkedSource, Image>( linkedSource => linkedSource.SummaryImage ?? new Image() ); var exception = Assert.Throws <ArgumentException>(act); Assert.Contains("ForLinkedTargetLinkedSource", exception.Message); Assert.Contains("direct getter", exception.Message); }
public void Create_LinkTargetShouldBeEquatable() { var summaryImage1 = LinkTargetFactory.Create <ForLinkedTargetLinkedSource, Image>( linkedSource => linkedSource.SummaryImage); var summaryImage2 = LinkTargetFactory.Create <ForLinkedTargetLinkedSource, Image>( linkedSource => linkedSource.SummaryImage); var anotherImage = LinkTargetFactory.Create <ForLinkedTargetLinkedSource, Image>( linkedSource => linkedSource.AnotherImage); Assert.True(summaryImage2.Equals(summaryImage1)); Assert.False(anotherImage.Equals(summaryImage1)); }
public void SetListTargetProperty() { var actual = new LinkedSourceWithList(); var sut = (MultiValueLinkTarget <LinkedSourceWithList, Image>)LinkTargetFactory.Create <LinkedSourceWithList, Image>( linkedSource => linkedSource.Images); sut.LazyInit(actual, 2); sut.SetLinkTargetValue(actual, new Image { Alt = "the-alt1" }, 0); sut.SetLinkTargetValue(actual, new Image { Alt = "the-alt2" }, 1); Assert.Equal("the-alt1", actual.Images[0].Alt); Assert.Equal("the-alt2", actual.Images[1].Alt); }
/// <summary> /// Load a reference by ID. /// </summary> public LoadLinkProtocolForLinkedSourceBuilder <TLinkedSource> LoadLinkReferencesByIds <TReference, TId>( Func <TLinkedSource, IEnumerable <TId> > getLookupIds, Expression <Func <TLinkedSource, IList <TReference> > > getLinkTarget) { if (getLookupIds == null) { throw new ArgumentNullException(nameof(getLookupIds)); } if (getLinkTarget == null) { throw new ArgumentNullException(nameof(getLinkTarget)); } return(LoadLinkReferencesByIds( getLookupIds, LinkTargetFactory.Create(getLinkTarget) )); }
/// <summary> /// Load a reference by ID. /// </summary> public LoadLinkProtocolForLinkedSourceBuilder <TLinkedSource> LoadLinkReferenceById <TReference, TId>( Func <TLinkedSource, TId> getLookupId, Expression <Func <TLinkedSource, TReference> > getLinkTarget) { if (getLookupId == null) { throw new ArgumentNullException(nameof(getLookupId)); } if (getLinkTarget == null) { throw new ArgumentNullException(nameof(getLinkTarget)); } return(LoadLinkReferencesByIds( ToGetLookupIdsForSingleValue(getLookupId), LinkTargetFactory.Create(getLinkTarget) )); }
/// <summary> /// Load a nested linked source by ID. /// </summary> public LoadLinkProtocolForLinkedSourceBuilder <TLinkedSource> LoadLinkNestedLinkedSourceById <TChildLinkedSource, TId>( Func <TLinkedSource, TId> getLookupId, Expression <Func <TLinkedSource, TChildLinkedSource> > getLinkTarget, Action <TLinkedSource, TChildLinkedSource> initChildLinkedSource = null) { if (getLookupId == null) { throw new ArgumentNullException(nameof(getLookupId)); } if (getLinkTarget == null) { throw new ArgumentNullException(nameof(getLinkTarget)); } return(LoadLinkNestedLinkedSourcesByIds( ToGetLookupIdsForSingleValue(getLookupId), LinkTargetFactory.Create(getLinkTarget), (linkedSource, referenceIndex, childLinkedSource) => initChildLinkedSource?.Invoke(linkedSource, childLinkedSource) )); }
/// <summary> /// Load a nested linked source using a model from its parent linked source. /// </summary> public LoadLinkProtocolForLinkedSourceBuilder <TLinkedSource> LoadLinkNestedLinkedSourceFromModel <TChildLinkedSource, TChildLinkedSourceModel>( Func <TLinkedSource, TChildLinkedSourceModel> getNestedLinkedSourceModel, Expression <Func <TLinkedSource, TChildLinkedSource> > getLinkTarget, Action <TLinkedSource, TChildLinkedSource> initChildLinkedSource = null ) where TChildLinkedSource : class, ILinkedSource <TChildLinkedSourceModel>, new() { if (getNestedLinkedSourceModel == null) { throw new ArgumentNullException(nameof(getNestedLinkedSourceModel)); } if (getLinkTarget == null) { throw new ArgumentNullException(nameof(getLinkTarget)); } return(LoadLinkNestedLinkedSourcesFromModels( ToGetLookupIdsForSingleValue(getNestedLinkedSourceModel), LinkTargetFactory.Create(getLinkTarget), (linkedSource, referenceIndex, childLinkedSource) => initChildLinkedSource?.Invoke(linkedSource, childLinkedSource) )); }
/// <summary> /// Load nested linked sources by their IDs. /// </summary> public LoadLinkProtocolForLinkedSourceBuilder <TLinkedSource> LoadLinkNestedLinkedSourcesByIds <TChildLinkedSource, TId>( Func <TLinkedSource, IEnumerable <TId> > getLookupIds, Expression <Func <TLinkedSource, List <TChildLinkedSource> > > getLinkTarget, Action <TLinkedSource, int, TChildLinkedSource> initChildLinkedSource = null) where TChildLinkedSource : ILinkedSource { if (getLookupIds == null) { throw new ArgumentNullException(nameof(getLookupIds)); } if (getLinkTarget == null) { throw new ArgumentNullException(nameof(getLinkTarget)); } return(LoadLinkNestedLinkedSourcesByIds( getLookupIds, LinkTargetFactory.Create(getLinkTarget), initChildLinkedSource )); }
/// <summary> /// Load nested linked sources using models from the parent linked source. /// </summary> public LoadLinkProtocolForLinkedSourceBuilder <TLinkedSource> LoadLinkNestedLinkedSourcesFromModels <TChildLinkedSource, TChildLinkedSourceModel>( Func <TLinkedSource, IEnumerable <TChildLinkedSourceModel> > getNestedLinkedSourceModels, Expression <Func <TLinkedSource, IList <TChildLinkedSource> > > getLinkTarget, Action <TLinkedSource, int, TChildLinkedSource> initChildLinkedSource = null ) where TChildLinkedSource : class, ILinkedSource <TChildLinkedSourceModel>, new() { if (getNestedLinkedSourceModels == null) { throw new ArgumentNullException(nameof(getNestedLinkedSourceModels)); } if (getLinkTarget == null) { throw new ArgumentNullException(nameof(getLinkTarget)); } return(LoadLinkNestedLinkedSourcesFromModels( getNestedLinkedSourceModels, LinkTargetFactory.Create(getLinkTarget), initChildLinkedSource )); }