예제 #1
0
        public void LazyLoaded_Implicit_Conversion_When_Not_IsLoad_Should_Call_DB_Once()
        {
			// Arrange
			StubResultSet rsOffices = new StubResultSet("Number");
			rsOffices.AddRow(1);
			rsOffices.AddRow(2);
			
			var db = CreateDB_ForQuery(rsOffices);

			Building building = new Building();
			int calls = 0;
			var lazyProxy = new LazyLoaded<Building, List<Office>>((d, b) => {
				calls++;
				return d.Query<Office>().ToList();
			}, RelationshipTypes.Many);
			lazyProxy.Prepare(() => db, building, "Offices");
			building._offices = lazyProxy;

			// Act
			int count = building.Offices.Count;

			// Assert
			Assert.AreEqual(2, count);
			Assert.AreEqual(1, calls);

			// Act again (should not hit db)
			count = building.Offices.Count;

			// Assert
			Assert.AreEqual(2, count);
			Assert.AreEqual(1, calls);
        }
예제 #2
0
 public void LazyLoaded_Implicit_Conversion_When_IsLoad_Should_Return_Value()
 {
     Building building = new Building();
     Office office1 = new Office { Number = 1 };
     Office office2 = new Office { Number = 2 };
     building._offices = new LazyLoaded<Building, List<Office>>(new List<Office> { office1, office2 });
     int count = building.Offices.Count;
     Assert.IsTrue(count == 2);
 }
예제 #3
0
		public void LazyLoadedException_ShouldThrowDataMappingException()
		{
			// Arrange
			StubResultSet rsOffices = new StubResultSet("Number");
			rsOffices.AddRow(1);
			rsOffices.AddRow(2);

			var db = CreateDB_ForQuery(rsOffices);

			Building building = new Building();
			var lazyProxy = new LazyLoaded<Building, List<Office>>((d, b) =>
			{
				throw new Exception("Oops!");
				//return d.Query<Office>().ToList();
			}, RelationshipTypes.Many);
			lazyProxy.Prepare(() => db, building, "Offices");
			building._offices = lazyProxy;

			// Act
			int count = building.Offices.Count;
		}