public void FileWithEmptyLines_ShouldBeStrippedOfThem()
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = "", Value = ""
                },
                new PropertyPair {
                    Key = "", Value = ""
                },
                new PropertyPair {
                    Key = "Key1", Value = "Value1"
                },
                new PropertyPair {
                    Key = "", Value = ""
                },
                new PropertyPair {
                    Key = "#", Value = "Comment 1"
                },
                new PropertyPair {
                    Key = "!", Value = "Comment 2"
                },
                new PropertyPair {
                    Key = "", Value = ""
                }
            });
            ICommand cmd = new StripEmptyLinesCommand(file);

            cmd.Execute();

            Assert.Equal(3, file.GetProperties().Count());
            Assert.Equal("Comment 2", file.GetProperties().Last().Value);
            Assert.Equal("Value1", file.GetProperties().First().Value);
        }
Example #2
0
        public void IntegrationTest()
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = "Key1", Value = "Value1"
                },
                new PropertyPair {
                    Key = "#", Value = ""
                },
                new PropertyPair {
                    Key = "#", Value = " A TAB-LIKE COMMENT"
                },
                new PropertyPair {
                    Key = "#", Value = ""
                },
                new PropertyPair {
                    Key = "", Value = ""
                },
                new PropertyPair {
                    Key = "!", Value = "key = value"
                },
                new PropertyPair {
                    Key = "Key2", Value = "Value2"
                }
            });
            ICommand cmd = new StripCommentsCommand(file);

            cmd.Execute();

            Assert.Equal(3, file.GetProperties().Count());
            Assert.Equal("Key1", file.GetProperties().First().Key);
            Assert.Equal("Key2", file.GetProperties().Last().Key);
        }
Example #3
0
        public void EmptyFile_ShouldDoNothing()
        {
            IPropertiesFile file = new InMemoryPropertiesFile();
            ICommand        cmd  = new StripCommentsCommand(file);

            cmd.Execute();

            Assert.Empty(file.GetProperties());
        }
        public void NullPropertyKey_ShouldDoNothing()
        {
            IPropertiesFile file = new InMemoryPropertiesFile();
            ICommand        cmd  = new RemovePropertyByKeyCommand(file, null);

            cmd.Execute();

            Assert.Empty(file.GetProperties());
        }
Example #5
0
        public void NullProperty_ShouldNotEditEmptyCollection()
        {
            IPropertiesFile   file = new InMemoryPropertiesFile(new List <PropertyPair>());
            IUserConfirmation uc   = new ThrowOnTriggerUserConfirmation();
            ICommand          cmd  = new AddPropertyCommand(file, null, uc);

            cmd.Execute();

            Assert.Empty(file.GetProperties());
        }
Example #6
0
        public void FileWithComment_ShouldRemoveComment(string commentKey)
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = commentKey, Value = "Hello, I am a comment."
                }
            });
            ICommand cmd = new StripCommentsCommand(file);

            cmd.Execute();

            Assert.Empty(file.GetProperties());
        }
Example #7
0
        public void ShouldAddIntoEmptyCollection()
        {
            IPropertiesFile   file = new InMemoryPropertiesFile(new List <PropertyPair>());
            IUserConfirmation uc   = new ThrowOnTriggerUserConfirmation();
            var prop = new PropertyPair {
                Key = "greeting", Value = "Hello, World!"
            };
            ICommand cmd = new AddPropertyCommand(file, prop, uc);

            cmd.Execute();

            var collection = file.GetProperties();

            Assert.Single(collection);
            Assert.Same(prop, collection.First());
        }
        public void OnlyEmptyLines_ShouldRemoveEmptyLines()
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = "", Value = ""
                },
                new PropertyPair {
                    Key = "", Value = ""
                }
            });
            ICommand cmd = new StripEmptyLinesCommand(file);

            cmd.Execute();

            Assert.Empty(file.GetProperties());
        }
        public void CommentKey_ShouldDoNothing(string targetKey)
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = "#", Value = "I am a comment."
                },
                new PropertyPair {
                    Key = "!", Value = "I am also a comment."
                }
            });
            ICommand cmd = new RemovePropertyByKeyCommand(file, targetKey);

            cmd.Execute();

            Assert.Equal(2, file.GetProperties().Count());
        }
        public void EmptyPropertyKey_ShouldDoNothing()
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = "Key1", Value = "Value1"
                },
                new PropertyPair {
                    Key = "", Value = ""
                }
            });
            ICommand cmd = new RemovePropertyByKeyCommand(file, "");

            cmd.Execute();

            Assert.Equal(2, file.GetProperties().Count());
        }
Example #11
0
        public void NullProperty_ShouldNotEditFilledCollection()
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = "A", Value = "a"
                },
                new PropertyPair {
                    Key = "B", Value = "b"
                }
            });
            IUserConfirmation uc  = new ThrowOnTriggerUserConfirmation();
            ICommand          cmd = new AddPropertyCommand(file, null, uc);

            cmd.Execute();

            Assert.Equal(2, file.GetProperties().Count());
        }
Example #12
0
        public void FileWithoutComments_ShouldDoNothing()
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = "Key1", Value = "Value1"
                },
                new PropertyPair {
                    Key = "", Value = ""
                },
                new PropertyPair {
                    Key = "Key2", Value = "Value2"
                }
            });
            ICommand cmd = new StripCommentsCommand(file);

            cmd.Execute();

            Assert.Equal(3, file.GetProperties().Count());
        }
Example #13
0
        public void WhenUserDeniesShouldNotAddDuplicateValue()
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = "A", Value = "a"
                },
                new PropertyPair {
                    Key = "B", Value = "b"
                }
            });
            IUserConfirmation uc = new AlwaysDenyingUserConfirmation();
            var prop             = new PropertyPair {
                Key = "greeting", Value = "b"
            };
            ICommand cmd = new AddPropertyCommand(file, prop, uc);

            cmd.Execute();

            Assert.Equal(2, file.GetProperties().Count());
        }
Example #14
0
        public void ShouldUpdateExistingIfKeyAlreadyExists()
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = "A", Value = "a"
                },
                new PropertyPair {
                    Key = "B", Value = "b"
                }
            });
            IUserConfirmation uc = new ThrowOnTriggerUserConfirmation();
            var prop             = new PropertyPair {
                Key = "B", Value = "Hello, World!"
            };
            ICommand cmd = new AddPropertyCommand(file, prop, uc);

            cmd.Execute();

            Assert.Equal(2, file.GetProperties().Count());
            Assert.Equal("Hello, World!", file.GetProperties().Last().Value);
        }
Example #15
0
        public void ShouldBeAddedAtTheEndOfCollection()
        {
            IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>
            {
                new PropertyPair {
                    Key = "A", Value = "a"
                },
                new PropertyPair {
                    Key = "B", Value = "b"
                }
            });
            IUserConfirmation uc = new ThrowOnTriggerUserConfirmation();
            var prop             = new PropertyPair {
                Key = "greeting", Value = "Hello, World!"
            };
            ICommand cmd = new AddPropertyCommand(file, prop, uc);

            cmd.Execute();

            var collection = file.GetProperties();

            Assert.Equal(3, collection.Count());
            Assert.Same(prop, collection.Last());
        }