public void Setup()
 {
     this.loggerMock         = new Mock <ILogger>();
     this.fileWrapperMock    = new Mock <IFileWrapper>();
     this.pathToHostsFile    = "/etc/hosts";
     this.hostFileParser     = new HostFileParser(this.loggerMock.Object);
     this.hostFileDownloader = new HostFileDownloader(this.loggerMock.Object,
                                                      new HttpClient(), this.hostFileParser);
     this.hostFileWriter = new HostFileWriter(this.loggerMock.Object,
                                              this.fileWrapperMock.Object, this.hostFileParser, this.pathToHostsFile);
 }
Beispiel #2
0
        private static void Setup(string[] args)
        {
            log = new LoggerConfiguration()
                  .WriteTo.Console()
                  .CreateLogger();

            fileWrapper      = new FileWrapper();
            appConfiguration = new AppConfiguration(log, fileWrapper, args);
            ConfigureLogger();
            httpClient         = new HttpClient();
            hostFileParser     = new HostFileParser(log);
            hostFileWriter     = new HostFileWriter(log, fileWrapper, hostFileParser, appConfiguration.ConfigurationOptions.HostsFilePath);
            hostFileDownloader = new HostFileDownloader(log, httpClient, hostFileParser);
        }
        public GeneratorActionResult ExecuteAction(GeneratorArguments arguments, Core.InputFields.ActionInputValues values, Dictionary <string, string> parameters)
        {
            var editHostsFile = values.GetBool("EditHostsFile");
            var hostName      = values.GetString("HostName");

            if (editHostsFile)
            {
                // Create backup
                System.IO.File.WriteAllText(string.Concat(HostFileWriter.HostFilePath, ".backup"),
                                            System.IO.File.ReadAllText(HostFileWriter.HostFilePath, Encoding.UTF8),
                                            Encoding.UTF8);

                var hostEditor = new HostFileWriter();

                hostEditor.AddOrUpdateEntry(hostName, "127.0.0.1", String.Concat("Dev URL for ", arguments.Name));

                hostEditor.Save();
            }

            return(new GeneratorActionResult(true, ""));
        }