Ejemplo n.º 1
0
        public void Test(Type type, int repeatTimes, TimeSpan duration)
        {
            var builder = new DtoBuilder();
            var ins     = builder.Create(type);

            HeatUp(ins);

            var counters = new int[repeatTimes];

            for (var i = 0; i < repeatTimes; i++)
            {
                var counter   = 0;
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                while (stopWatch.Elapsed < duration)
                {
                    var memoryStream = WriteDto(ins);
                    Assert.True(memoryStream.Length > 0);
                    counter++;
                }

                stopWatch.Stop();
                counters[i] = counter;
            }

            var min     = counters.Min();
            var max     = counters.Max();
            var avg     = counters.Average();
            var diff    = (double)(max - min) / min * 100;
            var message = $"Test for {type} repeted {repeatTimes} times, each took {duration}. Min: {min} Max: {max} Diff: {diff} Avg: {avg}";

            _testOutput.WriteLine(message);
            Helper.SaveLog($"{nameof(WriteDtoToMemoryStream)}", message);
        }
Ejemplo n.º 2
0
        public void Create_ClassWithLists_InstanceFilled()
        {
            var builder = new DtoBuilder();
            var ins     = builder.Create <ClassWith256Lists <int> >();

            Assert.NotNull(ins);
            Assert.True(IsInstanceWithArrysValid <ClassWith256Lists <int>, int>(ins, IsIntValid));
        }
Ejemplo n.º 3
0
        public void Create_ClassWithStrings_InstanceFilled()
        {
            var builder = new DtoBuilder();
            var ins     = builder.Create <ClassWith256Strings>();

            Assert.NotNull(ins);
            Assert.True(IsInstanceValid <ClassWith256Strings, string>(ins, IsStringValid));
        }
Ejemplo n.º 4
0
        public void Create_ClassWithInts_InstanceFilled()
        {
            var builder = new DtoBuilder();
            var ins     = builder.Create <ClassWith256Ints>();

            Assert.NotNull(ins);
            Assert.True(IsInstanceValid <ClassWith256Ints, int>(ins, IsIntValid));
        }
Ejemplo n.º 5
0
        public void TestPerfomanceOnReadingToDto(int repeatTimes, TimeSpan duration)
        {
            var type          = typeof(ClassWith256Ints);
            var parameterName = nameof(ClassWith256Ints.Property256);

            var builder  = new DtoBuilder();
            var instance = builder.Create <ClassWith256Ints>();

            HeatUp(instance);

            var counters = new int[repeatTimes];

            for (var i = 0; i < repeatTimes; i++)
            {
                var counter   = 0;
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                while (stopWatch.Elapsed < duration)
                {
                    var value = instance.Property256;
                    Assert.True(value > -1);
                    counter++;
                }

                stopWatch.Stop();
                counters[i] = counter;
            }

            var min     = counters.Min();
            var max     = counters.Max();
            var avg     = counters.Average();
            var diff    = (double)(max - min) / min * 100;
            var message = $"Test for {type} parameter {parameterName} repeted {repeatTimes} times, each took {duration}. Min: {min} Max: {max} Diff: {diff} Avg: {avg}";

            _testOutput.WriteLine(message);
            Helper.SaveLog($"{nameof(DtoTests)}_{nameof(TestPerfomanceOnReadingToDto)}", message);
        }