Exemplo n.º 1
0
        /// <summary>
        /// Generates data for members for which data generators are added.
        /// </summary>
        /// <returns>Key-value pairs where key is a member path and value is a member value.</returns>
        /// <remarks>If there is a loop in the data generators, it will randomly decide how deep to recurse.</remarks>
        public override IList <NamedValue> GenerateData()
        {
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            if (this.currentRecursionDepth > this.recursionLimit)
            {
                // TODO: should this be null instead?
                return(new List <NamedValue>());
            }

            if (this.currentRecursionDepth == 0)
            {
                this.recursionLimit = this.random.Next(MaxRecursionLimit);
            }

            try
            {
                this.currentRecursionDepth++;

                var result = new List <NamedValue>();
                foreach (string currentMemberPath in this.membersDataGenerators.Keys)
                {
                    IDataGenerator memberDataGenerator = this.GetMemberDataGenerator(currentMemberPath);
                    var            memberData          = memberDataGenerator.GenerateData();
                    result.AddMemberData(currentMemberPath, memberData);
                }

                return(result);
            }
            finally
            {
                this.currentRecursionDepth--;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates values for the properties with the specified paths.
        /// </summary>
        /// <param name="conceptualDataServices">Conceptual data services.</param>
        /// <param name="entitySetName">A name of the entity set for which data needs to be generated.</param>
        /// <param name="entityTypeFullName">An entity type full name.</param>
        /// <param name="propertyPaths">The property paths for which to generate values.</param>
        /// <param name="valuesToAvoid">The collection of named values where name is a property path and value is a property value which should be avoided when generating value for this property.</param>
        /// <returns>Generated properties' values.</returns>
        public static IEnumerable <NamedValue> GeneratePropertyValues(this IEntityModelConceptualDataServices conceptualDataServices, string entitySetName, string entityTypeFullName, IEnumerable <string> propertyPaths, IEnumerable <NamedValue> valuesToAvoid)
        {
            ExceptionUtilities.CheckArgumentNotNull(conceptualDataServices, "conceptualDataServices");
            ExceptionUtilities.CheckArgumentNotNull(propertyPaths, "propertyPaths");
            ExceptionUtilities.CheckArgumentNotNull(valuesToAvoid, "valuesToAvoid");

            var               memberDataGenerators = conceptualDataServices.GetStructuralGenerator(entityTypeFullName, entitySetName);
            const int         MaxAttempts          = 10;
            List <NamedValue> generatedValues      = new List <NamedValue>();

            foreach (string propertyPath in propertyPaths)
            {
                IDataGenerator propertyGenerator            = memberDataGenerators.GetMemberDataGenerator(propertyPath);
                var            valuesToAvoidForThisProperty = valuesToAvoid.Where(nv => nv.Name == propertyPath).Select(nv => nv.Value).ToList();

                int    attemptCount = 0;
                object value;
                do
                {
                    value = propertyGenerator.GenerateData();
                    attemptCount++;
                }while (valuesToAvoidForThisProperty.Contains(value, ValueComparer.Instance) && attemptCount < MaxAttempts);

                generatedValues.AddMemberData(propertyPath, value);
            }

            return(generatedValues);
        }
 public void GeneratesTheRightType(IDataGenerator dg)
 {
     dg.NullProbability=0;
     // generate row
     DataRow row = dg.Column.Table.NewRow();
     dg.GenerateData(row);
     Assert.IsFalse(row.HasErrors);
     // check that value has the right type
     ReflectionAssert.IsAssignableFrom(dg.GeneratedType,row[dg.Column].GetType());
 }
Exemplo n.º 4
0
 public void Initialize()
 {
     context            = new DataContext();
     customerRepository = new CustomerRepository(context);
     productRepository  = new ProductRepository(context);
     eventRepository    = new EventRepository(context);
     service            = new DataService(customerRepository, eventRepository, productRepository);
     generator          = new FixedExampleData();
     //generator = new RandomExampleData();
     generator.GenerateData(context);
 }
Exemplo n.º 5
0
        public void GeneratesTheRightType(IDataGenerator dg)
        {
            dg.NullProbability = 0;
            // generate row
            DataRow row = dg.Column.Table.NewRow();

            dg.GenerateData(row);
            Assert.IsFalse(row.HasErrors);
            // check that value has the right type
            ReflectionAssert.IsAssignableFrom(dg.GeneratedType, row[dg.Column].GetType());
        }
Exemplo n.º 6
0
 private void Initialize()
 {
     if (Accounts.Count(account => true) == 0)
     {
         DataContainer data = dataGenerator.GenerateData();
         Accounts.BulkWrite(data.Accounts.Select(CreateInsertModel));
         IncomingPayments.BulkWrite(data.IncomingPayments.Select(CreateInsertModel));
         OutgoingPayments.BulkWrite(data.OutgoingPayments.Select(CreateInsertModel));
         IncomingTaxes.BulkWrite(data.IncomingTaxes.Select(CreateInsertModel));
         OutgoingTaxes.BulkWrite(data.OutgoingTaxes.Select(CreateInsertModel));
     }
 }
Exemplo n.º 7
0
        public GraphForm(GraphWindow graphWindow, Form parent, IStaticsFactory factory, IDataGenerator data)
        {
            InitializeComponent();
            this.Closing += Form1_Closing;
            this.parent = parent;
            this.graphWindow = graphWindow;

            original = new DataContainer();
            original.Data = data.GenerateData();
            modified = original.Clone();
            mean = factory.GetMeanCalculator().CalculateMean(modified.Data);
            modified.Data = factory.GetDataTransformer().TransformData(modified.Data);
            
        }
Exemplo n.º 8
0
        public ActionResult GenerateData(IndexVM indexVM)
        {
            var listPOCO = sharePointService.GetListPOCO(indexVM.SelectedListVM.Title);

            indexVM.SyncModels(listPOCO);
            ModelState.Clear();
            TryValidateModel(indexVM);
            if (ModelState.IsValid)
            {
                var data = dataGenerator.GenerateData(listPOCO, indexVM.RecordsToGenerateCount);
                sharePointService.Save(data, listPOCO);
            }
            indexVM = GetDefaultIndexVM();
            indexVM = indexVMFactory.GetIndexVMWithSelectedList(indexVM, listPOCO);
            indexVM.ShowSuccessGeneration = ModelState.IsValid;
            indexVM.ShowFailedGeneration  = !ModelState.IsValid;
            return(View("Index", indexVM));
        }
Exemplo n.º 9
0
 private void GenerateNextData(int count = GenerateCount)
 {
     _iterator = _dataGenerator.GenerateData(count).GetEnumerator();
     _iterator.MoveNext();
 }
Exemplo n.º 10
0
 public LinearSearch(IDataGenerator dataGen) : base(dataGen)
 {
     NoOfEntries = dataGen.NoOfEntries;
     Data        = dataGen.GenerateData();
 }