/*----------------------------------------------------------------------------------------------------
        * Create and return List of <TModel>. Properties of <TModel> will be equal to the following values:
        *
        *       - <DataTime> type : All properties will be generate in <dataGenerator.GenerateRandomDate>
        *                           method.
        *
        *       - <String> type :   Properties with "Login" name will be generate in
        *                           <dataGenerator.GenerateRandomLogin()> method.
        *
        *                           Properties with "Password" name will be generate in
        *                           <dataGenerator.GenerateRandomPassword()> method.
        *
        *                           All other properties will be generate in
        *                           <dataGenerator.GenerateRandomDescription()> method.
        *  ----------------------------------------------------------------------------------------------------*/
        /// <summary>
        /// Return List of TModel with properties generated by IDataGenerator.
        /// </summary>
        /// <param name="modelsCount">Required TModel count in list.</param>
        /// <returns>Generated TModels collection.</returns>
        public List <TModel> GetData(int modelsCount = 10000)
        {
            List <TModel> dataList = new List <TModel>();

            dataList.Capacity = modelsCount;
            var genericType = GetType().GetGenericArguments();

            for (int i = 0; i < modelsCount; i++)
            {
                dynamic model = Activator.CreateInstance(genericType[0]);
                foreach (var prop in (model as TModel).GetType().GetProperties())
                {
                    PropertyInfo pInfo = prop as PropertyInfo;
                    if (pInfo != null)
                    {
                        if (pInfo.PropertyType == typeof(string))
                        {
                            // Without encryption
                            if (cryptographer == null)
                            {
                                switch (pInfo.Name)
                                {
                                case "Login":
                                {
                                    prop.SetValue(model, dataGenerator.GenerateRandomLogin());
                                    break;
                                }

                                case "Password":
                                {
                                    prop.SetValue(model, dataGenerator.GenerateRandomPassword());
                                    break;
                                }

                                case "Date":
                                {
                                    prop.SetValue(model, dataGenerator.GenerateRandomDate());
                                    break;
                                }

                                default:
                                {
                                    prop.SetValue(model, dataGenerator.GenerateRandomDescription());
                                    break;
                                }
                                }
                            }
                            // With encryption
                            else
                            {
                                switch (pInfo.Name)
                                {
                                case "Login":
                                {
                                    prop.SetValue(model, cryptographer.Encypt(dataGenerator.GenerateRandomLogin()));
                                    break;
                                }

                                case "Password":
                                {
                                    prop.SetValue(model, cryptographer.Encypt(dataGenerator.GenerateRandomPassword()));
                                    break;
                                }

                                case "Date":
                                {
                                    prop.SetValue(model, cryptographer.Encypt(dataGenerator.GenerateRandomDate()));
                                    break;
                                }

                                default:
                                {
                                    prop.SetValue(model, cryptographer.Encypt(dataGenerator.GenerateRandomDescription()));
                                    break;
                                }
                                }
                            }
                        }
                    }
                }
                dataList.Add(model);
            }
            return(dataList);
        }
Ejemplo n.º 2
0
        public void GenerateRandomDescription_LenghtGreaterThanZero()
        {
            string result = dataGenerator.GenerateRandomDescription();

            Assert.That(result.Length, Is.GreaterThan(0));
        }