Esempio n. 1
0
        public void GivenNotEqualData_WhenComparingPerformance_ThenPerformanceShouldBeBetterThanLinq()
        {
            // Given
            var       random    = new Random(42);
            const int arraySize = 1000000;
            var       array1    = new byte[arraySize];
            var       array2    = new byte[arraySize];

            random.NextBytes(array1);
            random.NextBytes(array2);

            // Precondition
            CollectionAssert.AreNotEqual(array1, array2);

            // When
            var  stopwatch = new Stopwatch();
            long timeToBeat = 0, actualTime = 0;

            for (var i = 0; i < 10000; i++)
            {
                stopwatch.Start();
                Assert.IsFalse(SlowBaselineLinqEquality(array1, array2));
                stopwatch.Stop();
                timeToBeat += stopwatch.ElapsedTicks;

                stopwatch.Reset();
                stopwatch.Start();
                Assert.IsFalse(FingerprintHelper.AreEqual(array1, array2));
                stopwatch.Stop();
                actualTime += stopwatch.ElapsedTicks;
            }

            // Then
            Assert.Less(actualTime, timeToBeat, $"actualTime '{actualTime}' is not less than timeToBeat '{timeToBeat}'");
        }
Esempio n. 2
0
        private void btnComputer_Click(object sender, EventArgs e)
        {
            string computerName = HardwareInfoHelper.GetComputerName();
            string userName     = HardwareInfoHelper.GetUserName();
            string systemType   = HardwareInfoHelper.GetSystemType();
            string cpuid        = HardwareInfoHelper.GetCPUId();
            string cpuName      = HardwareInfoHelper.GetCPUName();
            int    cpuUsage     = HardwareInfoHelper.GetCpuUsage();
            string diskId       = HardwareInfoHelper.GetDiskID();
            string ip           = HardwareInfoHelper.GetIPAddress();
            string macAddress   = HardwareInfoHelper.GetMacAddress();
            string memery       = HardwareInfoHelper.GetTotalPhysicalMemory();

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("ComputerName:\t {0} \r\n", computerName);
            sb.AppendFormat("UserName:\t {0} \r\n", userName);
            sb.AppendFormat("SystemType:\t {0} \r\n", systemType);
            sb.AppendFormat("CPU ID:\t {0} \r\n", cpuid);
            sb.AppendFormat("CPU Name:\t {0} \r\n", cpuName);
            sb.AppendFormat("CPU Usage:\t {0} \r\n", cpuUsage);
            sb.AppendFormat("Disk Id:\t {0} \r\n", diskId);
            sb.AppendFormat("IP:\t {0} \r\n", ip);
            sb.AppendFormat("MacAddress:\t {0} \r\n", macAddress);
            sb.AppendFormat("TotalPhysicalMemory:\t {0} \r\n", memery);
            MessageDxUtil.ShowTips(sb.ToString());

            string identity = FingerprintHelper.Value();

            MessageDxUtil.ShowTips(identity);
        }
Esempio n. 3
0
        public void Get_EntityIsNull_ThrowArgumentNullException()
        {
            // Call
            TestDelegate call = () => FingerprintHelper.Get(null);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(call).ParamName;

            Assert.AreEqual("entity", paramName);
        }
Esempio n. 4
0
        public void GivenProjectEntity_WhenGeneratingFingerprintMultipleTime_ThenHashRemainsEqual()
        {
            // Given
            RiskeerProject project = RiskeerProjectTestHelper.GetFullTestProject();
            ProjectEntity  entity  = project.Create(new PersistenceRegistry());

            // When
            byte[] hash1 = FingerprintHelper.Get(entity);
            byte[] hash2 = FingerprintHelper.Get(entity);

            // Then
            Assert.IsNotNull(hash1);
            CollectionAssert.IsNotEmpty(hash1);
            CollectionAssert.AreEqual(hash1, hash2);
        }
Esempio n. 5
0
        public void GivenProjectEntity_WhenComparingFingerprintsBeforeAndAfterChange_ThenHashDifferent()
        {
            // Given
            RiskeerProject project = RiskeerProjectTestHelper.GetFullTestProject();
            ProjectEntity  entity  = project.Create(new PersistenceRegistry());

            // When
            byte[] hash1 = FingerprintHelper.Get(entity);
            entity.AssessmentSectionEntities.First().Name = "Something completely different";
            byte[] hash2 = FingerprintHelper.Get(entity);

            // Then
            Assert.IsNotNull(hash1);
            CollectionAssert.IsNotEmpty(hash1);
            CollectionAssert.AreNotEqual(hash1, hash2);
        }
Esempio n. 6
0
        public void GivenProjectEntity_WhenGeneratingFingerprintEqualData_ThenHashRemainsEqual()
        {
            // Setup
            RiskeerProject project1 = RiskeerProjectTestHelper.GetFullTestProject();
            RiskeerProject project2 = RiskeerProjectTestHelper.GetFullTestProject();
            ProjectEntity  entity1  = project1.Create(new PersistenceRegistry());
            ProjectEntity  entity2  = project2.Create(new PersistenceRegistry());

            // Call
            byte[] hash1 = FingerprintHelper.Get(entity1);
            byte[] hash2 = FingerprintHelper.Get(entity2);

            // Assert
            Assert.IsNotNull(hash1);
            CollectionAssert.IsNotEmpty(hash1);
            CollectionAssert.AreEqual(hash1, hash2);
        }
Esempio n. 7
0
        public void AreEqual_ArraysAreEqual_ReturnTrue()
        {
            // Setup
            var       random    = new Random(42);
            const int arraySize = 10;
            var       array1    = new byte[arraySize];

            random.NextBytes(array1);

            // Precondition
            CollectionAssert.AreEqual(array1, array1);

            // Call
            bool areCollectionEqual = FingerprintHelper.AreEqual(array1, array1);

            // Assert
            Assert.IsTrue(areCollectionEqual);
        }