Exemplo n.º 1
0
        public void GetHashCode_TwoIdenticalObjects_BothInitialized_HashCodesAreEqual()
        {
            // Arrange
            var object1 = new SystemPerformanceData
            {
                MemoryStatus = new SystemMemoryInformation {
                    AvailableMemoryInGB = 3
                },
                ProcessorStatus = new ProcessorUtilizationInformation {
                    ProcessorUtilizationInPercent = 30d
                }
            };

            var object2 = new SystemPerformanceData
            {
                MemoryStatus = new SystemMemoryInformation {
                    AvailableMemoryInGB = 3
                },
                ProcessorStatus = new ProcessorUtilizationInformation {
                    ProcessorUtilizationInPercent = 30d
                }
            };

            // Act
            int hashCodeObject1 = object1.GetHashCode();
            int hashCodeObject2 = object2.GetHashCode();

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
Exemplo n.º 2
0
        public void GetHashCode_SameHashCodeIsReturnedEveryTimeTheMethodIsCalled_AsLongAsTheObjectDoesNotChange()
        {
            // Arrange
            var memoryStatus = new SystemMemoryInformation {
                AvailableMemoryInGB = 3
            };
            var processorStatus = new ProcessorUtilizationInformation {
                ProcessorUtilizationInPercent = 30d
            };
            var storageStatus = new SystemStorageInformation();

            var object1 = new SystemPerformanceData {
                MemoryStatus = memoryStatus, ProcessorStatus = processorStatus, StorageStatus = storageStatus
            };

            int expectedHashcode = object1.GetHashCode();

            for (var i = 0; i < 100; i++)
            {
                // Act
                object1.MemoryStatus    = memoryStatus;
                object1.ProcessorStatus = processorStatus;
                object1.StorageStatus   = storageStatus;

                int generatedHashCode = object1.GetHashCode();

                // Assert
                Assert.AreEqual(expectedHashcode, generatedHashCode);
            }
        }
Exemplo n.º 3
0
        public void GetHashCode_TwoDistinctObjects_HashCodesAreDifferent()
        {
            // Arrange
            var object1 = new SystemPerformanceData
            {
                MemoryStatus = new SystemMemoryInformation {
                    AvailableMemoryInGB = 3
                },
                ProcessorStatus = new ProcessorUtilizationInformation {
                    ProcessorUtilizationInPercent = 30d
                }
            };

            var object2 = new SystemPerformanceData
            {
                MemoryStatus = new SystemMemoryInformation {
                    AvailableMemoryInGB = 4
                },
                ProcessorStatus = new ProcessorUtilizationInformation {
                    ProcessorUtilizationInPercent = 90d
                }
            };

            // Act
            int hashCodeObject1 = object1.GetHashCode();
            int hashCodeObject2 = object2.GetHashCode();

            // Assert
            Assert.AreNotEqual(hashCodeObject1, hashCodeObject2);
        }
Exemplo n.º 4
0
        public void Equals_TwoIdenticalInitializedObjects_ResultIsTrue()
        {
            // Arrange
            var object1 = new SystemPerformanceData
            {
                MemoryStatus = new SystemMemoryInformation {
                    AvailableMemoryInGB = 3
                },
                ProcessorStatus = new ProcessorUtilizationInformation {
                    ProcessorUtilizationInPercent = 30d
                }
            };

            var object2 = new SystemPerformanceData
            {
                MemoryStatus = new SystemMemoryInformation {
                    AvailableMemoryInGB = 3
                },
                ProcessorStatus = new ProcessorUtilizationInformation {
                    ProcessorUtilizationInPercent = 30d
                }
            };

            // Act
            bool result = object1.Equals(object2);

            // Assert
            Assert.IsTrue(result);
        }
        public void GetSystemStatusViewModel_MemoryStatusIsNotNull_ResultContainsMemoryStatusDataPoint()
        {
            // Arrage
            var memoryStatus = new SystemMemoryInformation {
                UsedMemoryInGB = 1d, AvailableMemoryInGB = 10d
            };
            var systemPerformanceInformation = new SystemPerformanceData {
                MemoryStatus = memoryStatus
            };
            var systemInformation = new SystemInformation {
                SystemPerformance = systemPerformanceInformation
            };
            var memoryStatusViewModel = new SystemStatusPointViewModel {
                Name = "Memory Status", Value = 10d
            };

            var processorStatusOrchestrator = new Mock <IProcessorStatusOrchestrator>();
            var memoryStatusOrchestrator    = new Mock <IMemoryStatusOrchestrator>();

            memoryStatusOrchestrator.Setup(p => p.GetMemoryUtilizationInPercent(It.IsAny <SystemMemoryInformation>())).Returns(memoryStatusViewModel);

            var storageStatusOrchestrator = new Mock <IStorageStatusOrchestrator>();

            var systemStatusOrchestrator = new SystemStatusOrchestrator(
                processorStatusOrchestrator.Object, memoryStatusOrchestrator.Object, storageStatusOrchestrator.Object);

            // Act
            var result = systemStatusOrchestrator.GetSystemStatusViewModel(systemInformation);

            // Assert
            Assert.AreEqual(memoryStatusViewModel.Value, result.DataPoints.First(d => d.Name.Equals(memoryStatusViewModel.Name)).Value);
        }
        private void UpdateSystemPerformanceData()
        {
            // get latest control definition
            var controlDefinition = this.agentControlDefinitionProvider.GetControlDefinition();

            if (controlDefinition == null || controlDefinition.SystemPerformanceCheck == null)
            {
                return;
            }

            var systemPerformanceCheckSettings = controlDefinition.SystemPerformanceCheck;

            // get the latest performance data
            this.systemPerformanceData = new SystemPerformanceData
            {
                ProcessorStatus = this.processorStatusProvider.GetProcessorStatus(),
                MemoryStatus    = this.systemMemoryStatusProvider.GetMemoryStatus(),
                StorageStatus   = this.systemStorageStatusProvider.GetStorageStatus()
            };

            // update the check interval
            if (systemPerformanceCheckSettings.CheckIntervalInSeconds > 0)
            {
                var timerStartTime = new TimeSpan(0, 0, systemPerformanceCheckSettings.CheckIntervalInSeconds);
                var timerInterval  = new TimeSpan(0, 0, 0, systemPerformanceCheckSettings.CheckIntervalInSeconds);
                this.timer.Change(timerStartTime, timerInterval);
            }
        }
Exemplo n.º 7
0
        public void Default_StorageStatus_IsNull()
        {
            // Arrange
            var performanceData = new SystemPerformanceData();

            // Assert
            Assert.IsNull(performanceData.StorageStatus);
        }
Exemplo n.º 8
0
        public void Default_ProcessorStatus_IsNull()
        {
            // Arrange
            var performanceData = new SystemPerformanceData();

            // Assert
            Assert.IsNull(performanceData.ProcessorStatus);
        }
Exemplo n.º 9
0
        public void Equals_TwoUninitializedObjects_ResultIsTrue()
        {
            // Arrange
            var object1 = new SystemPerformanceData();
            var object2 = new SystemPerformanceData();

            // Act
            bool result = object1.Equals(object2);

            // Assert
            Assert.IsTrue(result);
        }
Exemplo n.º 10
0
        public void GetHashCode_TwoIdenticalObjects_BothUninitialized_HashCodesAreEqual()
        {
            // Arrange
            var package1 = new SystemPerformanceData();
            var package2 = new SystemPerformanceData();

            // Act
            int hashCodeObject1 = package1.GetHashCode();
            int hashCodeObject2 = package2.GetHashCode();

            // Assert
            Assert.AreEqual(hashCodeObject1, hashCodeObject2);
        }
Exemplo n.º 11
0
        public void ToString_Contains_StorageStatus()
        {
            // Arrange
            var expectedString     = "Storage Status 1234";
            var storageInformation = new Mock <SystemStorageInformation>();

            storageInformation.Setup(s => s.ToString()).Returns(expectedString);

            var object1 = new SystemPerformanceData {
                StorageStatus = storageInformation.Object
            };

            // Act
            string result = object1.ToString();

            // Assert
            Assert.IsTrue(result.Contains(expectedString));
        }
Exemplo n.º 12
0
        public void ToString_Contains_ProcessorStatus()
        {
            // Arrange
            var expectedString = "ProzessorStatus 1234";
            var processorUtilizationInformation = new Mock <ProcessorUtilizationInformation>();

            processorUtilizationInformation.Setup(p => p.ToString()).Returns(expectedString);

            var object1 = new SystemPerformanceData {
                ProcessorStatus = processorUtilizationInformation.Object
            };

            // Act
            string result = object1.ToString();

            // Assert
            Assert.IsTrue(result.Contains(expectedString));
        }
Exemplo n.º 13
0
        public void Equals_SuppliedObjectIsOfOtherType_ResultIsFalse()
        {
            // Arrange
            var object1 = new SystemPerformanceData
            {
                MemoryStatus = new SystemMemoryInformation {
                    AvailableMemoryInGB = 3
                },
                ProcessorStatus = new ProcessorUtilizationInformation {
                    ProcessorUtilizationInPercent = 30d
                }
            };

            var object2 = new object();

            // Act
            bool result = object1.Equals(object2);

            // Assert
            Assert.IsFalse(result);
        }
Exemplo n.º 14
0
        public void GetHashCode_ForAllUniqueObject_AUniqueHashCodeIsReturned()
        {
            var hashCodes = new Dictionary <int, SystemPerformanceData>();

            for (var i = 0; i < 10000; i++)
            {
                // Act
                var object1 = new SystemPerformanceData
                {
                    MemoryStatus = new SystemMemoryInformation {
                        AvailableMemoryInGB = i
                    },
                    ProcessorStatus = new ProcessorUtilizationInformation {
                        ProcessorUtilizationInPercent = 30d
                    }
                };

                int generatedHashCode = object1.GetHashCode();

                // Assert
                Assert.IsFalse(hashCodes.ContainsKey(generatedHashCode));
                hashCodes.Add(generatedHashCode, object1);
            }
        }
        public void GetSystemStatusViewModel_StorageStatusIsNotNull_ResultContainsStorageStatusDataPoint()
        {
            // Arrage
            var deviceInfo1 = new SystemStorageDeviceInformation {
                DeviceName = "C:", FreeDiscSpaceInPercent = 20d
            };
            var deviceInfos   = new[] { deviceInfo1 };
            var storageStatus = new SystemStorageInformation {
                StorageDeviceInfos = deviceInfos
            };
            var systemPerformanceInformation = new SystemPerformanceData {
                StorageStatus = storageStatus
            };
            var systemInformation = new SystemInformation {
                SystemPerformance = systemPerformanceInformation
            };
            var storageStatusViewModel = new SystemStatusPointViewModel {
                Name = "Storage Status" + deviceInfo1.DeviceName, Value = deviceInfo1.FreeDiscSpaceInPercent
            };

            var processorStatusOrchestrator = new Mock <IProcessorStatusOrchestrator>();
            var memoryStatusOrchestrator    = new Mock <IMemoryStatusOrchestrator>();
            var storageStatusOrchestrator   = new Mock <IStorageStatusOrchestrator>();

            storageStatusOrchestrator.Setup(s => s.GetStorageUtilizationInPercent(It.IsAny <SystemStorageInformation>())).Returns(
                new[] { storageStatusViewModel });

            var systemStatusOrchestrator = new SystemStatusOrchestrator(
                processorStatusOrchestrator.Object, memoryStatusOrchestrator.Object, storageStatusOrchestrator.Object);

            // Act
            var result = systemStatusOrchestrator.GetSystemStatusViewModel(systemInformation);

            // Assert
            Assert.AreEqual(storageStatusViewModel.Value, result.DataPoints.First(d => d.Name.Equals(storageStatusViewModel.Name)).Value);
        }