public void Repository_For_Uses_Registered_Fetching_Strategies() { IEnumerable <Order> orders; using (var testData = new NHTestDataGenerator(Factory.OpenSession())) using (new UnitOfWorkScope()) { testData.Batch(actions => actions.CreateOrderForProducts(actions.CreateProducts(5))); var strategies = new IFetchingStrategy <Order, NHRepositoryTests>[] { new OrderOrderItemsStrategy(), new OrderItemsProductStrategy() }; ServiceLocator.Current.Expect(x => x.GetAllInstances <IFetchingStrategy <Order, NHRepositoryTests> >()) .Return(strategies); orders = new NHRepository <Order>() .For <NHRepositoryTests>() .ToList(); } orders.ForEach(order => { Assert.That(NHibernateUtil.IsInitialized(order.Items), Is.True); order.Items.ForEach(item => Assert.That(NHibernateUtil.IsInitialized(item.Product), Is.True)); }); }
public void Repository_For_Uses_Registered_Fetching_Strategies() { IEnumerable<Order> orders; using (var testData = new NHTestDataGenerator(Factory.OpenSession())) using (new UnitOfWorkScope()) { testData.Batch(actions => actions.CreateOrderForProducts(actions.CreateProducts(5))); var strategies = new IFetchingStrategy<Order, NHRepositoryTests>[] { new OrderOrderItemsStrategy(), new OrderItemsProductStrategy() }; ServiceLocator.Current.Expect(x => x.GetAllInstances<IFetchingStrategy<Order, NHRepositoryTests>>()) .Return(strategies); orders = new NHRepository<Order>() .For<NHRepositoryTests>() .ToList(); } orders.ForEach(order => { Assert.That(NHibernateUtil.IsInitialized(order.Items), Is.True); order.Items.ForEach(item => Assert.That(NHibernateUtil.IsInitialized(item.Product), Is.True)); }); }