Пример #1
0
        public static void Should_ImportFileProcess_ReturnInitialisedObject_WhenCreatingObject()
        {
            // Arrange
            var fileImporter  = Substitute.For <IFileImporter>();
            var outputWriter  = Substitute.For <IOutputWriter>();
            var calculator    = Substitute.For <ICalculator>();
            var configuration = Substitute.For <IConfiguration>();


            // Act
            var fileImportProcess = new FileImportProcess(fileImporter, outputWriter, calculator, configuration);

            // Assert
            Assert.NotNull(fileImportProcess);
        }
Пример #2
0
        public static void Should_ImportFileProcess_ReturnDataItems_WhenImportingFile()
        {
            // Arrange
            var inpdata = new[]
            {
                "Index, Girth (in), Height (ft), Volume(ft^3)",
                "1,   8.3,     70,   10.3, Willow, True",
                "2,   8.6,     65,   10.3, Oak, False"
            };

            File.WriteAllText(@"test.csv", string.Join(",", inpdata));

            string input = AppDomain.CurrentDomain.BaseDirectory;

            var expected = from row in inpdata.Skip(1)
                           let data = row.Split(',')
                                      select new DataItem
                                      (
                data[0].ToInt(),
                data[1].ToDouble(),
                data[2].ToDouble(),
                data[3].ToDouble(),
                data[4],
                data[5].ToBoolean()
                                      );

            var fileProvider = Substitute.For <IFileProvider>();

            fileProvider.ReadAllLines(Arg.Any <string>()).Returns(inpdata);

            var fileSanitiser = new FileSanitiser(fileProvider);
            var fileLoader    = new FileLoader();

            var fileImporter  = new FileImporter(fileLoader, fileSanitiser);
            var outputWriter  = Substitute.For <IOutputWriter>();
            var calculator    = Substitute.For <ICalculator>();
            var configuration = Substitute.For <IConfiguration>();

            var sut = new FileImportProcess(fileImporter, outputWriter, calculator, configuration);

            // Act
            var actual = sut.LoadData($@"{input}test.csv");

            // Assert
            actual.Should().BeEquivalentTo(expected);
        }
Пример #3
0
        public static void Should_ImportFileProcess_ReturnStringOfFileLocation_WhenCallingForFile()
        {
            // Arrange
            var fileProvider = Substitute.For <IFileProvider>();

            fileProvider.ReadAllLines(Arg.Any <string>()).Returns((string[])null);

            var fileImporter  = Substitute.For <IFileImporter>();
            var outputWriter  = Substitute.For <IOutputWriter>();
            var calculator    = Substitute.For <ICalculator>();
            var configuration = Substitute.For <IConfiguration>();

            var sut = new FileImportProcess(fileImporter, outputWriter, calculator, configuration);

            // Act
            var actual = sut.ReturnFileLocation();

            // Assert
            Assert.NotNull(actual);
        }