예제 #1
0
파일: Tests.cs 프로젝트: MichaelBuen/DitTO
        public void Test_Dto_To_Live_Nh_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 = "Great" },
                            new CommentDto { TheComment = "Nice" }
                        }
                    },
                    new OrderLineDto { ProductoId = 1, Quantity = 4, Price = 5, Amount = 20, FreebieId = 2 },
                }
            };

            // Act
            Order oPoco = Mapper.ToPoco<OrderDto,Order>(oDto);

            // Assert
            using (ISession s = NhDbMapper.GetSession(connectionString))
            {
                var db = new NH.Repository<Order>(s);
                db.Save(oPoco);

                Assert.AreNotEqual(0, oPoco.OrderId);
                Assert.AreEqual(3, db.Get(oPoco.OrderId).OrderLines.Count);
            }
        }
예제 #2
0
        public void Nh_Can_Fetch_Eager_Load()
        {
            EmptyDatabase();
            IRepository<Question> db = new NH.Repository<Question>(NhModelsMapper.GetSession(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 = NH.EagerExtensionHelper.EagerLoad(db.All.Where(x => x.QuestionId == qx.QuestionId), "Answers").SingleOrDefault();

            // Assert
            Assert.AreEqual("42", qq.Text);
        }