コード例 #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);
        }
コード例 #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);
        }
コード例 #3
0
ファイル: Operation.cs プロジェクト: gheorghitamutu/Hyped
        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();
        }
コード例 #4
0
ファイル: Tui.cs プロジェクト: b1thunt3r/WinInfo
        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);
        }
コード例 #5
0
        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);
            }
        }
コード例 #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);
                }
            }
        }
コード例 #7
0
 public void Initialize()
 {
     _system = ComputerSystem.GetInstances();
 }