Esempio n. 1
0
        public void Should_ReturnExpectedResult_WithChangedColumnOrder(string header, string line)
        {
            var deserializeRowData = new DeserializeRowData <Procurement>();
            var lineParser         = new LineParser();
            var expected           = new Procurement
            {
                Project       = "2",
                Description   = "Harmonize Lactobacillus acidophilus sourcing",
                StartDate     = "2014-01-01 00:00:00.000",
                Category      = "Dairy",
                Responsible   = "Daisy Milks",
                SavingsAmount = "NULL",
                Currency      = "EUR",
                Complexity    = "Simple"
            };


            var headerColumnDictionary = lineParser.TabSeparatedParser(header);
            var rowColumnDictionary    = lineParser.TabSeparatedParser(line);
            var actual             = deserializeRowData.Deserialize(headerColumnDictionary, rowColumnDictionary, attributeMappings);
            var expectedJsonString = JsonConvert.SerializeObject(expected);
            var actualJsonString   = JsonConvert.SerializeObject(actual);

            Assert.Equal(expectedJsonString, actualJsonString);
        }
        public void Should_Correctly_Deserialize_Parsed_Row_Data()
        {
            var deserializeRowData = new DeserializeRowData <Procurement>();

            var properties = new Dictionary <int, string>
            {
                { 0, "Project" }, { 1, "Description" }, { 3, "Start date" }, { 4, "Category" }, { 5, "Responsible" },
                { 6, "Savings amount" }, { 7, "Currency" }, { 8, "Complexity" }
            };
            var values = new Dictionary <int, string>
            {
                { 0, "2" }, { 1, "Black and white logo paper" }, { 3, "2012-06-01 00:00:00.000" }, { 4, "Office supplies" },
                { 5, "Clark Kent" },
                { 6, "4880.199567" }, { 7, "EUR" }, { 8, "Simple" }
            };

            var propertyMapping = new Dictionary <string, string>
            {
                { "Project", "Project" }, { "Description", "Description" }, { "StartDate", "Start date" },
                { "Category", "Category" },
                { "Responsible", "Responsible" },
                { "SavingsAmount", "Savings amount" }, { "Currency", "Currency" }, { "Complexity", "Complexity" }
            };

            var expected = new Procurement
            {
                Project       = "2",
                Description   = "Black and white logo paper",
                StartDate     = "2012-06-01 00:00:00.000",
                Category      = "Office supplies",
                Responsible   = "Clark Kent",
                SavingsAmount = "4880.199567",
                Currency      = "EUR",
                Complexity    = "Simple"
            };

            var actual = deserializeRowData.Deserialize(properties, values, propertyMapping);

            var expectedJsonString = JsonConvert.SerializeObject(expected);
            var actualJsonString   = JsonConvert.SerializeObject(actual);

            Assert.Equal(expectedJsonString, actualJsonString);
        }
Esempio n. 3
0
        public void Should_ReturnError_With_WrongStartDateFormat(string line)
        {
            var expectedResult        = "Start date should conform to the following format: yyyy-mm-dd hh:mm:ss.sss";
            var lineParser            = new LineParser();
            var deserializeRowData    = new DeserializeRowData <Procurement>();
            var headerColumnDictionay = lineParser.TabSeparatedParser(headerString);
            var rowColumnDictionary   = lineParser.TabSeparatedParser(line);

            var entity = deserializeRowData.Deserialize(headerColumnDictionay, rowColumnDictionary,
                                                        attributeMappings);


            var actualResult = string.Empty;
            var results      = new ProcurementEntityValidator().Validate(entity);

            if (!results.IsValid)
            {
                actualResult = string.Join("", results.Errors);
            }


            Assert.Equal(expectedResult, actualResult);
        }
Esempio n. 4
0
        public void Should_ReturnError_With_ComplexityDiffersFromGivenValues(string line)
        {
            var expectedResult =
                $"Column Complexity should only have following values: {string.Join(",", validComplexityTypes)}";
            var lineParser            = new LineParser();
            var deserializeRowData    = new DeserializeRowData <Procurement>();
            var headerColumnDictionay = lineParser.TabSeparatedParser(headerString);
            var rowColumnDictionary   = lineParser.TabSeparatedParser(line);

            var entity = deserializeRowData.Deserialize(headerColumnDictionay, rowColumnDictionary,
                                                        attributeMappings);


            var actualResult = string.Empty;
            var results      = new ProcurementEntityValidator().Validate(entity);

            if (!results.IsValid)
            {
                actualResult = string.Join("", results.Errors);
            }


            Assert.Equal(expectedResult, actualResult);
        }
Esempio n. 5
0
        public void Should_ReturnError_With_WrongSavingAmountFormat(string line)
        {
            var expectedResult =
                "Money (Savings amount) values should conform be numbers with a point as the decimal separator";
            var lineParser            = new LineParser();
            var deserializeRowData    = new DeserializeRowData <Procurement>();
            var headerColumnDictionay = lineParser.TabSeparatedParser(headerString);
            var rowColumnDictionary   = lineParser.TabSeparatedParser(line);

            var entity = deserializeRowData.Deserialize(headerColumnDictionay, rowColumnDictionary,
                                                        attributeMappings);


            var actualResult = string.Empty;
            var results      = new ProcurementEntityValidator().Validate(entity);

            if (!results.IsValid)
            {
                actualResult = string.Join("", results.Errors);
            }


            Assert.Equal(expectedResult, actualResult);
        }