예제 #1
0
        public void FieldMapperTests_NestedKeys_Double_OnDifferentLines()
        {
            // Arrange
            var    emailKey   = "Email Name";
            string emailValue = "*****@*****.**";
            string phoneKey   = "Phone";
            string phoneValue = "5551231234";

            var content = string.Format("{1} {0} {2} {0} {3} {0} {4}",
                                        Environment.NewLine,
                                        emailKey,
                                        emailValue,
                                        phoneKey,
                                        phoneValue
                                        );

            var mappings = new List <string>();

            mappings.Add(emailKey);
            mappings.Add(phoneKey);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(emailValue, result[emailKey]);
            Assert.AreEqual(phoneValue, result[phoneKey]);
        }
예제 #2
0
        public void FieldMapperTests_NestedKeys_OnSameLine()
        {
            // Arrange
            var emailKey      = "Email Name";
            var emailValue    = "*****@*****.**";
            var phoneKey      = "Phone";
            var phoneValue    = "5555551234";
            var fullNameKey   = "Name";
            var fullNameValue = "Joe Moceri";
            var zipKey        = "Zip Name";
            var zipValue      = "00000";

            var content  = $"{emailKey} {emailValue} {phoneKey} {phoneValue} {fullNameKey} {fullNameValue} {zipKey} {zipValue}";
            var mappings = new List <string>();

            mappings.Add(emailKey);
            mappings.Add(fullNameKey);
            mappings.Add(phoneKey);
            mappings.Add(zipKey);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(emailValue, result[emailKey]);
            Assert.AreEqual(fullNameValue, result[fullNameKey]);
            Assert.AreEqual(phoneValue, result[phoneKey]);
            Assert.AreEqual(zipValue, result[zipKey]);
        }
예제 #3
0
        public void FieldMapperTests_GetAndMap_FirstName()
        {
            // Arrange
            string key   = "First Name:";
            string value = "Joe";

            var content  = $"{key} {value}";
            var mappings = new List <string>();

            mappings.Add(key);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(value, result[key]);
        }
예제 #4
0
        public void FieldMapperTests_CaseInsensitiveShouldntFindValue()
        {
            // Arrange
            string key   = "First Name:";
            string value = "Joe";

            var content  = $"FIRst NaMe: {value}";
            var mappings = new List <string>();

            mappings.Add(key);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(result.Count, 0);
        }
예제 #5
0
        public void FieldMapperTests_ShouldReturnEmptyResultIfNoKeysFound()
        {
            // Arrange
            string key   = "First Name:";
            string value = "Joe";

            var content  = $"{value}";
            var mappings = new List <string>();

            mappings.Add(key);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(result.Count, 0);
        }
예제 #6
0
        public void FieldMapperTests_LineBreakSeparatedMapping_NoSpace_CarriageReturnAndLineFeed_FirstName()
        {
            // Arrange
            string key   = "First{0}Name:";
            string value = "Joe";

            var content  = $"{string.Format(key, "\r\n")} {value}";
            var mappings = new List <string>();

            mappings.Add(string.Format(key, " "));

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(value, result[string.Format(key, " ")]);
        }
예제 #7
0
        public void FieldMapperTests_PutMapping_ShouldThrowArgumentExceptionIfTryingToAddDuplicateKey()
        {
            // Arrange
            string key         = "First Name:";
            string value       = "Joe";
            string secondKey   = "First Name:";
            string secondValue = "Tom";

            var content  = $"{key} {value} {secondKey} {secondValue}";
            var mappings = new List <string>();

            mappings.Add(key);
            mappings.Add(secondKey);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(secondValue, result[key]);
        }
예제 #8
0
        public void FieldMapperTests_NestedKeys_Triple_OnSameLines()
        {
            // Arrange
            string emailKey   = "Email Name";
            string phoneKey   = "Phone";
            string nameKey    = "Name";
            string zipKey     = "Zip Name";
            string cityKey    = "City Zip Name";
            string addressKey = "Address City Zip Name";

            string emailValue   = "*****@*****.**";
            string phoneValue   = "5551231234";
            string nameValue    = "Joe Moceri";
            string zipValue     = "000000";
            string cityValue    = "ExampleCity";
            string addressValue = "Example Address #123";

            var content  = string.Format("{1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12}", Environment.NewLine, emailKey, emailValue, phoneKey, phoneValue, nameKey, nameValue, zipKey, zipValue, cityKey, cityValue, addressKey, addressValue);
            var mappings = new List <string>();

            mappings.Add(emailKey);
            mappings.Add(nameKey);
            mappings.Add(phoneKey);
            mappings.Add(zipKey);
            mappings.Add(cityKey);
            mappings.Add(addressKey);

            // Act
            var parser = new FieldMapper(content, mappings);
            var result = parser.Get();

            // Assert
            Assert.AreEqual(emailValue, result[emailKey]);
            Assert.AreEqual(phoneValue, result[phoneKey]);
            Assert.AreEqual(nameValue, result[nameKey]);
            Assert.AreEqual(zipValue, result[zipKey]);
            Assert.AreEqual(cityValue, result[cityKey]);
            Assert.AreEqual(addressValue, result[addressKey]);
        }