当前位置: 首页>>代码示例>>C#>>正文


C# Car.FillTank方法代码示例

本文整理汇总了C#中Car.FillTank方法的典型用法代码示例。如果您正苦于以下问题:C# Car.FillTank方法的具体用法?C# Car.FillTank怎么用?C# Car.FillTank使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Car的用法示例。


在下文中一共展示了Car.FillTank方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: when_driving_car

    void when_driving_car()
    {
        it["should throw error if car isn't started"] =
            expect<InvalidOperationException>(() =>
            {
                Car car = new Car(tankSize: 10, mpg: 1);
                car.Drive(10);
            });

        new[]
        {
            new { gasInTank = 10, mpg = 1,  miles = 10.0, expectedDistance = 10.0,
                  gasLeft = 0.0, running = false, lowfuel = true, onEmpty = true },

            new { gasInTank = 10, mpg = 2,  miles = 5.0,  expectedDistance = 5.0,
                  gasLeft = 7.5, running = true, lowfuel = false, onEmpty = false },

            new { gasInTank = 10, mpg = 10, miles = 10.0, expectedDistance = 10.0,
                  gasLeft = 9.0, running = true, lowfuel = false, onEmpty = false }
        }.Do(example =>
        {
            context["with {0} gallon(s) of gas, mpg: {1}, driving: {2} miles"
                .With(example.gasInTank, example.mpg, example.miles)] = () =>
            {
                Car car = null;

                before = () =>
                {
                    car = new Car(example.gasInTank, example.mpg);
                    car.FillTank(example.gasInTank);
                };

                act = () => car.Drive(example.miles);

                it["should have made it {0} miles".With(example.expectedDistance)] = () =>
                {
                    car.Odometer.should_be(example.expectedDistance);
                };

                it["should have {0} gallons left in tank".With(example.gasLeft)] = () =>
                {
                    car.GasInTank.should_be(example.gasLeft);
                };

                it["should {0} running".With(example.running ? "be" : "not be")] = () =>
                {
                    car.IsRunning.should_be(example.running);
                };

                it["should {0} low fuel".With(example.lowfuel ? "have" : "not have")] = () =>
                {
                    car.IsLowOnFuel.should_be(example.lowfuel);
                };
            };
        });
    }
开发者ID:DevlinLiles,项目名称:NSpec,代码行数:56,代码来源:describe_car.cs


注:本文中的Car.FillTank方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。