Exemplo n.º 1
0
		// Use this method to specify the test(s) to run...
		public static void Dispatcher( IKLink link )
		{
			Console.WriteLine( "\n===== Creating the maps..." ); Console.ReadLine();
			KMaps.StartCollector( 2500, true ); // Just for DEBUG purposes
			var map = new KMap<Region>( link, x => x.Regions ); map.Validate();

			var reg = Test_Insert( link );
			Test_Update( link, reg );
			Test_Delete( link, reg );
		}
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var map = new KMap(3, new HashSet <long>()
            {
                4, 5, 6
            }, new HashSet <long>()
            {
            });

            map.PrintCoverages(true);
            map.PrintTestResults();

            Console.ReadKey();
        }
Exemplo n.º 3
0
		public static KMap<Employee> CreateMapEmployee( IKLink link )
		{
			var map = new KMap<Employee>( link, x => x.Employees );
			map.UnManagedColumns( "ManagerId", "CountryId" );

			map.CreateInstance = () => { return new Employee(); };
			map.ClearInstance = obj => { obj.Clear(); };

			map.WriteRecord = ( obj, record ) => {
				DEBUG.IndentLine( "\n-- Map<Employee>.WriteRecord() Instance = {0}", obj );
				map.BaseWriteRecord( obj, record );
				record.OnSet( "ManagerId", () => { return obj.Manager == null ? null : obj.Manager.Id; } );
				record.OnSet( "CountryId", () => { return obj.Country == null ? null : obj.Country.Id; } );
				DEBUG.Unindent();
			};
			map.LoadRecord = ( record, obj ) => {
				DEBUG.IndentLine( "\n-- Map<Employee>.LoadRecord() Record = {0}", record );
				map.BaseLoadRecord( record, obj );
				record.OnGet( "ManagerId", val => { obj.Manager = val == null ? null : link.Find<Employee>( x => x.Id == val ); } );
				record.OnGet( "CountryId", val => { obj.Country = val == null ? null : link.Find<Country>( x => x.Id == val ); } );
				DEBUG.Unindent();
			};
			map.OnRefresh = obj => {
				DEBUG.IndentLine( "\n-- Map<Employee>.OnRefresh() Instance = {0}", obj );
				obj = map.BaseOnRefresh( obj );
				obj.Employees.Clear(); obj.Employees.AddRange( link.Query<Employee>().Where( x => x.ManagerId == obj.Id ).ToList() );
				DEBUG.Unindent(); return obj;
			};

			map.OnInsert = obj => {
				DEBUG.IndentLine( "\n-- Map<Employee>.OnInsert() Instance = {0} ...", obj );
				obj.Manager = link.Sync( obj.Manager, KMaps.SyncReason.Insert );
				obj.Country = link.Sync( obj.Country, KMaps.SyncReason.Insert );
				obj = map.BaseOnInsert( obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Insert );
				DEBUG.Unindent(); return obj;
			};
			map.OnUpdate = obj => {
				DEBUG.IndentLine( "\n-- Map<Employee>.OnUpdate() Instance = {0} ...", obj );
				obj.Manager = link.Sync( obj.Manager, KMaps.SyncReason.Update );
				obj.Country = link.Sync( obj.Country, KMaps.SyncReason.Update );
				obj = map.BaseOnUpdate( obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Update );
				DEBUG.Unindent(); return obj;
			};
			map.OnDelete = obj => {
				DEBUG.IndentLine( "\n-- Map<Employee>.OnDelete() Instance = {0} ...", obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Delete );
				obj = map.BaseOnDelete( obj );
				DEBUG.Unindent(); return obj;
			};

			map.Validate();
			Console.WriteLine( "\n> Map: {0} -- Discarded: {1} -- Schema: {2}",
				map, TypeHelper.ToString( map.DiscardedColumns, "[]" ), map.Schema );
			return map;
		}
Exemplo n.º 4
0
		public static KMap<Country> CreateMapCountry( IKLink link )
		{
			var map = new KMap<Country>( link, x => x.Countries );
			map.UnManagedColumns( "RegionId" );

			map.CreateInstance = () => { return new Country(); };
			map.ClearInstance = obj => { obj.Clear(); };

			map.WriteRecord = ( obj, record ) => {
				DEBUG.IndentLine( "\n-- Map<Country>.WriteRecord() Instance = {0}", obj );
				map.BaseWriteRecord( obj, record );
				record.OnSet( "RegionId", () => { return obj.Region == null ? null : obj.Region.Id; } );
				DEBUG.Unindent();
			};
			map.LoadRecord = ( record, obj ) => {
				DEBUG.IndentLine( "\n-- Map<Country>.LoadRecord() Record = {0}", record );
				map.BaseLoadRecord( record, obj );
				record.OnGet( "RegionId", val => { obj.Region = val == null ? null : link.Find<Region>( x => x.Id == val ); } );
				DEBUG.Unindent();
			};
			map.OnRefresh = obj => {
				DEBUG.IndentLine( "\n-- Map<Country>.OnRefresh() Instance = {0}", obj );
				obj = map.BaseOnRefresh( obj );
				obj.Employees.Clear(); obj.Employees.AddRange( link.Query<Employee>().Where( x => x.CountryId == obj.Id ).ToList() );
				DEBUG.Unindent(); return obj;
			};

			map.OnInsert = obj => {
				DEBUG.IndentLine( "\n-- Map<Country>.OnInsert() Instance = {0} ...", obj );
				obj.Region = link.Sync( obj.Region, KMaps.SyncReason.Insert );
				obj = map.BaseOnInsert( obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Insert );
				DEBUG.Unindent(); return obj;
			};
			map.OnUpdate = obj => {
				DEBUG.IndentLine( "\n-- Map<Country>.OnUpdate() Instance = {0} ...", obj );
				obj.Region = link.Sync( obj.Region, KMaps.SyncReason.Update );
				obj = map.BaseOnUpdate( obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Update );
				DEBUG.Unindent(); return obj;
			};
			map.OnDelete = obj => {
				DEBUG.IndentLine( "\n-- Map<Country>.OnDelete() Instance = {0} ...", obj );
				link.Sync<Employee>( obj.Employees, KMaps.SyncReason.Delete );
				obj = map.BaseOnDelete( obj );
				DEBUG.Unindent(); return obj;
			};

			map.Validate(); return map;
		}