コード例 #1
0
        public void CheckUniqueColumnPropInParallel()
        {
            //Arrange
            ConcurrentBag <int> ids           = new ConcurrentBag <int>();
            List <int>          objectNumbers = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8
            };

            Parallel.ForEach(objectNumbers, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 4
            },
                             number =>
            {
                MergeableTestRow row = new MergeableTestRow()
                {
                    ColKey1   = number,
                    ColKey2   = "",
                    ColValue1 = "X",
                    ColValue2 = 3.0
                };
                //Act
                ids.Add(int.Parse(row.Id));
            });

            //Assert
            Assert.All(ids, id => Assert.True(id >= 1 && id <= 8));
        }
コード例 #2
0
        public void CheckIfObjectsAreEqual()
        {
            //Arrange
            MergeableTestRow row = new MergeableTestRow()
            {
                ColKey1   = 1,
                ColKey2   = "A",
                ColValue1 = "X",
                ColValue2 = 3.0
            };

            MergeableTestRow other = new MergeableTestRow()
            {
                ColKey1   = 2,
                ColKey2   = "B",
                ColValue1 = "X",
                ColValue2 = 3.0
            };

            //Act
            bool isEqual = row.Equals(other);

            //Assert
            Assert.True(isEqual);
        }
コード例 #3
0
        public void CompareWithHiddenReflection(int objectsToCreate, double deviation)
        {
            //Arrange

            //Act
            var timeWithReflection = BigDataHelper.LogExecutionTime("Creation with Reflection",
                                                                    () =>
            {
                for (int i = 0; i < objectsToCreate; i++)
                {
                    MergeableTestRow row = new MergeableTestRow()
                    {
                        ColKey1   = i,
                        ColKey2   = "Test",
                        ColValue1 = "X1" + i,
                        ColValue2 = "T1" + i
                    };
                    string id    = row.UniqueId;
                    bool isequal = row.Equals(row);
                    LogTask.Trace("Id:" + id + " Equals:" + isequal.ToString());
                }
                ;
            });

            output.WriteLine("Elapsed " + timeWithReflection.TotalSeconds + " seconds for creation with reflection.");

            var timeWithoutReflection = BigDataHelper.LogExecutionTime("Creation without Reflection",
                                                                       () =>
            {
                for (int i = 0; i < objectsToCreate; i++)
                {
                    MergeableTestHidingRefĺection row = new MergeableTestHidingRefĺection()
                    {
                        ColKey1   = i,
                        ColKey2   = "Test",
                        ColValue1 = "X2" + i,
                        ColValue2 = "T2" + i
                    };
                    string id    = row.UniqueId;
                    bool isequal = row.Equals(row);
                    LogTask.Trace("Id:" + id + " Equals:" + isequal.ToString());
                }
            });

            output.WriteLine("Elapsed " + timeWithoutReflection.TotalSeconds + " seconds for creation without reflection.");

            //Assert
            Assert.True(timeWithoutReflection < timeWithReflection);
            Assert.True(timeWithoutReflection.TotalMilliseconds * (deviation + 1) > timeWithReflection.TotalMilliseconds);
        }
コード例 #4
0
        public void CheckUniqueColumnProp()
        {
            //Arrange
            MergeableTestRow row = new MergeableTestRow()
            {
                ColKey1   = 1,
                ColKey2   = "A",
                ColValue1 = "X",
                ColValue2 = 3.0
            };

            //Act
            string id = row.Id;

            //Assert
            Assert.True(id == "1A" || id == "A1");
        }