Exemplo n.º 1
0
        public void CanGetDashboardSummary()
        {
            DashboardTasks dashboardService = new DashboardTasks(CreateMockSupplierRepository());

            DashboardSummaryDto summary = dashboardService.GetDashboardSummary();

            summary.SuppliersCarryingMostProducts.ShouldNotBeNull();
            summary.SuppliersCarryingMostProducts.Count.ShouldEqual(1);
            summary.SuppliersCarryingMostProducts[0].CompanyName.ShouldEqual("Codai");
            summary.SuppliersCarryingMostProducts[0].Products.Count.ShouldEqual(2);

            summary.SuppliersCarryingFewestProducts.ShouldNotBeNull();
            summary.SuppliersCarryingFewestProducts.Count.ShouldEqual(1);
            summary.SuppliersCarryingFewestProducts[0].CompanyName.ShouldEqual("Acme");
            summary.SuppliersCarryingFewestProducts[0].Products.Count.ShouldEqual(1);
        }
        /// <summary>
        /// Uses the repository and domain layer to gather a few summary items for a dashboard view.
        /// </summary>
        public DashboardSummaryDto GetDashboardSummary() {
            DashboardSummaryDto dashboardSummaryDto = new DashboardSummaryDto();

            IList<Supplier> allSuppliers = supplierRepository.GetAll();

            // Arguably, the following two collection extension methods could be moved to 
            // ISupplierRepository, but since there's only 29 suppliers in the Northwind database, 
            // pushing this to the data layer isn't going to buy us any performance improvement.  
            // Consequently, IMO, I lean towards keeping such logic on the application side.
            // Furthermore, you should let a profiler inform you if have a bottle neck and then decide 
            // to optimize on the application or by pushing the logic and/or filtering to the database.
            dashboardSummaryDto.SuppliersCarryingMostProducts = allSuppliers.FindSuppliersCarryingMostProducts();
            dashboardSummaryDto.SuppliersCarryingFewestProducts = allSuppliers.FindSuppliersCarryingFewestProducts();

            return dashboardSummaryDto;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Uses the repository and domain layer to gather a few summary items for a dashboard view.
        /// </summary>
        public DashboardSummaryDto GetDashboardSummary()
        {
            DashboardSummaryDto dashboardSummaryDto = new DashboardSummaryDto();

            IList <Supplier> allSuppliers = supplierRepository.GetAll();

            // Arguably, the following two collection extension methods could be moved to
            // ISupplierRepository, but since there's only 29 suppliers in the __NAME__ database,
            // pushing this to the data layer isn't going to buy us any performance improvement.
            // Consequently, IMO, I lean towards keeping such logic on the application side.
            // Furthermore, you should let a profiler inform you if have a bottle neck and then decide
            // to optimize on the application or by pushing the logic and/or filtering to the database.
            dashboardSummaryDto.SuppliersCarryingMostProducts   = allSuppliers.FindSuppliersCarryingMostProducts();
            dashboardSummaryDto.SuppliersCarryingFewestProducts = allSuppliers.FindSuppliersCarryingFewestProducts();

            return(dashboardSummaryDto);
        }