Example #1
0
            public void SecondFillUp()
            {
                //arrange
                var f1 = new FillUp();

                f1.Odometer = 1000;
                f1.Litters  = 50.00;
                f1.IsFull   = true;

                var f2 = new FillUp();

                f2.Odometer = 1600;
                f2.Litters  = 60.00;
                f2.IsFull   = true;

                f1.NextFillUp = f2;

                //act
                double?kml1 = f1.Kml;
                double?kml2 = f2.Kml;

                //assert
                Assert.Equal(10, kml1);
                Assert.Null(kml2);
            }
Example #2
0
        public void AddFillUp(Guid Id, FillUp item)
        {
            Car c = carRepo.Find(Id);

            c.AddFillUp(item.Odometer, item.Liters, item.IsFull);
            carRepo.SaveChanges();
        }
Example #3
0
            public void FillUpCalculateKmL_Case2()
            {
                // Arrange
                //var f1 = new FillUp();
                //f1.OdoMeter = 2000;
                //f1.Liters = 50.0;
                //f1.IsFull = true;

                //var f2 = new FillUp();
                //f2.OdoMeter = 2500;
                //f2.Liters = 20.0;
                //f2.IsFull = true;

                // Or
                //var f1 = new FillUp(odoMeter: 2000, liters: 50, isFull: true);
                //var f2 = new FillUp(2500, 20, true);

                // Or
                var f1 = new FillUp(odoMeter: 2000, liters: 50);
                var f2 = new FillUp(2500, 20);

                f1.NextFillUp = f2;

                // Act
                var kml = f1.KmL;

                // Assert
                Assert.Equal(25.0, kml);
            }
Example #4
0
            public void ThirdFillUp_Return12()
            {
                //arrrang
                Car    c  = new Car();
                FillUp f1 = new FillUp();

                f1.Odometer = 1000;
                f1.Liters   = 60;

                FillUp f2 = new FillUp();

                f2.Odometer   = 1500;
                f2.Liters     = 50;
                f1.NextFillUp = f2;

                FillUp f3 = new FillUp();

                f3.Odometer   = 2100;
                f3.Liters     = 50;
                f2.NextFillUp = f3;

                c.FillUps.Add(f1);
                c.FillUps.Add(f2);
                c.FillUps.Add(f3);

                //act
                double?result = c.AverageKilometersPerLiter;

                //assert
                Assert.Equal(11.09, result);
            }
Example #5
0
            public void ThreeFullFillUps()
            {
                var f1 = new FillUp();

                f1.Odometer = 1000;
                f1.Liters   = 40.0;
                f1.IsFull   = true;

                var f2 = new FillUp();

                f2.Odometer = 1600;
                f2.Liters   = 50.0;
                f2.IsFull   = true;

                f1.NextFillUp = f2;

                var f3 = new FillUp();

                f3.Odometer = 2200;
                f3.Liters   = 60.0;
                f3.IsFull   = true;

                f2.NextFillUp = f3;

                double?result1 = f1.ConsumptionRate;
                double?result2 = f2.ConsumptionRate;
                double?result3 = f3.ConsumptionRate;

                Assert.Equal(12.0, result1);
                Assert.Equal(10.0, result2);
                Assert.Null(result3);
            }
Example #6
0
        public void ThirdFillUp_Return12()
        {
            //arrrang
            FillUp f1 = new FillUp();

            f1.Odometer = 1000;
            f1.Liters   = 60;

            FillUp f2 = new FillUp();

            f2.Odometer = 1500;
            f2.Liters   = 50;

            f1.NextFillUp = f2;

            FillUp f3 = new FillUp();

            f3.Odometer = 2100;
            f3.Liters   = 50;

            f2.NextFillUp = f3;

            //act
            double?result = f2.KilometersPerLiter;

            //assert
            Assert.Equal(12, result);
        }
