Exemple #1
0
        public void Test_Corner_Cases_on_Live_Ef_to_Poco()
        {
            var db = new EfDbMapper(connectionString);
            var repo = new EF.Repository<Order>(db);

            var customerStub = new EF.Repository<Customer>(db);
            Customer cx = customerStub.LoadStub(1);

            Order oPoco = repo.Get(1);

            {
                System.Reflection.PropertyInfo px = oPoco.GetType().GetProperty("Customer", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                oPoco.GetType().InvokeMember("Customer", System.Reflection.BindingFlags.GetProperty, null, oPoco, new object[] { });

                var a = oPoco.OrderLines;
                var b = a[0].Order;

                object x = oPoco.Customer;

                var languages = oPoco.Customer.Country.Languages;

                // To avoid circular reference
                // http://connect.microsoft.com/VisualStudio/feedback/details/679399/entity-framework-4-1-using-lazyloading-with-notracking-option-causes-invalidoperationexception
                // object countries = languages[0].Countries;

                // Do these instead:
                int lid = languages.First().LanguageId;
                Language firstLanguage = new EF.Repository<Language>(db).All.SingleOrDefault(l => l.LanguageId == lid);
                object countries = firstLanguage.Countries;

            }

            Assert.AreEqual("Michael", oPoco.Customer.CustomerName);
            Assert.AreEqual("Philippines", oPoco.Customer.Country.CountryName);

            Assert.AreEqual(1, oPoco.OrderLines[0].Product.ProductId);

            OrderDto oDto = Mapper.ToDto<Order, OrderDto>(oPoco);

            Assert.AreEqual("Michael", oDto.CustomerName);

            Assert.AreEqual(3, oDto.OrderLines.Count);
        }