public void Read_ReturnCollectionOfDictionaryWordObjectsWithDataFromStreamRowsSkipFirst()
        {
            // arrange
            var stream = new MemoryStream();

            var streamWriter = new StreamWriter(stream);
            streamWriter.WriteLine(3);
            streamWriter.WriteLine("element1 10");
            streamWriter.WriteLine("element2 20");
            streamWriter.WriteLine("element3 30");
            streamWriter.Flush();
            stream.Seek(0, SeekOrigin.Begin);

            var expectedResultArray = new DictionaryWord[]
            {
                new DictionaryWord("element1", 10),
                new DictionaryWord("element2", 20),
                new DictionaryWord("element3", 30)
            };

            var streamReader = new StreamReader(stream);
            var dictionaryWordsInputReader =
                new DictionaryWordsInputReader(streamReader);

            // act
            var actualResultCollection = dictionaryWordsInputReader.Read();

            //assert
            var actualResultArray = actualResultCollection.ToArray();
            CollectionAssert.AreEqual(
                expectedResultArray,
                actualResultArray,
                new DictionaryWordComparer());
        }
        public void Constructor_WhenStreamReaderIsNull_ShouldThrowArgumentNullException()
        {
            // arrange
            StreamReader streamReader = null;

            // act
            try
            {
                var dictionaryWordsInputReader =
                    new DictionaryWordsInputReader(streamReader);
            }
            catch (ArgumentNullException e)
            {
                //assert
                Assert.AreEqual("streamReader", e.ParamName, false);
                return;
            }

            Assert.Fail("Ожидаемое исключение не было выброшено.");
        }
        public void Read_ReturnCollectionWithSizeEqualNumberFromStreamFirstRowData()
        {
            // arrange
            var stream = new MemoryStream();

            var streamWriter = new StreamWriter(stream);
            streamWriter.WriteLine(3);
            streamWriter.WriteLine("element1 10");
            streamWriter.WriteLine("element2 20");
            streamWriter.WriteLine("element3 30");
            streamWriter.WriteLine("element4 40");
            streamWriter.Flush();
            stream.Seek(0, SeekOrigin.Begin);

            var expectedResultCollectionSize = 3;

            var streamReader = new StreamReader(stream);
            var dictionaryWordsInputReader =
                new DictionaryWordsInputReader(streamReader);

            // act
            var actualResultCollection = dictionaryWordsInputReader.Read();

            //assert
            var actualResultArray = actualResultCollection.ToArray();
            Assert.AreEqual(expectedResultCollectionSize, actualResultArray.Length);
        }
        public void Read_WhenStreamFromSecondRowDataHasInvalidFormat_ShouldThrowFormatException()
        {
            // arrange
            var stream = new MemoryStream();

            var streamWriter = new StreamWriter(stream);
            streamWriter.WriteLine(2);
            streamWriter.WriteLine("Element1 10");  // корректный формат
            streamWriter.WriteLine("Element2");     // некорректный формат
            streamWriter.Flush();
            stream.Seek(0, SeekOrigin.Begin);

            var streamReader = new StreamReader(stream);
            var dictionaryWordsInputReader =
                new DictionaryWordsInputReader(streamReader);

            // act
            try
            {
                dictionaryWordsInputReader.Read();
            }
            catch (FormatException)
            {
                //assert
                return;
            }

            Assert.Fail("Ожидаемое исключение не было выброшено.");
        }
        public void Read_WhenStreamFirstRowDataIsNotNumber_ShouldThrowFormatException()
        {
            // arrange
            var stream = new MemoryStream();

            var streamWriter = new StreamWriter(stream);
            streamWriter.Write("some string");
            streamWriter.Flush();
            stream.Seek(0, SeekOrigin.Begin);

            var streamReader = new StreamReader(stream);
            var dictionaryWordsInputReader =
                new DictionaryWordsInputReader(streamReader);

            // act
            try
            {
                dictionaryWordsInputReader.Read();
            }
            catch (FormatException)
            {
                //assert
                return;
            }

            Assert.Fail("Ожидаемое исключение не было выброшено.");
        }
        public void Read_WhenNumberInStreamFirstRowLessThan0_ShouldThrowInvalidOperationException()
        {
            // arrange
            var stream = new MemoryStream();

            var streamWriter = new StreamWriter(stream);
            streamWriter.Write(-1);
            streamWriter.Flush();
            stream.Seek(0, SeekOrigin.Begin);

            var streamReader = new StreamReader(stream);
            var dictionaryWordsInputReader =
                new DictionaryWordsInputReader(streamReader);

            // act
            try
            {
                dictionaryWordsInputReader.Read();
            }
            catch (InvalidOperationException)
            {
                //assert
                return;
            }

            Assert.Fail("Ожидаемое исключение не было выброшено.");
        }