Example #7
0
                public void CarAverageConsumption()
                {
                    Car c = new Car();

                    Assert.Null(c.AverageConsumptionRate);

                    FillUp f1 = c.AddFillUp(odometer: 1000, liters: 40.0);

                    Assert.Null(c.AverageConsumptionRate);

                    FillUp f2 = c.AddFillUp(odometer: 1600, liters: 50.0);

                    Assert.Equal(12.0, c.AverageConsumptionRate);

                    FillUp f3 = c.AddFillUp(odometer: 2200, liters: 60.0);

                    Assert.Equal(10.91, c.AverageConsumptionRate);

                    //FillUp f4 = c.AddFillUp(odometer: 4000, liters: 80.0);
                    //Assert.Equal(15.79, c.AverageConsumptionRate);

                    //FillUp f5 = c.AddFillUp(odometer: 100000, liters: 500.0);
                    //Assert.Equal(143.48, c.AverageConsumptionRate);


                    FillUp f5 = c.AddFillUp(odometer: 100000, liters: 500.0);

                    Assert.Equal(162.3, c.AverageConsumptionRate);

                    // FillUp f4 = c.AddFillUp(odometer: 4000, liters: 80.0);
                    //  Assert.Equal(143.48, c.AverageConsumptionRate);
                }
Example #8
0
            public void AvgTwoFillup()
            {
                Car    c  = new Car();
                FillUp f1 = c.AddFillUp(odometer: 1000, liters: 40.0);
                FillUp f2 = c.AddFillUp(odometer: 1600, liters: 50.0);

                Assert.Equal(12.0, c.AverageConsumptionRate);
            }
Example #9
0
            public void FillUp1AverageConsumptionRate()
            {
                Car c = new Car();

                FillUp f1 = c.AddFillUp(odometer: 0, liters: 0);

                Assert.Null(c.AverageConsumptionRate);
            }
Example #10
0
            public void FirstFillUp_ReturnNull()
            {
                var f = new FillUp(1000, 50.0);

                double?kml = f.KmL;

                Assert.Null(kml);
            }
Example #11
0
            public void AddFirstFillUp()
            {
                Car    c  = new Car();
                FillUp f1 = c.AddFillUp(odometer: 1000, liters: 40.0);

                Assert.Equal(1, c.FillUps.Count());
                Assert.Equal(1000, f1.Odometer);
                Assert.Equal(40.0, f1.Liters);
            }
Example #12
0
 public static FillUpResponse FromModel(FillUp item)
 {
     return(new FillUpResponse
     {
         Id = item.Id,
         Odometer = item.Odometer,
         Liters = item.Liters
     });
 }
Example #13
0
        public FillUp AddFillUp(Guid Id, FillUp item)
        {
            Car    c = Find(Id);
            FillUp f = c.AddFillUp(item.Odometer, item.Liters, item.IsFull);

            SaveChanges();

            return(f);
        }
Example #14
0
            public void FillUp()
            {
                FillUp f;

                f = new FillUp();

                Assert.Equal(0, f.Odometer);
                Assert.Equal(0.0, f.Liters);
            }
Example #15
0
            public void NewFillUp()
            {
                FillUp f;

                f = new FillUp();
                Assert.Equal(0, f.Odometer);
                Assert.Equal(0.0, f.Liters);
                Assert.True(f.IsFull);
            }
Example #16
0
            public void AvgThreeFillup()
            {
                Car    c  = new Car();
                FillUp f1 = c.AddFillUp(odometer: 1000, liters: 40.0);
                FillUp f2 = c.AddFillUp(odometer: 1600, liters: 50.0);
                FillUp f3 = c.AddFillUp(odometer: 2200, liters: 60.0);

                Assert.Equal(10.91, c.AverageConsumptionRate);
            }
Example #17
0
            public void AddFirstFillUp()
            {
                var    c = new Car("My Ford");
                FillUp f = c.AddFillUp(odometer: 1000, liters: 20);

                Assert.Equal(1, c.FillUps.Count());
                Assert.Equal(1000, f.Odometer);
                Assert.Equal(20.0, f.Liters);
            }
