private static RelatedDtoLoader GetRelatedDtoLoader(MyUnitTestData testData)
        {
            var fakeProductRule = new Mock <IDtoLoadRule>();

            fakeProductRule.Setup(x => x.LoadAsObjectAsync(It.IsAny <IEnumerable <object> >()))
            .Returns <IEnumerable <object> >(ids => {
                return(Task.FromResult(testData.ProductDtos.Where(x => ids.Contains(x.Id)).Select(x => (object)x)));
            });

            fakeProductRule.Setup(x => x.GetKey(It.IsAny <object>()))
            .Returns <object>(x => { return(((ProductDto)x).Id); });

            var orderRelatedDtoProperties = new RelatedDtoPropertyCollection(typeof(OrderDto));

            var fakeProfile = new Mock <IRelatedDtoLoaderProfile>();

            fakeProfile.Setup(x => x.GetRule(typeof(ProductDto)))
            .Returns(fakeProductRule.Object);
            fakeProfile.Setup(x => x.GetRelatedDtoProperties(typeof(OrderDto)))
            .Returns(orderRelatedDtoProperties);

            var dtoLoader = new RelatedDtoLoader(fakeProfile.Object);

            return(dtoLoader);
        }
Esempio n. 2
0
        public void LoadForDto(Type targetDtoType)
        {
            var props = new RelatedDtoPropertyCollection(targetDtoType);

            if (props.Any())
            {
                _targetDtoPropertyCollection[targetDtoType] = props;
            }
        }
        private static RelatedDtoLoader GetRelatedDtoLoader(MyUnitTestData testData)
        {
            var fakeProfile = new Mock <IRelatedDtoLoaderProfile>();

            FackProduct(testData, fakeProfile);
            FackProductComment(testData, fakeProfile);

            var orderRelatedDtoProperties = new RelatedDtoPropertyCollection(typeof(OrderDto));

            fakeProfile.Setup(x => x.GetRelatedDtoProperties(typeof(OrderDto)))
            .Returns(orderRelatedDtoProperties);

            var dtoLoader = new RelatedDtoLoader(null, fakeProfile.Object);

            return(dtoLoader);
        }
        private static void FackProduct(MyUnitTestData testData, Mock <IRelatedDtoLoaderProfile> fakeProfile)
        {
            var fakeRule = new Mock <IDtoLoadRule>();

            fakeRule.Setup(x => x.LoadAsObjectAsync(It.IsAny <IServiceProvider>(), It.IsAny <IEnumerable <object> >()))
            .Returns <IServiceProvider, IEnumerable <object> >((serviceProvider, ids) =>
            {
                return(Task.FromResult(testData.ProductDtos.Where(x => ids.Contains(x.Id)).Select(x => (object)x)));
            });

            fakeRule.Setup(x => x.GetKey(It.IsAny <object>()))
            .Returns <object>(x => { return(((ProductDto)x).Id); });

            fakeProfile.Setup(x => x.GetRule(typeof(ProductDto)))
            .Returns(fakeRule.Object);

            var productRelatedDtoProperties = new RelatedDtoPropertyCollection(typeof(ProductDto));

            fakeProfile.Setup(x => x.GetRelatedDtoProperties(typeof(ProductDto)))
            .Returns(productRelatedDtoProperties);
        }