Exemplo n.º 1
0
        public void TypeParser_ChangeType_PassEmptyValue_ThrowArgumentNullException()
        {
            //
            // Arrange.
            //
            var value = string.Empty;

            //
            // Assert.
            //
            Assert.ThrowsException <ArgumentNullException>(() => TypeParser.ChangeType <string>(value));
        }
Exemplo n.º 2
0
        public void TypeParser_ChangeType_PassNullValue_ThrowArgumentNullException()
        {
            //
            // Arrange.
            //
            object integer = null;

            //
            // Assert.
            //
            Assert.ThrowsException <ArgumentNullException>(() => TypeParser.ChangeType <int>(integer));
        }
Exemplo n.º 3
0
        public void TypeParser_ChangeType_PassStringWithInt_MakeValueTypeOfInt()
        {
            //
            // Arrange.
            //
            var inputValue   = "10";
            var expectedType = typeof(int);
            int actualResult;

            //
            // Act.
            //
            actualResult = TypeParser.ChangeType <int>(inputValue);

            //
            // Assert.
            //
            Assert.AreEqual(expectedType, actualResult.GetType());
        }
Exemplo n.º 4
0
        public void TypeParser_ChangeType_PassStringWithInt_MakeInt()
        {
            //
            // Arrange.
            //
            var inputValue     = "150";
            var expectedResult = 150;
            int actualResult;

            //
            // Act.
            //
            actualResult = TypeParser.ChangeType <int>(inputValue);

            //
            // Assert.
            //
            Assert.AreEqual(expectedResult, actualResult);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Convert data to collection of type T.
        /// </summary>
        /// <owner>Anton Petrenko</owner>
        /// <param name="content">Content of the file.</param>
        public T[] ConvertData(string content)
        {
            if (string.IsNullOrWhiteSpace(content))
            {
                throw new ArgumentNullException(nameof(content));
            }

            try
            {
                var      numbers = new List <T>();
                string[] items   = content.Split(separators);
                for (int i = 0; i < items.Length; i++)
                {
                    numbers.Add(TypeParser.ChangeType <T>(items[i].Trim()));
                }

                return(numbers.ToArray());
            }
            catch (ArgumentNullException)
            {
                throw new ArgumentNullException();
            }
        }