Neon.Xunit.HostsFixture.RemoveSection(string)

Here are the examples of the csharp api Neon.Xunit.HostsFixture.RemoveSection(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

19 Source : HostsFixture.cs
with Apache License 2.0
from nforgeio

public static void EnsureReset()
        {
            RemoveSection();
        }

19 Source : HostsFixture.cs
with Apache License 2.0
from nforgeio

public void Commit()
        {
            // Use a static lock to ensure that only once fixture instance
            // at a time can munge the [hosts] file.

            lock (syncLock)
            {
                var sectionHostname = GetSectionHostname(fixtureId);

                // Remove any existing section for this instance.

                RemoveSection(fixtureId);

                // Append the fixture section to the end of the [hosts] file.

                var sb = new StringBuilder();

                sb.AppendLine($"# START-NEON-HOSTS-FIXTURE-{fixtureId}");

                sb.AppendLine($"{dummyIP, -15} {sectionHostname}");

                foreach (var record in records)
                {
                    sb.AppendLine($"{record.Item2, -15} {record.Item1}");
                }

                sb.AppendLine($"# END-NEON-HOSTS-FIXTURE-{fixtureId}");

                retryFile.Invoke(
                    () =>
                    {
                        File.AppendAllText(HostsPath, sb.ToString());
                    });

                if (NeonHelper.IsWindows)
                {
                    // Flush the DNS cache (and I believe this reloads the [hosts] file too).

                    var response = NeonHelper.ExecuteCapture("ipconfig", "/flushdns");

                    if (response.ExitCode != 0)
                    {
                        throw new ToolException($"ipconfig [exitcode={response.ExitCode}]: {response.ErrorText}");
                    }
                }
                else if (NeonHelper.IsOSX)
                {
                    // $todo(jefflill):
                    //
                    // We may need to clear the OSX DNS cache here.
                    //
                    // Here's some information on how to do this:
                    //
                    //      https://help.dreamhost.com/hc/en-us/articles/214981288-Flushing-your-DNS-cache-in-Mac-OS-X-and-Linux

                    throw new NotImplementedException("$todo(jefflill): Purge the OSX DNS cache.");
                }

                // Wait for the local DNS resolver to indicate that it's picked
                // up the changes by verifying that the section hostname resolves.

                retryReady.Invoke(
                    () =>
                    {
                        var addresses = GetHostAddresses(sectionHostname);

                        if (addresses.Length == 0)
                        {
                            throw new NotReadyException($"Waiting for [{sectionHostname}] to resolve by the local DNS resolver.");
                        }
                    });
            }
        }

19 Source : HostsFixture.cs
with Apache License 2.0
from nforgeio

public override void Reset()
        {
            records.Clear();
            RemoveSection(fixtureId);
        }

19 Source : HostsFixture.cs
with Apache License 2.0
from nforgeio

protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (!base.IsDisposed)
                {
                    // Ensure that there are no remaining temporary records
                    // in the hosts file.

                    RemoveSection(fixtureId);
                    GC.SuppressFinalize(this);
                }
            }
        }