public void Load_ValidFileExists_LoadsDataCorrectly()
        {
            var actual = SimpleFileTariffLoader.Load(new FileInfo("./data/prices.json"));

            var actualLookup = actual.ToLookup(t => t.Name);

            actualLookup.Should().HaveCount(4);

            actualLookup["2yr-fixed"].Should().HaveCount(1);
            actualLookup["simpler-energy"].Should().HaveCount(1);

            var better = actualLookup["better-energy"].Single();

            better.Name.Should().Be("better-energy");
            better.GasRate.Should().Be(0.0288M);
            better.PowerRate.Should().Be(0.1367M);
            better.StandingCharge.Should().Be(8.33M);

            var greener = actualLookup["greener-energy"].Single();

            greener.Name.Should().Be("greener-energy");
            greener.GasRate.Should().BeNull();
            greener.PowerRate.Should().Be(0.1544M);
            greener.StandingCharge.Should().Be(8.33M);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            // use only a little bit of DI to get everything started.
            var provider = new ServiceCollection()
                           // register the tariff source, which is consumed by the commands
                           .AddSingleton(_ =>
            {
                // ensure the tarrif data is loaded before we use it.
                ITariffSource source = new TariffSource();
                source.ReloadAsync(() => SimpleFileTariffLoader.Load(new FileInfo(Path.GetFullPath("./prices.json")))).Wait();
                return(source);
            })
                           // Register our little 'command line' component
                           .AddCommands(config => config
                           // register the commands that we've implemented
                                        .AddCommand <CostCommand>()
                                        .AddCommand <UsageCommand>())
                           // this builds the MS container
                           .BuildServiceProvider();

            // run the app
            provider.ExecuteCommands(bootstrapper =>
                                     bootstrapper.Execute(args, System.Console.Out, System.Console.Error));
        }
 public void Load_InvalidJsonFileExists_Throws()
 {
     new Action(() => SimpleFileTariffLoader.Load(new FileInfo("./invalid-prices.json")))
     .Should().Throw <ArgumentException>();
 }
 public void Load_NoFileExists_Throws()
 {
     new Action(() => SimpleFileTariffLoader.Load(new FileInfo("./idontexist")))
     .Should().Throw <ArgumentException>();
 }
        public void Load_EmptyFileExists_LoadsEmptyData()
        {
            var actual = SimpleFileTariffLoader.Load(new FileInfo("./data/empty-prices.json"));

            actual.Should().BeEmpty();
        }