Example #18
0
            public void AddTwoFillUp()
            {
                Car    c  = new Car();
                FillUp f1 = c.AddFillUp(odometer: 1000, liters: 40.0);
                FillUp f2 = c.AddFillUp(odometer: 1600, liters: 50.0);

                Assert.Same(f2, f1.NextFillUp);
                Assert.Equal(2, c.FillUps.Count());
            }
Example #19
0
            public void FirstFillUp_ReturnNull()
            {
                var f = new FillUp();

                f.Odometer = 1000;
                f.Liters   = 40;
                double?result = f.ConsumptionRate;

                Assert.Null(result);
            }
Example #20
0
            public void InvalidData(int odometer, double liters)
            {
                FillUp f1 = new FillUp(odometer, liters);

                //Assert.Null(f1.Kml);
                Assert.ThrowsAny <Exception>(() =>
                {
                    var k1 = f1.Kml;
                });
            }
Example #21
0
            public void SecondFillUps()
            {
                var job = new Job();

                FillUp f1 = job.AddFillUp(odometer: 1000, liters: 60);
                FillUp f2 = job.AddFillUp(odometer: 1000, liters: 60);

                Assert.Equal(2, job.FillUps.Count);
                Assert.Same(f2, f1.Next);
            }
Example #22
0
            public void AddFirstFillUp()
            {
                var    c = new Car(name: "My Jazz");
                FillUp f = c.AddFillUp(odometer: 1000, liters: 20.0);

                Assert.NotNull(f);
                Assert.Equal(1, c.FillUps.Count());
                Assert.Equal(1000, f.Odometer);
                Assert.Equal(20.0, f.Liters);
            }
Example #23
0
            public void AddTwoFillUpsAndThemShouldBeChainedCorrectly()
            {
                var    c  = new Car("My Ford");
                FillUp f1 = c.AddFillUp(odoMeter: 1000, liters: 40);
                FillUp f2 = c.AddFillUp(2000, 50);

                Dump(c);

                //Assert.Same(f2, f1.NextFillUp);//Equal is same value, Same is same object
                f1.NextFillUp.ShouldBeSameAs(f2);
            }
Example #24
0
            public void NewFillUpDontHasKmL()
            {
                //arrange
                var f1 = new FillUp();

                //act
                double?kml = f1.KmL; //Nullable<double>

                //a
                Assert.Null(kml);
            }
Example #25
0
            public void NewFillUpDontHasKmL()
            {
                //arrange
                var f1 = new FillUp();

                // act
                double?kml = f1.KmL; /*KilometerPerLiteral*/

                // assert
                Assert.Null(kml);
            }
Example #26
0
            public void TwoFillUpsCanCalculateKmL_Case2()
            {
                var f1 = new FillUp(odometer: 2000, liters: 50.0);
                var f2 = new FillUp(odometer: 2500, liters: 20.0);

                f1.NextFillUp = f2;

                var kml1 = f1.KmL;

                Assert.Equal(25.0, kml1);
            }
Example #27
0
            public void NewFillUpDontHasKML() // inner or nester class
            // arrange
            {
                var f1 = new FillUp();

                // act
                double?kml = f1.KmL; //KilometersPerLiteral (Nullable(double) => double?)

                // a
                Assert.Null(kml);
            }
Example #28
0
            public void NewFillUpDontHaveKmL()
            {
                // Arrange
                var f1 = new FillUp();

                // Act
                double?kml = f1.KmL;

                // Assert
                Assert.Null(kml);
            }
Example #29
0
 public static FillUpResponse FromModel(FillUp item)
 {
     return(new FillUpResponse
     {
         Id = item.Id,
         Obometer = item.odometer,
         Liters = item.liters,
         IsFull = item.isFull,
         Kml = item.Kml,
     });
 }
        public IActionResult OnGet(int?id)
        {
            var vehicle = _context.Vehicle.FirstOrDefault(v => v.Id == id);

            MyFillUp = new FillUp();

            MyFillUp.Date    = DateTime.Now;
            MyFillUp.Vehicle = vehicle;

            return(Page());
        }