コード例 #1
0
        public void LoadItselfOnlyOnceOnPropertyAccess()
        {
            int orderId = 123;
            var order   = new TestOrderWrapper(orderId);

            Assert.AreEqual(orderId, order.Id);
            Assert.IsFalse(order.WasLoadCalled);
            Assert.AreEqual(0, order.GetDataRowCount);

            // should call Load and GetDataRow once
            var shipMethod = order.ShipMethod;

            Assert.IsTrue(order.WasLoadCalled);
            Assert.AreEqual(1, order.GetDataRowCount);

            // should not increment GetDataRowCount
            var customer = order.Customer;

            Assert.IsTrue(order.WasLoadCalled);
            Assert.AreEqual(1, order.GetDataRowCount);
        }
コード例 #2
0
        public void Load_Itself_Only_Once_On_Property_Access()
        {
            int orderId = 123;
            var order   = new TestOrderWrapper(orderId);

            Assert.Equal(orderId, order.Id);
            Assert.False(order.WasLoadCalled);
            Assert.Equal(0, order.GetDataRowCount);

            // should call Load and GetDataRow once
            var shipMethod = order.ShipMethod;

            Assert.True(order.WasLoadCalled);
            Assert.Equal(1, order.GetDataRowCount);
            Assert.Equal("FEDEX", shipMethod);

            // should not increment GetDataRowCount
            var customer = order.Customer;

            Assert.True(order.WasLoadCalled);
            Assert.Equal(1, order.GetDataRowCount);
        }