public void Test_Dto_To_Live_Ef_Poco() { // Arrange OrderDto oDto = new OrderDto { OrderDate = new DateTime(2012, 07, 22), OrderDescription = "Hey Apple!", CustomerId = 1, CustomerName = "Hey", OrderLines = new[] { new OrderLineDto { ProductoId = 1, Quantity = 7, Price = 6, Amount = 42 }, new OrderLineDto { ProductoId = 2, Quantity = 3, Price = 6, Amount = 18, FreebieId = 1, Koments = new[] { new CommentDto { TheComment = "Lovely" }, new CommentDto { TheComment = "View" } } }, new OrderLineDto { ProductoId = 1, Quantity = 4, Price = 5, Amount = 20, FreebieId = 2 }, } }; // Act Order oPoco = Mapper.ToPoco<OrderDto,Order>(oDto); var db = new EfDbMapper(connectionString); // can use this too: /* db.AssignStub(oPoco); db.Set<Order>().Add(oPoco); db.SaveChanges(); */ db.AssignStub(oPoco); var repoOrder = new EF.Repository<Order>(db); repoOrder.Save(oPoco); Assert.AreNotEqual("", oPoco.Customer.CustomerName); Assert.IsNotNull(oPoco.Customer); // oPoco = repoOrder.Get(oPoco.OrderId); repoOrder.Save(oPoco); // Assert Assert.AreNotEqual(0, oPoco.OrderId); Assert.IsNotNull(oPoco.Customer); Assert.AreNotEqual("", oPoco.Customer.CustomerName); }
public void Ef_Can_Fetch_Eager_Load() { EmptyDatabase(); IRepository<Question> db = new EF.Repository<Question>(new EfDbMapper(connectionString)); Test_Can_Fetch_Eager_Load_Common(db); // Arrange EmptyDatabase(); Question qx = new Question { Text = "42" }; db.Save(qx); db.Evict(qx.QuestionId); // Act var qq = EF.EagerExtensionHelper.EagerLoad(db.All.Where(x => x.QuestionId == qx.QuestionId), "Answers").SingleOrDefault(); // Assert Assert.AreEqual("42", qq.Text); }