예제 #1
0
        public void Save_SavesHostFileToStream()
        {
            var actualStream   = new MemoryStream();
            var expectedStream = TestContext.GetResourceStream("FluentInstallation.Web.Hosts.Hosts.txt");

            var hostsFile = new HostsFile();

            hostsFile.AddComment("This is a test comment line 1");
            hostsFile.AddComment("This is a test comment line 2");

            hostsFile.AddHostEntry(new HostEntry()
            {
                IpAddress = "172.0.1.1", HostName = "mysite.co.uk", Description = string.Empty, IsEnabled = true
            });
            hostsFile.AddHostEntry(new HostEntry()
            {
                IpAddress = "172.0.1.2", HostName = "mysite.de", Description = string.Empty, IsEnabled = true
            });
            hostsFile.AddHostEntry(new HostEntry()
            {
                IpAddress = "172.0.1.3", HostName = "mysite.ie", Description = "This is a comment", IsEnabled = true
            });

            hostsFile.Save(actualStream);

            actualStream.Position = 0;
            var actual   = actualStream.ReadToEnd();
            var expected = expectedStream.ReadToEnd();

            Assert.Equal(expected, actual);
        }
예제 #2
0
        public void AddComment_AddsCommentToHostFile()
        {
            var sut = new HostsFile();

            sut.AddComment("Test comment");
            Assert.Equal(1, sut.AllComments().Count());
        }
        public void RemoveComment_RemovesCommentFromHostFile()
        {
            var sut = new HostsFile();
            sut.AddComment("Test comment");

            sut.RemoveComment("Test comment");

            Assert.Empty(sut.AllComments());
        }
예제 #4
0
        public void RemoveComment_RemovesCommentFromHostFile()
        {
            var sut = new HostsFile();

            sut.AddComment("Test comment");

            sut.RemoveComment("Test comment");

            Assert.Empty(sut.AllComments());
        }
예제 #5
0
        public static HostsFile Load(Stream stream)
        {
            var hostsFile = new HostsFile();

            var reader = new StreamReader(stream);

            while (reader.Peek() >= 0)
            {
                string line = reader.ReadLine();

                HostEntry hostEntry;

                if (HostEntry.TryParse(line, out hostEntry))
                {
                    hostsFile.AddHostEntry(hostEntry);
                }
                else
                {
                    hostsFile.AddComment(line.TrimStart('#'));
                }
            }

            return(hostsFile);
        }
예제 #6
0
        public static HostsFile Load(Stream stream)
        {
            var hostsFile = new HostsFile();

            var reader = new StreamReader(stream);

            while (reader.Peek() >= 0)
            {
                string line = reader.ReadLine();

                HostEntry hostEntry;

                if (HostEntry.TryParse(line, out hostEntry))
                {
                    hostsFile.AddHostEntry(hostEntry);
                }
                else
                {
                    hostsFile.AddComment(line.TrimStart('#'));
                }
            }

            return hostsFile;
        }
 public void AddComment_AddsCommentToHostFile()
 {
     var sut = new HostsFile();
     sut.AddComment("Test comment");
     Assert.Equal(1, sut.AllComments().Count());
 }
        public void Save_SavesHostFileToStream()
        {
            var actualStream = new MemoryStream();
            var expectedStream = TestContext.GetResourceStream("FluentInstallation.Web.Hosts.Hosts.txt");

            var hostsFile = new HostsFile();
            hostsFile.AddComment("This is a test comment line 1");
            hostsFile.AddComment("This is a test comment line 2");

            hostsFile.AddHostEntry(new HostEntry() { IpAddress = "172.0.1.1", HostName = "mysite.co.uk", Description = string.Empty, IsEnabled = true });
            hostsFile.AddHostEntry(new HostEntry() { IpAddress = "172.0.1.2", HostName = "mysite.de", Description = string.Empty, IsEnabled = true });
            hostsFile.AddHostEntry(new HostEntry() { IpAddress = "172.0.1.3", HostName = "mysite.ie", Description = "This is a comment", IsEnabled = true });

            hostsFile.Save(actualStream);

            actualStream.Position = 0;
            var actual = actualStream.ReadToEnd();
            var expected = expectedStream.ReadToEnd();

            Assert.Equal(expected, actual);
        }