public void Is_Random_Order()
        {
            IEnumerable <TestEntity> entities = new TestEntity[]
            {
                new TestEntity(23.3245F),
                new TestEntity(56.12345F),
                new TestEntity(77.89F),
                new TestEntity(0),
                new TestEntity(0.4563467F),
                new TestEntity(456.23234F),
                new TestEntity(4.124F),
                new TestEntity(0.00045634F),
                new TestEntity(777.777F),
                new TestEntity(-235.235325326464F),
            };
            var oldEntities = entities.Select(e => new TestEntity(e.SomeField)).ToArray();

            var shuffleFieldValuesHelper = new ShuffleFieldValuesHelper <TestEntity>();

            foreach (var entity in entities)
            {
                shuffleFieldValuesHelper.AddEntity(entity);
                shuffleFieldValuesHelper.AddValue("SomeField", entity.SomeField);
            }
            shuffleFieldValuesHelper.Process();

            Assert.Equal(oldEntities, entities, new TestEntityComparer());
        }
Beispiel #2
0
        protected override IEnumerable <Opportunity> ChangeByRules(IEnumerable <Opportunity> opportunities)
        {
            var randomHelper       = new RandomHelper();
            var shuffleFieldValues = new ShuffleFieldValuesHelper <Opportunity>();

            foreach (var opportunity in opportunities)
            {
                // А. Если значение поля «Ручной ввод скидки»(mcdsoft_discount) = «Да» [1], то
                // заполнить поля «Основная скидка СМ»(cmdsoft_standartdiscount), «% Основная скидка Чиллера»(mcdsoft_standartdiscount_chiller %),
                // «Гарантия, %»(cmdsoft_warranty) = Random(Тип - число в плавающей точкой, точность - 2, 0 - 100, 00)
                if (opportunity.mcdsoft_discount != null && (bool)opportunity.mcdsoft_discount)
                {
                    opportunity.cmdsoft_standartdiscount         = randomHelper.GetDecimal(0, 100);
                    opportunity.mcdsoft_standartdiscount_chiller = randomHelper.GetDecimal(0, 100);
                    opportunity.cmdsoft_warranty = randomHelper.GetDecimal(0, 100);
                }

                // B. В тех проектах, где значение поля «Результат»(cmdsoft_result) = «Проигран» [289 540 002],
                // копировать в отдельную таблицу значения полей «Причина проигрыша» (mcdsoft_reason_for_the_loss),
                // потом из этой таблицы случайным образом вставить(переписать) значения в другой проект(то есть перетасовать в проигранных проектах «Причины проигрыша»)
                if (opportunity.cmdsoft_Result != null && opportunity.cmdsoft_Result.Value == 289540002)
                {
                    shuffleFieldValues.AddEntity(opportunity);
                    shuffleFieldValues.AddValue("mcdsoft_reason_for_the_loss", opportunity.mcdsoft_reason_for_the_loss);
                }
            }

            // B. Дополнение (см. выше)
            shuffleFieldValues.Process();

            return(opportunities);
        }
        protected override IEnumerable <Contact> ChangeByRules(IEnumerable <Contact> contacts)
        {
            var random             = new Random();
            var shuffleFieldValues = new ShuffleFieldValuesHelper <Contact>();

            foreach (var contact in contacts)
            {
                shuffleFieldValues.AddEntity(contact);
                shuffleFieldValues.AddValue("firstname", contact.FirstName);
                shuffleFieldValues.AddValue("lastname", contact.LastName);
                shuffleFieldValues.AddValue("middlename", contact.MiddleName);
                contact.mcdsoft_contactnumber = random.Next(10000, 99999).ToString();
            }

            shuffleFieldValues.Process();

            return(contacts);
        }