Ejemplo n.º 1
0
        private static QueryProcessResponse CreateResponse(Type type, IEnumerable items, ProcessURI uri)
        {
            var domains = new DomainCollection();
            var enumerator = items.GetEnumerator();
            while (enumerator.MoveNext())
            {
                var instance = enumerator.Current;
                var entity = new EntityDomain(type, uri)
                {
                    Instance = instance,
                    Value = ContextFactory.GetContext(type).GetID(instance),
                };

                domains.Add(entity);
            }
            return new QueryProcessResponse(type, domains) { URI = uri };
        }
Ejemplo n.º 2
0
        private void ReflectTestMethod(
            RunInvokerTree tree,
            RunInvokerVertex parent,
            object fixture,
            MethodInfo method,
            IgnoreAttribute ignore,
            ExplicitAttribute expl)
        {
            // Check if fixture/method is ignored/explicit
            if (ignore == null && TypeHelper.HasCustomAttribute(method, typeof(IgnoreAttribute)))
            {
                ignore = TypeHelper.GetFirstCustomAttribute(method, typeof(IgnoreAttribute)) as IgnoreAttribute;
            }
            if (expl == null && TypeHelper.HasCustomAttribute(method, typeof(ExplicitAttribute)))
            {
                expl = TypeHelper.GetFirstCustomAttribute(method, typeof(ExplicitAttribute)) as ExplicitAttribute;
            }

            if (ignore != null)
            {
                // Do not generate unnecessary test cases
                IgnoredLoadingRunInvoker invoker = new IgnoredLoadingRunInvoker(this, method, ignore.Description);
                tree.AddChild(parent, invoker);
            }
            else if (expl != null)
            {
                // Do not generate unnecessary test cases
                IgnoredLoadingRunInvoker invoker = new IgnoredLoadingRunInvoker(this, method, expl.Description);
                tree.AddChild(parent, invoker);
            }
            else
            {
                CombinatorialTestAttribute testAttribute = TypeHelper.GetFirstCustomAttribute(method, typeof(CombinatorialTestAttribute))
                                                           as CombinatorialTestAttribute;

                ParameterInfo[] parameters = method.GetParameters();
                if (parameters.Length == 0)
                {
                    Exception ex = new Exception("No parameters");
                    MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method);
                    tree.AddChild(parent, invoker);
                    return;
                }

                // create the models
                DomainCollection domains        = new DomainCollection();
                Type[]           parameterTypes = new Type[parameters.Length];
                int index = 0;
                foreach (ParameterInfo parameter in parameters)
                {
                    parameterTypes[index] = parameter.ParameterType;

                    DomainCollection pdomains = new DomainCollection();
                    foreach (UsingBaseAttribute usingAttribute in parameter.GetCustomAttributes(typeof(UsingBaseAttribute), true))
                    {
                        try
                        {
                            usingAttribute.GetDomains(pdomains, parameter, fixture);
                        }
                        catch (Exception ex)
                        {
                            Exception pex = new Exception("Failed while loading domains from parameter " + parameter.Name,
                                                          ex);
                            MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, pex, method);
                            tree.AddChild(parent, invoker);
                        }
                    }
                    if (pdomains.Count == 0)
                    {
                        Exception ex = new Exception("Could not find domain for argument " + parameter.Name);
                        MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method);
                        tree.AddChild(parent, invoker);
                        return;
                    }
                    domains.Add(Domains.ToDomain(pdomains));

                    index++;
                }

                // get the validator method if any
                MethodInfo validator = null;
                if (testAttribute.TupleValidatorMethod != null)
                {
                    validator = fixture.GetType().GetMethod(testAttribute.TupleValidatorMethod, parameterTypes);
                    if (validator == null)
                    {
                        Exception ex = new Exception("Could not find validator method " + testAttribute.TupleValidatorMethod);
                        MethodFailedLoadingRunInvoker invoker = new MethodFailedLoadingRunInvoker(this, ex, method);
                        tree.AddChild(parent, invoker);
                        return;
                    }
                }

                // we make a cartesian product of all those
                foreach (ITuple tuple in Products.Cartesian(domains))
                {
                    // create data domains
                    DomainCollection tdomains = new DomainCollection();
                    for (int i = 0; i < tuple.Count; ++i)
                    {
                        IDomain dm = (IDomain)tuple[i];
                        tdomains.Add(dm);
                    }

                    // computing the pairwize product
                    foreach (ITuple ptuple in testAttribute.GetProduct(tdomains))
                    {
                        if (validator != null)
                        {
                            bool isValid = (bool)validator.Invoke(fixture, ptuple.ToObjectArray());
                            if (!isValid)
                            {
                                continue;
                            }
                        }

                        TupleRunInvoker invoker  = new TupleRunInvoker(this, method, tuple, ptuple);
                        IRunInvoker     dinvoker = DecoratorPatternAttribute.DecoreInvoker(method, invoker);
                        tree.AddChild(parent, dinvoker);
                    }
                }
            }
        }
        /// <summary>
        /// Initialize information from PTF config
        /// </summary>
        /// <param name="testSite"></param>
        public override void Initialize(ITestSite testSite)
        {
            base.Initialize(testSite);

            Site.Log.Add(LogEntryKind.Debug, "Read common properties from PTF configure file.");

            AllowBreakEnvironment    = GetBoolProperty(propertyGroup + "AllowBreakEnvironment");
            DomainFunctionLevel      = GetEnumProperty <DomainFunctionLevel>(propertyGroup + "DomainFunctionLevel");
            DomainAdminGroup         = GetProperty(propertyGroup + "DomainAdminGroup");
            DomainAdministratorName  = GetProperty(propertyGroup + "DomainAdministratorName", true);
            DomainUserPassword       = GetProperty(propertyGroup + "DomainUserPassword", true);
            PrimaryDomainDnsName     = GetProperty(propertyGroup + "PrimaryDomain.DNSName", true);
            PrimaryDomainNetBiosName = GetProperty(propertyGroup + "PrimaryDomain.NetBiosName" ?? (PrimaryDomainDnsName.Split('.'))[0].ToString());
            PrimaryDomainSrvGUID     = GetProperty(propertyGroup + "PrimaryDomain.ServerGUID", true);
            PrimaryDomainSID         = GetProperty(propertyGroup + "PrimaryDomain.SID", true);
            PDCNetbiosName           = GetProperty(propertyGroup + "WritableDC1.NetbiosName", true);
            PDCPassword            = GetProperty(propertyGroup + "WritableDC1.Password", true);
            PDCIPAddress           = GetProperty(propertyGroup + "WritableDC1.IPAddress");
            PDCOSVersion           = GetEnumProperty <ServerVersion>(propertyGroup + "WritableDC1.OSVersion");
            PDCIsWindows           = (PDCOSVersion == ServerVersion.NonWin ? false : true);
            SDCNetbiosName         = GetProperty(propertyGroup + "WritableDC2.NetbiosName");
            SDCPassword            = GetProperty(propertyGroup + "WritableDC2.Password");
            SDCIPAddress           = GetProperty(propertyGroup + "WritableDC2.IPAddress");
            SDCOSVersion           = GetEnumProperty <ServerVersion>(propertyGroup + "WritableDC2.OSVersion");
            SDCIsWindows           = (SDCOSVersion == ServerVersion.NonWin ? false : true);
            RODCNetbiosName        = GetProperty(propertyGroup + "RODC.NetbiosName");
            RODCPassword           = GetProperty(propertyGroup + "RODC.Password");
            RODCIPAddress          = GetProperty(propertyGroup + "RODC.IPAddress");
            RODCOSVersion          = GetEnumProperty <ServerVersion>(propertyGroup + "RODC.OSVersion");
            RODCIsWindows          = (RODCOSVersion == ServerVersion.NonWin ? false : true);
            ChildDomainDnsName     = GetProperty(propertyGroup + "ChildDomain.DNSName");
            ChildDomainNetBiosName = GetProperty(propertyGroup + "ChildDomain.NetBiosName") ?? (ChildDomainDnsName.Split('.'))[0].ToString();
            CDCNetbiosName         = GetProperty(propertyGroup + "CDC.NetbiosName");
            CDCIPAddress           = GetProperty(propertyGroup + "CDC.IPAddress");
            CDCOSVersion           = GetEnumProperty <ServerVersion>(propertyGroup + "CDC.OSVersion");
            CDCIsWindows           = (CDCOSVersion == ServerVersion.NonWin ? false : true);
            TrustDomainDnsName     = GetProperty(propertyGroup + "TrustDomain.DNSName");
            TrustDomainNetBiosName = GetProperty(propertyGroup + "TrustDomain.NetBiosName") ?? (TrustDomainDnsName.Split('.'))[0].ToString();
            TDCNetbiosName         = GetProperty(propertyGroup + "TDC.NetbiosName");
            TDCIPAddress           = GetProperty(propertyGroup + "TDC.IPAddress");
            TDCOSVersion           = GetEnumProperty <ServerVersion>(propertyGroup + "TDC.OSVersion");
            TDCIsWindows           = (TDCOSVersion == ServerVersion.NonWin ? false : true);
            DMNetbiosName          = GetProperty(propertyGroup + "DM.NetbiosName");
            DMPassword             = GetProperty(propertyGroup + "DM.Password");
            DMOldPassword          = GetProperty(propertyGroup + "DM.OldPassword");
            DMIPAddress            = GetProperty(propertyGroup + "DM.IPAddress");
            ENDPOINTNetbiosName    = GetProperty(propertyGroup + "ENDPOINT.NetbiosName", true);
            ENDPOINTPassword       = GetProperty(propertyGroup + "ENDPOINT.Password", true);
            ENDPOINTOldPassword    = GetProperty(propertyGroup + "ENDPOINT.OldPassword");
            ENDPOINTIPAddress      = GetProperty(propertyGroup + "ENDPOINT.IPAddress");
            ADLDSInstanceName      = GetProperty(propertyGroup + "ADLDSInstanceName");
            ADDSPortNum            = GetProperty(propertyGroup + "ADDSPortNum");
            ADLDSPortNum           = GetProperty(propertyGroup + "ADLDSPortNum");
            ADLDSSSLPortNum        = GetProperty(propertyGroup + "ADLDSSSLPortNum");
            LDSApplicationNC       = GetProperty(propertyGroup + "LDSApplicationNC");
            ClientUserName         = GetProperty(propertyGroup + "ClientUserName");
            ClientUserPassword     = GetProperty(propertyGroup + "ClientUserPassword");

            Site.Log.Add(LogEntryKind.Debug, "Read common properties from PTF configure file completed.");
            Site.Log.Add(LogEntryKind.Debug, "Construct common classes for domain, domain controller and endpoint.");

            domains           = new DomainCollection();
            domainControllers = new DomainControllerCollection();

            Domain primaryDomain = new Domain(PrimaryDomainDnsName, PrimaryDomainNetBiosName);

            domains.Add(primaryDomain);
            DomainController pdc  = new DomainController(primaryDomain, PDCNetbiosName, PDCIPAddress, (ServerVersion)PDCOSVersion);
            DomainController sdc  = new DomainController(primaryDomain, SDCNetbiosName, SDCIPAddress, (ServerVersion)SDCOSVersion);
            DomainController rodc = new DomainController(primaryDomain, RODCNetbiosName, RODCIPAddress, (ServerVersion)RODCOSVersion);

            domainControllers.Add(pdc);
            domainControllers.Add(sdc);
            domainControllers.Add(rodc);

            if (string.IsNullOrEmpty(ChildDomainDnsName))
            {
                Site.Log.Add(LogEntryKind.Warning, "ChildDomainDnsName is not configured in PTF, indicating the environment has no child domain.");
            }
            else
            {
                Domain           childDomain = new Domain(ChildDomainDnsName);
                DomainController cdc         = new DomainController(childDomain, CDCNetbiosName, CDCIPAddress, (ServerVersion)CDCOSVersion);
                domains.Add(childDomain);
                domainControllers.Add(cdc);
            }

            if (string.IsNullOrEmpty(TrustDomainDnsName))
            {
                Site.Log.Add(LogEntryKind.Warning, "TrustDomainDnsName is not configured in PTF, indicating the environment has no trusted domain.");
            }
            else
            {
                Domain           trustDomain = new Domain(TrustDomainDnsName);
                DomainController tdc         = new DomainController(trustDomain, TDCNetbiosName, TDCIPAddress, (ServerVersion)TDCOSVersion);
                domains.Add(trustDomain);
                domainControllers.Add(tdc);
            }

            Computer endpoint = new Computer(primaryDomain, ENDPOINTNetbiosName, ENDPOINTIPAddress);

            domainMembers = new ComputerCollection();
            domainMembers.Add(endpoint);

            Site.Log.Add(LogEntryKind.Debug, "Construct common classes for domain, domain controller and endpoint completed.");
        }
Ejemplo n.º 4
0
 public void AddReader(BookReader reader)
 {
     _Readers.Add(reader);
 }