Beispiel #1
0
        public void GetInstancesWithCondition_ExpectingOneElementBeingHostMachine()
        {
            var sut = ComputerSystem.GetInstances($"Name='{Environment.MachineName}'");

            Assert.AreEqual(sut.Count, 1);
            Assert.AreEqual(sut.Cast <ComputerSystem>().ToList().FirstOrDefault()?.Name, Environment.MachineName);
        }
Beispiel #2
0
        public void GetInstances_ExpectingAtLeastOneElementBeingHostMachine()
        {
            var sut = ComputerSystem.GetInstances();

            Assert.IsTrue(sut.Count > 0);
            Assert.AreEqual(sut.Cast <ComputerSystem>().ToList().FirstOrDefault()?.Name, Environment.MachineName);
        }
Beispiel #3
0
        static public void GetComputerSystem(Dictionary <string, object> args, out ComputerSystem ComputerSystem)
        {
            ComputerSystem = ComputerSystem.GetInstances()
                             .Where((cs) =>
            {
                return(args.ToList().All(pair =>
                {
                    var propertyName = pair.Key;
                    var propertyValue = pair.Value;

                    switch (propertyName)
                    {
                    case nameof(cs.Name):
                        var computerSystemName = Convert.ToString(cs.LateBoundObject[nameof(cs.Name)]);
                        var Name = Convert.ToString(propertyValue);
                        return string.Compare(computerSystemName, Name, true, CultureInfo.InvariantCulture) == 0;

                    default:
                        throw new Exception("Property value not handled or invalid!");
                    }
                }));
            })
                             .ToList()
                             .First();
        }
Beispiel #4
0
        public Tui()
        {
            var scope       = Wmi.GetScope();
            var enumOptions = new EnumerationOptions {
                EnsureLocatable = true
            };

            _system          = ComputerSystem.GetInstances(scope, enumOptions).Cast <ComputerSystem>().FirstOrDefault();
            _processor       = Processor.GetInstances(scope, enumOptions).Cast <Processor>().FirstOrDefault();
            _networkAdapters = NetworkAdapter.GetInstances(scope, enumOptions)
                               .Cast <NetworkAdapter>()
                               .Where(n => n.PhysicalAdapter);
            _operatingSystem = new OperatingSystem0(scope);
        }
        private void RenameComputerName()
        {
            logger.Info("Rename Computer");
            try
            {
                var computer = ComputerSystem.GetInstances().OfType <ComputerSystem>().First();

                var result = computer.Rename(DesiredComputerName, null, null);

                if (result != 0)
                {
                    logger.Error("Failed to rename due to error code {0}", result);
                }
                else
                {
                    logger.Info("Rename Succeeded");
                }
            }
            catch (Exception ex)
            {
                logger.FatalException("ComputerSystem.Rename threw exception.", ex);
            }
        }
Beispiel #6
0
        public void DestroySystem_ExpectingGetInstancesWithElementNameConditionCountZero()
        {
            using (var viridianUtils = new ViridianUtils())
            {
                viridianUtils.SUT_ComputerSystemMO(
                    ViridianUtils.GetCurrentMethod(),
                    out uint ReturnValue,
                    out ManagementPath Job,
                    out ManagementPath ResultingSystem);

                using (var computerSystem = new ComputerSystem(ResultingSystem))
                {
                    var name = computerSystem.Name;

                    viridianUtils.Dispose(); // destroy VM

                    var ReferenceConfigurationInstances = ComputerSystem.GetInstances().Where((cs) => cs.Name == name).ToList();

                    Assert.AreEqual(0U, ReturnValue);
                    Assert.AreEqual(0, ReferenceConfigurationInstances.Count);
                }
            }
        }
Beispiel #7
0
 public void Initialize()
 {
     _system = ComputerSystem.GetInstances();
 }