示例#1
0
        public void AutoMapper_projectto_expression_transformed_to_single_intermediate_type()
        {
            // configure automapper
            AutoMapper.Mapper.CreateMap <TestData, FormattedName>()
            .ForMember(f => f.DisplayName, m => m.MapFrom(t => string.Format("{0} {1}", t.FirstName, t.LastName)))
            .ForMember(f => f.IndexedName, m => m.MapFrom(t => string.Format("{0}, {1}", t.LastName.ToUpper(), t.FirstName)));
            AutoMapper.Mapper.AssertConfigurationIsValid();

            var query = TestData.Sample.AsQueryable()
                        .Project().To <FormattedName>();

            // build queryable provider stub to monitor what's passed through to underlying provider
            var stubProvider  = new StubQueryProviderProxy(query.Provider);
            var mockQueryable = MockQueryableHelper.CreateMockQueryable(query, stubProvider);

            // act: apply LinqDefer to the mocked query/provider stub
            var queryWithDefer = mockQueryable.Object.ThenDoDeferred();
            var results        = queryWithDefer.ToArray();

            // assert: the underlying mocked provider was only asked for our intermediate type
            Assert.AreEqual(1, stubProvider.CreateQueryCalledTypes.Count);
            Assert.IsTrue(stubProvider.CreateQueryCalledTypes[0].Assembly.FullName == IntermediateTypeCache.AssemblyFullName);

            var expectedResults =
                TestData.Sample.Select(AutoMapper.Mapper.Map <TestData, FormattedName>).ToArray();

            AssertExtensions.AreCollectionsEquivalent(results, expectedResults);
        }
        public void More_queryable_work_after_deferred_works()
        {
            var expected = TestData.Sample.Select(d => d.FirstName + "!").ToArray();
            var query    = TestData.Sample.AsQueryable()
                           .Select(d => new string(d.FirstName.Reverse().ToArray()))
                           .ThenDoDeferred()
                           .Select(d => new string(d.Reverse().ToArray()) + "!");

            var results = query.ToArray();

            AssertExtensions.AreCollectionsEquivalent(expected, results);
        }
        public void More_queryable_work_after_deferred_works()
        {
            var expected = TestData.Sample.Select(d => d.FirstName + "!").ToArray();
            var query    = TestData.Sample.AsQueryable()
                           .Select(d => new string(d.FirstName.Reverse().ToArray()));

            query = DeferProvider.Wrap(query, LinqDeferConfiguration.Default)
                    .Select(d => new string(d.Reverse().ToArray()) + "!");

            var results = query.ToArray();

            AssertExtensions.AreCollectionsEquivalent(expected, results);
        }
        public void Create_untyped_query_works()
        {
            var expected = TestData.Sample.Select(d => d.FirstName + "!").ToArray();
            var query    = TestData.Sample.AsQueryable()
                           .Select(d => d.FirstName + "!");

            var nonTypedQuery = DeferProvider.Wrap((IQueryable)query, LinqDeferConfiguration.Default);

            var results          = nonTypedQuery.GetEnumerator().ToArray();
            var stringArrResults = results.Cast <string>().ToArray();

            AssertExtensions.AreCollectionsEquivalent(expected, stringArrResults);
        }
示例#5
0
        public void Format_name_with_string_format()
        {
            var sourceData = TestData.Sample;

            var query = sourceData.AsQueryable()
                        .Select(n => string.Format("{0}, {1}", n.LastName, n.FirstName))
                        .ThenDoDeferred();

            var results = query.ToArray();

            var expected = sourceData.Select(n => string.Format("{0}, {1}", n.LastName, n.FirstName)).ToArray();

            AssertExtensions.AreCollectionsEquivalent(expected, results);
        }
        public void Basic_postprocessing_works()
        {
            var sourceData = TestData.Sample.Select(s => s.FirstName).ToArray();
            var expected   = sourceData.Select(d => new string(d.Reverse().ToArray()));

            Expression <Func <string, string> > process = (s) => new string(s.Reverse().ToArray());

            var processingEnum = new DeferPostProcessEnumerator <string>(sourceData.GetEnumerator(), process);

            var results         = processingEnum.ToArray();
            var resultsAsString = results.Cast <string>().ToArray();

            AssertExtensions.AreCollectionsEquivalent(resultsAsString, expected);
        }
        public void Manual_enumeration_of_query_works()
        {
            var expected = TestData.Sample.Select(d => new string(d.FirstName.Reverse().ToArray())).ToArray();
            var query    = TestData.Sample.AsQueryable()
                           .Select(d => new string(d.FirstName.Reverse().ToArray()))
                           .ThenDoDeferred();
            var enumerable = (IEnumerable)query;

            var results    = new List <string>();
            var enumerator = enumerable.GetEnumerator();

            while (enumerator.MoveNext())
            {
                results.Add((string)enumerator.Current);
            }

            AssertExtensions.AreCollectionsEquivalent(expected, results);
        }