Exemplo n.º 1
0
        public void GetOrLoadCollectionQueryResult_PerformsEagerFetching_AndRegistersLoadedObjects()
        {
            LoadedObjectDataPendingRegistrationCollector collector = null;

            var consolidatedResultItems = new[] { CreateEquivalentData(_resultItem1), CreateEquivalentData(_resultItem2) };

            using (_mockRepository.Ordered())
            {
                _persistenceStrategyMock
                .Expect(mock => mock.ExecuteCollectionQuery(_queryWithFetchQueries, _loadedObjectDataProviderStub))
                .Return(new[] { _resultItem1, _resultItem2 });
                _loadedObjectDataRegistrationAgentMock
                .Expect(
                    mock => mock.BeginRegisterIfRequired(
                        Arg.Is(new[] { _resultItem1, _resultItem2 }), Arg.Is(true), Arg <LoadedObjectDataPendingRegistrationCollector> .Is.NotNull))
                .WhenCalled(mi => collector = (LoadedObjectDataPendingRegistrationCollector)mi.Arguments[2])
                .Return(consolidatedResultItems);
                _eagerFetcherMock
                .Expect(
                    mock => mock.PerformEagerFetching(
                        Arg.Is(consolidatedResultItems),
                        Arg.Is(_queryWithFetchQueries.EagerFetchQueries),
                        Arg.Is(_fetchEnabledObjectLoader),
                        Arg <LoadedObjectDataPendingRegistrationCollector> .Matches(c => c == collector)));
                _loadedObjectDataRegistrationAgentMock
                .Expect(mock => mock.EndRegisterIfRequired(Arg <LoadedObjectDataPendingRegistrationCollector> .Matches(c => c == collector)));
            }
            _mockRepository.ReplayAll();

            var result = _fetchEnabledObjectLoader.GetOrLoadCollectionQueryResult(_queryWithFetchQueries);

            _mockRepository.VerifyAll();
            Assert.That(result, Is.EqualTo(consolidatedResultItems));
        }
        public void LoadObject()
        {
            _persistenceStrategyMock.Expect(mock => mock.LoadObjectData(DomainObjectIDs.Order1)).Return(_loadedObjectDataStub1);
            var throwOnNotFound = BooleanObjectMother.GetRandomBoolean();

            _loadedObjectDataRegistrationAgentMock.Expect(mock => mock.RegisterIfRequired(Arg.Is(new[] { _loadedObjectDataStub1 }), Arg.Is(throwOnNotFound)));

            _mockRepository.ReplayAll();

            var result = _objectLoader.LoadObject(DomainObjectIDs.Order1, throwOnNotFound);

            _mockRepository.VerifyAll();
            Assert.That(result, Is.SameAs(_loadedObjectDataStub1));
        }