public void Should_Load_Empty_When_File_Not_Existing() { var tempJsonFilePath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.json"); try { if (File.Exists(tempJsonFilePath)) { File.Delete(tempJsonFilePath); } var prov = new JsonMarketOverheadProvider(tempJsonFilePath); CollectionAssert.AreEqual(new string[] {}, prov.LoadData()); } catch {} }
public static void Main(string[] args) { try { var(commodity, tonPrice, tradeVolume) = GetParams(args); var marketOverheadJsonFile = Config[MarketOverheadJsonFileKey]; var jsonMarketOverheadProvider = new JsonMarketOverheadProvider(marketOverheadJsonFile); var fruitTrading = new FruitTrading(jsonMarketOverheadProvider, (line) => Console.WriteLine(line)); fruitTrading.ReportFullCostAcrossCountries(commodity, tonPrice, tradeVolume); } catch (Exception exc) { Console.WriteLine(exc.Message); } }
public void Should_Load_Empty_When_Invalid_Json() { var tempJsonFilePath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.json"); try { File.WriteAllText(tempJsonFilePath, ""); var prov = new JsonMarketOverheadProvider(tempJsonFilePath); CollectionAssert.AreEqual(new IMarketOverhead[] {}, prov.LoadData()); } catch {} if (File.Exists(tempJsonFilePath)) { File.Delete(tempJsonFilePath); } }
public void Should_Load_Correctly() { var tempJsonFilePath = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.json"); try { var json = "[{\"COUNTRY\":\"MX\",\"COMMODITY\":\"banana\",\"FIXED_OVERHEAD\":\"32.00\",\"VARIABLE_OVERHEAD\":\"1.24\"}, {\"COUNTRY\":\"BR\",\"COMMODITY\":\"mango\",\"FIXED_OVERHEAD\":\"20.00\",\"VARIABLE_OVERHEAD\":\"1.42\"}]"; File.WriteAllText(tempJsonFilePath, json); var prov = new JsonMarketOverheadProvider(tempJsonFilePath); var data = prov.LoadData().ToArray(); var stubbedProv = new StubbedMarketOverheadProvider(); stubbedProv.Add(("MX", "banana", 32.0, 1.24)); stubbedProv.Add(("BR", "mango", 20.0, 1.42)); Utils.AssertMarketOverheadDataAreEqual(stubbedProv.GetStub(0), data[0]); Utils.AssertMarketOverheadDataAreEqual(stubbedProv.GetStub(1), data[1]); } catch {} if (File.Exists(tempJsonFilePath)) { File.Delete(tempJsonFilePath); } }