コード例 #1
0
        public void LoadCsv_ValidLine_DataIsLoaded()
        {
            // Arrange
            var expectedFruit = new Fruit {
                Name = "some fruit", Price = 22.22m
            };
            var fileLine = $"{expectedFruit.Name}, {expectedFruit.Price}";
            var fileName = @"c:\test.csv";

            var fileSystemMock = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { fileName, new MockFileData(fileLine) },
            });

            // Action
            tillContextUT.LoadCsv(fileSystemMock, fileName);

            // Assert
            Assert.IsTrue(tillContextUT.Fruits.Count(f => f.Name == expectedFruit.Name) == 1);
            Assert.IsTrue(tillContextUT.Fruits.Count(f => f.Price == expectedFruit.Price) == 1);
        }
コード例 #2
0
        private void LoadPrices()
        {
            Console.WriteLine("First we need to load the prices. Please enter the path of a valid file with the prices of the fruits");
            Console.WriteLine($"The current directory is {Directory.GetCurrentDirectory()}");
            var fileName = Console.ReadLine();

            try
            {
                TillContext.LoadCsv(new FileSystem(), fileName);
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine($"We cannot load the file {Directory.GetCurrentDirectory()}\\{fileName}.");
                Console.WriteLine("Please try again with a correct file name");
                Console.WriteLine();
                LoadPrices();
            }
        }