Exemplo n.º 1
0
        public void SetDnsConfigurationDnsFromDHCPTest()
        {
            NetworkInterface ni = null;

            RunTest <DNSInformation>(

                new Backup <DNSInformation>(() =>
            {
                DNSInformation originalInformation = GetDnsConfiguration();
                string reason = null;
                Assert((originalInformation != null) && originalInformation.IsValidDnsInformation(false, out reason),
                       reason == null ? "Failed to get original DNS configuration" : reason,
                       "Check that valid DNS configuration returned from the DUT");

                ni = TurnOnDhcpIpv4();

                return(originalInformation);
            }),

                () =>
            {
                DNSInformation testInformation = new DNSInformation();
                testInformation.FromDHCP       = true;

                SetDnsConfiguration(testInformation);

                double timeout = ((double)_operationDelay) / 1000;

                BeginStep(string.Format("Wait {0} seconds to allow the DUT to interact with DHCP server", timeout.ToString("0.000")));
                Sleep(_operationDelay);
                StepPassed();

                DNSInformation actualInformation = GetDnsConfiguration();

                string reason = null;
                Assert((actualInformation != null) && actualInformation.IsValidDnsInformation(false, out reason),
                       reason == null ? "Failed to get original DNS configuration" : reason,
                       "Check that original DNS configuration returned from the DUT");


                Assert(actualInformation != null, "Failed to get current DNS configuration", "Check that current DNS configuration returned from the DUT");

                BeginStep("Check current DNS configuration");

                bool bAllEquals;

                bool bEquals = (actualInformation.FromDHCP == testInformation.FromDHCP);

                LogStepEvent(string.Format("FromDHCP: expected - {0}, actual - {1}", testInformation.FromDHCP,
                                           actualInformation.FromDHCP));

                bAllEquals = bEquals;

                string actualIpDescription;
                actualIpDescription = DeviceManagementNetworkTestSuite.DumpIPArray(actualInformation.DNSManual);

                string expectedAddress = "No IP Address";

                if (actualInformation.DNSManual != null && actualInformation.DNSManual.Count() > 0)
                {
                    bEquals = false;
                }
                else
                {
                    bEquals = true;
                }

                LogStepEvent(string.Format("DNSManual: expected - {0}, actual - {1}",
                                           expectedAddress, actualIpDescription));

                bAllEquals = bAllEquals && bEquals;

                /*************************************************/

                actualIpDescription = DeviceManagementNetworkTestSuite.DumpIPArray(actualInformation.DNSFromDHCP);

                if (actualInformation.DNSFromDHCP == null)
                {
                    bEquals = false;
                }
                else
                {
                    bEquals = (actualInformation.DNSFromDHCP.Length > 0);
                }

                string expectedDescription = "List of DNS servers";

                LogStepEvent(string.Format("DNSFromDHCP: expected - {0}, actual - {1}",
                                           expectedDescription, actualIpDescription));

                bAllEquals = bAllEquals && bEquals;

                /*********************************************************/

                if (!bAllEquals)
                {
                    throw new AssertException("Current DNS configuration differs from configuration was set");
                }

                StepPassed();
            },

                (originalInformation) =>
            {
                SetDnsConfiguration(originalInformation, "Restore DNS configuration");

                // if DHCP was ON, it has not been changed
                if (!ni.IPv4.Config.DHCP)
                {
                    // restore network interface configuration
                    RestoreNetworkInterface(ni.token, ni);
                }
            }
                );
        }
Exemplo n.º 2
0
        public void SetDnsConfigurationDnsManualIpv6Test()
        {
            NetworkInterface ni = null;

            RunTest <DNSInformation>(

                new Backup <DNSInformation>(() =>
            {
                DNSInformation originalInformation = GetDnsConfiguration();
                Assert(originalInformation != null, "Failed to get original DNS configuration", "Check that original DNS configuration returned from the DUT");

                ni = TurnOffDhcpIpv6();

                return(originalInformation);
            }),

                () =>
            {
                DNSInformation testInformation = new DNSInformation();
                testInformation.FromDHCP       = false;
                testInformation.DNSManual      =
                    new IPAddress[]
                {
                    new IPAddress()
                    {
                        IPv6Address = _environmentSettings.DnsIpv6, Type = IPType.IPv6
                    }
                };

                SetDnsConfiguration(testInformation);

                double timeout = ((double)_operationDelay) / 1000;

                BeginStep(string.Format("Wait {0} seconds to allow the DUT to apply settings", timeout.ToString("0.000")));
                Sleep(_operationDelay);
                StepPassed();

                DNSInformation actualInformation = GetDnsConfiguration();

                Assert(actualInformation != null, "Failed to get current DNS configuration", "Check that current DNS configuration returned from the DUT");

                BeginStep("Check current DNS configuration");

                bool bAllEquals;

                bool bEquals = (actualInformation.FromDHCP == testInformation.FromDHCP);

                LogStepEvent(string.Format("FromDHCP: expected - {0}, actual - {1}", testInformation.FromDHCP,
                                           actualInformation.FromDHCP));

                bAllEquals = bEquals;

                string actualIpDescription;
                actualIpDescription = DeviceManagementNetworkTestSuite.DumpIPArray(actualInformation.DNSManual);

                string expectedAddress = testInformation.DNSManual[0].IPv6Address;
                IPType expectedType    = testInformation.DNSManual[0].Type;

                if (actualInformation.DNSManual.Where(
                        A => A.Type == expectedType && A.IPv6Address == expectedAddress).Count() > 0)
                {
                    bEquals = true;
                }
                else
                {
                    bEquals = false;
                }

                LogStepEvent(string.Format("DNSManual: expected - {0} should be presented, actual - {1}",
                                           expectedAddress, actualIpDescription));

                bAllEquals = bAllEquals && bEquals;

                /*************************************************/

                actualIpDescription = DeviceManagementNetworkTestSuite.DumpIPArray(actualInformation.DNSFromDHCP);

                if (actualInformation.DNSFromDHCP == null)
                {
                    bEquals = true;
                }
                else
                {
                    bEquals = (actualInformation.DNSFromDHCP.Length == 0);
                }

                string expectedDescription = "No DNSFromDHCP";

                LogStepEvent(string.Format("DNSFromDHCP: expected - {0}, actual - {1}",
                                           expectedDescription, actualIpDescription));

                bAllEquals = bAllEquals && bEquals;

                /*********************************************************/

                if (!bAllEquals)
                {
                    throw new AssertException("Current DNS configuration differs from configuration was set");
                }

                StepPassed();
            },

                (originalInformation) =>
            {
                SetDnsConfiguration(originalInformation, "Restore DNS configuration");
                if (ni.IPv6.Config.DHCP != IPv6DHCPConfiguration.Off)
                {
                    // restore network interface configuration
                    RestoreNetworkInterface(ni.token, ni);
                }
            }
                );
        }