public void WhenGetFleetSummaryStatistics_CalculatesAcrossVehicles()
        {
            var fillups1 = new[]
            {
                new FillupEntry {
                    Date = DateTime.UtcNow.AddDays(-1), PricePerUnit = 1.0, TotalUnits = 10
                },
                new FillupEntry {
                    Date = DateTime.UtcNow, PricePerUnit = 1.0, TotalUnits = 10
                }
            };

            var fillups2 = new[]
            {
                new FillupEntry {
                    Date = DateTime.UtcNow.AddDays(-1), PricePerUnit = 1.0, TotalUnits = 10
                },
                new FillupEntry {
                    Date = DateTime.UtcNow, PricePerUnit = 1.0, TotalUnits = 10
                },
                new FillupEntry
                {
                    Date           = DateTime.UtcNow,
                    PricePerUnit   = 1.0,
                    TotalUnits     = 10,
                    TransactionFee = 5.0
                }
            };

            var vehicle1 = new Vehicle {
                VehicleId = 1
            };
            var vehicle2 = new Vehicle {
                VehicleId = 2
            };

            var mockVehicleRepository = new Mock <IVehicleRepository>();
            var mockFillupsRepository = new Mock <IFillupRepository>();

            mockVehicleRepository
            .Setup(x => x.GetVehicles(DefaultUserId))
            .Returns(new[] { vehicle1, vehicle2 });

            mockFillupsRepository
            .Setup(x => x.GetFillups(vehicle1.VehicleId))
            .Returns(fillups1);

            mockFillupsRepository
            .Setup(x => x.GetFillups(vehicle2.VehicleId))
            .Returns(fillups2);

            var handler = new GetFleetSummaryStatistics(mockVehicleRepository.Object, mockFillupsRepository.Object);

            var actual = handler.Execute(DefaultUserId);

            Assert.NotNull(actual);
            Assert.Equal(30, actual.TotalFuelCost);
            Assert.Equal(35, actual.TotalCost);
        }
Esempio n. 2
0
        public object GetDashboard()
        {
            var statistics = getFleetSummaryStatistics.Execute(1);
            var reminders  = GetReminders();

            var resource = new Page("Dashboard/init")
            {
                Title = "MileageStats Sample Application",
                Data  = new
                {
                    statistics,
                    reminders,
                    vehicles   = Url.Get <GetVehiclesController>(),
                    addVehicle = Url.Get <GetNewVehicleController>(),
                    profile    = Url.Get <GetProfileController>()
                }
            };

            return(resource);
        }