Exemplo n.º 1
0
 private static void Run()
 {
     using (var scope = _container.BeginLifetimeScope())
     {
         var         fileManager = scope.Resolve <IFileManager>();
         StdInReader stdInReader = new StdInReader(fileManager);
         Environment.SetEnvironmentVariable("INPUT_FILE", "C:\\test.txt");
         var arr = stdInReader.GetInputJaggedArray("");
         Array.ForEach(arr, a => Array.ForEach(a, b => Console.WriteLine(b)));
         Console.ReadLine();
     }
 }
Exemplo n.º 2
0
        public void StdInReader_InvalidFilePath_ThrowsArgumentNullException(string environmentVar)
        {
            // Arrange
            Environment.SetEnvironmentVariable("INPUT_FILE", "C:\\test.txt");
            int[][] testArray = GetCorrectResult();

            var mockFileManager = new Mock <IFileManager>();

            mockFileManager.Setup(f => f.StreamReader(null))
            .Throws(new ArgumentNullException());

            StdInReader reader = new StdInReader(mockFileManager.Object);

            // Act
            Action act = () => reader.GetInputJaggedArray(environmentVar);

            // Assert
            act.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 3
0
        public void StdInReader_ValidFilePath_ReturnsArrayWithData(string environmentVar)
        {
            // Arrange
            Environment.SetEnvironmentVariable(environmentVar, "C:\\test.txt");
            int[][] testArray = GetCorrectResult();

            var mockFileManager = new Mock <IFileManager>();

            mockFileManager.Setup(f => f.StreamReader(It.IsAny <string>()))
            .Returns(GetMockStream());

            StdInReader reader = new StdInReader(mockFileManager.Object);

            // Act

            int[][] result = reader.GetInputJaggedArray(environmentVar);


            // Assert
            for (int i = 0; i < result.Length; i++)
            {
                result[i].Should().Equal(testArray[i]);
            }
        }