Exemplo n.º 1
0
        /// <summary>
        ///     Get the model collection :
        ///     SubModel are transformed as Module
        ///     InlineModel are transformed as Group
        /// </summary>
        /// <param name="parentModel"></param>
        /// <returns></returns>
        //TODO change name SubModel into Module - InlineModel into Group
        public virtual ModelCollection GetModelCollection(Model parentModel)
        {
            var models = new ModelCollection();

            foreach (var subModel in SubModels)
            {
                var modelCollection = subModel.GetModelCollection(null);
                Variables.AddRange(modelCollection.GetVariables());
                Groups.AddRange(modelCollection.GetGroups());
                // Add module
                Module.CreateInstance(this, subModel.Name);
                models.AddRange(modelCollection);
            }

            foreach (var subModel in InlineModels)
            {
                var modelCollection = subModel.GetModelCollection(this);
                var variables       = modelCollection.GetVariables();
                Variables.AddRange(variables);
                // Add group for each inline model
                // InlineModel.Name are the same as their parentModel, therefore we use the className
                var group = new Group(subModel.GetType().Name, Name, variables.Names);
                Groups.Add(group);
            }

            models[0] = this;
            return(models);
        }
        public void ShouldSyncItsContainerWithModelParents()
        {
            var model_a = new Model ("a");
            var model_b = new Model ("b");
            var model_container = new Model("container");
            var models = new ModelCollection(model_container);
            models.AddRange(new [] {model_a, model_b});

            Assert.That(models.Container, Is.EqualTo(model_container));
            Assert.That(models.All(m => m.Parent == model_container));

            models.Clear();

            Assert.That(model_a.Parent, Is.Null);
            Assert.That(model_b.Parent, Is.Null);

            models.Add(model_a);

            Assert.That(model_a.Parent, Is.EqualTo(model_container));

            models.Insert(0, model_b);

            Assert.That(model_b.Parent, Is.EqualTo(model_container));

            models.Remove(model_a);

            Assert.That(model_a.Parent, Is.Null);
        }