/// <summary>
        /// Build a new <see cref="ILoadLinkProtocol"/> using assemblies as an entry point
        /// to find <see cref="ILoadLinkProtocolConfig"/> and types for which to apply the <paramref name="conventions"/>.
        /// </summary>
        public static ILoadLinkProtocol Build(
            this LoadLinkProtocolBuilder loadLinkProtocolBuilder,
            Func <IReferenceLoader> createReferenceLoader,
            IEnumerable <Assembly> assemblies,
            IList <ILoadLinkExpressionConvention> conventions)
        {
            loadLinkProtocolBuilder.ApplyConventions(
                assemblies,
                conventions
                );
            loadLinkProtocolBuilder.ApplyLoadLinkProtocolConfigs(assemblies);

            return(loadLinkProtocolBuilder.Build(createReferenceLoader));
        }
예제 #2
0
        private static ILoadLinkProtocol BuildLoadLinkProtocol()
        {
            var loadLinkProtocolBuilder = new LoadLinkProtocolBuilder();

            loadLinkProtocolBuilder.ApplyConventions(
                new List <Type> {
                typeof(LinkedSource)
            },
                new List <ILoadLinkExpressionConvention> {
                new LoadLinkByNullableValueTypeIdWhenIdSuffixMatches()
            }
                );
            return(loadLinkProtocolBuilder.Build(() => new ReferenceLoaderStub()));
        }
        private static ILoadLinkProtocol BuildLoadLinkProtocol()
        {
            var loadLinkProtocolBuilder = new LoadLinkProtocolBuilder();

            loadLinkProtocolBuilder.ApplyConventions(
                new List <Type> {
                typeof(LinkedSource), typeof(MasterLinkedSource)
            },
                new List <ILoadLinkExpressionConvention> {
                new LoadLinkNestedLinkedSourceListFromModelWhenNameMatches()
            }
                );

            return(loadLinkProtocolBuilder.Build(() => new ReferenceLoaderStub()));
        }
        public void ApplyConventions_ParameterizableConventions_ShouldNotThrow()
        {
            var loadLinkProtocolBuilder = new LoadLinkProtocolBuilder();

            loadLinkProtocolBuilder.ApplyConventions(
                new List <Type> {
                typeof(LinkedSourceWithImage)
            },
                new List <ILoadLinkExpressionConvention>
            {
                new ConventionStub("same-name"),
                new ConventionStub("different-name")
            }
                );
        }
        public void ApplyConventions_ShouldFilterModelOutWhenMatchingLinkTarget()
        {
            var loadLinkProtocolBuilder = new LoadLinkProtocolBuilder();
            var conventionStub          = new ConventionStub();

            loadLinkProtocolBuilder.ApplyConventions(
                new List <Type> {
                typeof(LinkedSourceWithImage)
            },
                new List <ILoadLinkExpressionConvention> {
                conventionStub
            }
                );

            Assert.False(conventionStub.DidAttemptToMatchModelAsLinkTarget);
        }
        public void ApplyConventions_ShouldMatchExpectedLinkTargets()
        {
            var loadLinkProtocolBuilder = new LoadLinkProtocolBuilder();
            var conventionStub          = new ConventionStub();

            loadLinkProtocolBuilder.ApplyConventions(
                new List <Type> {
                typeof(LinkedSourceWithImage), typeof(LinkedSourceWithPerson)
            },
                new List <ILoadLinkExpressionConvention> {
                conventionStub
            }
                );

            Assert.Equal(
                new[] { "Image", "Person" },
                conventionStub.LinkTargetPropertyNamesWhereConventionApplies);
        }
        public void ApplyConventions_DuplicateConventions_ShouldThrow()
        {
            var loadLinkProtocolBuilder = new LoadLinkProtocolBuilder();

            Action act = () => loadLinkProtocolBuilder.ApplyConventions(
                new List <Type> {
                typeof(LinkedSourceWithImage)
            },
                new List <ILoadLinkExpressionConvention>
            {
                new ConventionStub("same-name"),
                new ConventionStub("same-name")
            }
                );

            var exception = Assert.Throws <LinkItException>(act);

            Assert.Contains("with the same name", exception.Message);
            Assert.Contains("same-name", exception.Message);
        }
        public void ApplyConventions_DoesApplyFailed_ShouldThrow()
        {
            var loadLinkProtocolBuilder = new LoadLinkProtocolBuilder();

            Action act = () => loadLinkProtocolBuilder.ApplyConventions(
                new List <Type> {
                typeof(LinkedSource)
            },
                new List <ILoadLinkExpressionConvention> {
                new DoesApplyFailedConvention()
            }
                );

            var exception = Assert.ThrowsAny <Exception>(act);

            Assert.Contains("Does apply failed convention", exception.Message);
            Assert.Contains("LinkedSource.Person", exception.Message);
            Assert.Contains("PersonId", exception.Message);
            Assert.Contains("does apply failed", exception.InnerException.Message);
        }