Exemple #1
0
        public void Issue1372DataItemSetIsConsistenBeforeAnyBubblingOccurs()
        {
            var dataItemSet = new DataItemSet(typeof(IRegularGridCoverage));

            var items    = dataItemSet.AsEventedList <IRegularGridCoverage>();
            var coverage = new RegularGridCoverage {
                Name = "oldCoverage"
            };

            items.Add(coverage);

            Assert.AreEqual(1, dataItemSet.DataItems.Count);
            var newCoverage = new RegularGridCoverage {
                Name = "newCoverage"
            };

            int callCount = 0;

            ((INotifyPropertyChanged)dataItemSet).PropertyChanged += delegate
            {
                callCount++;
                //synchronization problem
                Assert.AreEqual(newCoverage, items[0]);
            };

            dataItemSet.DataItems[0].Value = newCoverage;

            Assert.AreEqual(2, callCount, "Value and Name get changed once Value property is set");
        }
Exemple #2
0
        public void AddFloatAndDatetimeParameters()
        {
            DataItemSet data = CreateEmptyDataItemSet();

            // add new time stamp patameter
            const string timeParameterName  = "p1";
            DateTime     timeParameterValue = DateTime.Now;
            var          parameter          = new Parameter <DateTime> {
                Name = timeParameterName, Value = timeParameterValue
            };

            data.Add(parameter);

            // add new float patameter
            const string floatParameterName  = "p2";
            const float  floatParameterValue = 10.4f;
            var          parameter1          = new Parameter <float> {
                Name = floatParameterName, Value = floatParameterValue
            };

            data.Add(parameter1);

            // check results of the operations above.
            Assert.AreEqual(parameter.Value, timeParameterValue);
            Assert.AreEqual(parameter.Name, timeParameterName);

            Assert.AreEqual(parameter1.Value, floatParameterValue);
            Assert.AreEqual(parameter1.Name, floatParameterName);

            Assert.AreEqual(data.Count, 2);

            Assert.AreSame(data["p1"].Value, parameter, "Access parameter 'p1' by its name");
            Assert.AreSame(data["p2"].Value, parameter1, "Access parameter 'p2' by its name");
        }
Exemple #3
0
        private static DataItemSet CreateEmptyDataItemSet()
        {
            var data = new DataItemSet {
                Name = "Data", Description = "Common data of the test units"
            };

            return(data);
        }
Exemple #4
0
        public void Clone()
        {
            DataItemSet dis   = new DataItemSet("kaas", "tag", typeof(Url));
            DataItemSet clone = (DataItemSet)dis.DeepClone();

            //TODO: add more asserts.
            Assert.AreEqual(dis.Name, clone.Name);
            Assert.AreEqual(dis.Tag, clone.Tag);
        }
Exemple #5
0
        public void GetAllItemsRecursive()
        {
            var    dataItemSet = new DataItemSet();
            var    dataItem    = new DataItem();
            string value       = "value";

            dataItem.Value = value;
            dataItemSet.Add(dataItem);

            Assert.AreEqual(new object[] { value, dataItem, dataItemSet }, dataItemSet.GetAllItemsRecursive().ToArray());
        }
Exemple #6
0
        public void PropertyChanged()
        {
            var set       = new DataItemSet();
            int callCount = 0;

            ((INotifyPropertyChanged)(set)).PropertyChanged += (s, e) =>
            {
                callCount++;
            };

            set.Name = "kaas";
            Assert.AreEqual(1, callCount);
        }
Exemple #7
0
        public void AddingItemsToAdapterSetsIsRemoveableCorrectly()
        {
            var dataItemSet = new DataItemSet(typeof(Url)); // new DataItemSet(new List<Url>(), "My FBC list", DataItemRole.Input, false);

            dataItemSet.ReadOnly = true;

            //get an adapter for the set and add to
            var urlList = dataItemSet.AsEventedList <Url>();

            urlList.Add(new Url());

            Assert.IsFalse(dataItemSet.DataItems[0].IsRemoveable);
        }
Exemple #8
0
        public void ClonedDataItemsInSetShouldHaveClonedDataItemSetAsOwner()
        {
            DataItemSet dataItemSet = CreateEmptyDataItemSet();
            var         dataItem    = new DataItem();
            string      value       = "value";

            dataItem.Value = value;
            dataItemSet.DataItems.Add(dataItem);

            DataItemSet clonedSet = (DataItemSet)dataItemSet.DeepClone();

            Assert.AreEqual(clonedSet, clonedSet.DataItems[0].Owner);
        }
Exemple #9
0
        public void AddSetsOwnerAndRoleOfChildItem()
        {
            var dataItemSet = new DataItemSet(typeof(object))
            {
                Role = DataItemRole.Output
            };
            var objectList = dataItemSet.AsEventedList <object>();

            //action! add an object throught list adapter
            objectList.Add(new object());

            Assert.AreEqual(1, dataItemSet.DataItems.Count);
            Assert.AreEqual(DataItemRole.Output, dataItemSet.DataItems[0].Role);
            Assert.AreEqual(dataItemSet, dataItemSet.DataItems[0].Owner);
        }
Exemple #10
0
        public void UpdateOwner()
        {
            var       set  = new DataItemSet();
            IDataItem item = new DataItem();

            //adding dataitem should update owner
            set.Add(item);
            Assert.AreEqual(set, item.Owner);

            var o = new object();

            //replacing dataitem should update owner
            set.Replace(o, 0);
            Assert.AreEqual(set, set[0].Owner);
        }
Exemple #11
0
        private static Project Create17ItemsProjectTree()
        {
            //   RootFolder
            //      |-DataItem1
            //          |-DataItem1Value
            //      |-Folder 1
            //          |-DataItemSet1
            //              |-DataItem2
            //                  |-string
            //      |-Model
            //          |-DataItem3
            //          |-StartTime
            //              |-StartTimeValue
            //          |-StopTime
            //              |-StopTimeValue
            //          |-CurrentTime
            //              |-CurrentTimeValue
            //          |-TimeStep
            //              |-TimeStepValue

            Project p      = new Project();
            var     folder = new Folder("folder1");

            p.RootFolder.Items.Add(new DataItem {
                Value = "dataItem1Value"
            });
            var set       = new DataItemSet("dataItemSet1");
            var dataItem2 = new DataItem {
                Name = "DataItem2"
            };

            dataItem2.Value = "string";
            set.DataItems.Add(dataItem2);

            //TODO : replace simplermodel with a mock/stubbed object
            SimplerModel model = new SimplerModel();

            model.DataItems.Add(new DataItem()
            {
                Name = "DataItem3"
            });
            folder.Items.Add(set);

            p.RootFolder.Add(folder);
            p.RootFolder.Add(model);
            return(p);
        }
Exemple #12
0
        public void DataItemSetStaysSynchronizedWithEventedListAdapter()
        {
            //TODO: remove test. This functionality now lies within the adapter.
            //testing it here is redundant.
            //wrap the list of functions in a DataItemSet
            var dataItemSet = new DataItemSet(typeof(Url));
            var list        = dataItemSet.AsEventedList <Url>();

            list.Add(new Url());
            list.Add(new Url());
            list.Add(new Url());

            Assert.AreEqual(3, dataItemSet.DataItems.Count,
                            "Values added to list must create data items on-the-fly in data item set");

            list.Remove(list[1]);
            Assert.AreEqual(2, dataItemSet.DataItems.Count);
        }
Exemple #13
0
        public void AddSubDataItems()
        {
            DataItemSet data = CreateEmptyDataItemSet();

            // add child datasets
            var childData1 = new DataItemSet("data1");
            var childData2 = new DataItemSet("data2");

            data.Add(childData1);
            data.Add(childData2);

            // add data1/ child data items
            var parameter1 = new Parameter <float>("parameter1");

            childData1.Add(parameter1);

            // add data2/ child data items
            var startTime = new Parameter <DateTime>("start time");
            var duration  = new Parameter <TimeSpan>("duration");

            childData2.Add(startTime);
            childData2.Add(duration);

            // asserts
            Assert.AreEqual(data.Count, 2);
            Assert.AreSame(data["data1"], childData1);
            Assert.AreSame(data["data2"], childData2);

            var data1 = (DataItemSet)data["data1"];

            Assert.AreEqual(data1.Count, 1);
            Assert.AreSame(parameter1, data1["parameter1"].Value);

            var data2 = (DataItemSet)data["data2"];

            Assert.AreEqual(data2.Count, 2);
            Assert.AreSame(startTime, data2["start time"].Value);
            Assert.AreSame(duration, data2["duration"].Value);

            // TODO: make workaround for index[] operator
            // int indexOfData2 = 1;
            // int indexOfDuration = 1;
            // Assert.AreSame(data2["duration"], data[indexOfData2][indexOfDuration]);
        }
Exemple #14
0
        public void TestAddingAndRemovingValuesToDataItemSetUpdatesAdaptedList()
        {
            //TODO: remove this is adapter
            //Create a dataitemset and list.
            var dataItemSet = new DataItemSet(typeof(Url));
            var url         = new Url();
            var dataItem    = new DataItem(url);
            var list        = dataItemSet.AsEventedList <Url>();

            //action! add an item to the set
            dataItemSet.DataItems.Add(dataItem);

            //make sure the list got updated
            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(url, list[0]);

            dataItemSet.DataItems.RemoveAt(0);
            Assert.AreEqual(0, list.Count);
        }
Exemple #15
0
        public void AddingAnElementShouldCauseCollectionChangedWith()
        {
            //TODO: remove this is adapter logic
            var dataItemSet = new DataItemSet(typeof(Url));
            var list        = dataItemSet.AsEventedList <Url>();

            //check the collectionchanged
            int callCount = 0;

            ((INotifyCollectionChange)dataItemSet).CollectionChanged +=
                delegate {
                callCount++;
            };

            //Action! should cause one collectionchanged events. One for the list and one for the dataitemset
            list.Add(new Url());

            //assert
            Assert.AreEqual(1, callCount);
        }
Exemple #16
0
        public void CollectionChangedEventBubbling()
        {
            int count = 0;


            var dataItemSet = new DataItemSet(typeof(Url));

            ((INotifyCollectionChange)dataItemSet).CollectionChanged += delegate { count++; };
            var list = dataItemSet.AsEventedList <Url>();

            list.Add(new Url());
            list.Add(new Url());
            list.Add(new Url());
            Assert.AreEqual(3, dataItemSet.DataItems.Count);
            Assert.AreEqual(3, count);


            list.Remove(list[1]);
            Assert.AreEqual(2, dataItemSet.DataItems.Count);
            Assert.AreEqual(4, count);
        }
        public void TestSequenceLinkFirstSourceThenTargetUseDataSets()
        {
            string result = "";

            SimplerModel sourceModel = new SimplerModel { Name = "source" };
            sourceModel.Executing += (s, e) => result += ((SimplerModel)s).Name;

            SimplerModel targetModel = new SimplerModel { Name = "target" };
            targetModel.Executing += (s, e) => result += ((SimplerModel)s).Name;

            IDataItemSet sourceInputSet = new DataItemSet { Name = "input", Role = DataItemRole.Input };
            IDataItem sourceInput = new DataItem { Name = "SI", Value = new object(), Role = DataItemRole.Input };
            sourceInputSet.Add(sourceInput);

            IDataItemSet sourceOutputSet = new DataItemSet { Name = "output", Role = DataItemRole.Output };
            IDataItem sourceOutput = new DataItem { Name = "SO", Value = new object(), Role = DataItemRole.Output };
            sourceOutputSet.Add(sourceOutput);

            IDataItemSet targetInputSet = new DataItemSet { Name = "input", Role = DataItemRole.Input };
            IDataItem targetInput = new DataItem { Name = "TI", Value = new object(), Role = DataItemRole.Input };
            targetInputSet.Add(targetInput);

            IDataItemSet targetOutputSet = new DataItemSet { Name = "output", Role = DataItemRole.Output };
            IDataItem targetOutput = new DataItem { Name = "TO", Value = new object(), Role = DataItemRole.Output };
            targetOutputSet.Add(targetOutput);

            sourceModel.DataItems.Add(sourceInputSet);
            sourceModel.DataItems.Add(sourceOutputSet);
            targetModel.DataItems.Add(targetInputSet);
            targetModel.DataItems.Add(targetOutputSet);

            var compositeModel = new CompositeModel
            {
                Name = "composite model",
                Models = { sourceModel, targetModel }
            };

            targetInput.LinkTo(sourceOutput);

            compositeModel.Initialize();
            compositeModel.Execute();

            Assert.AreEqual("sourcetarget", result);
        }
Exemple #18
0
         private static Project Create17ItemsProjectTree()
         {
             //   RootFolder
             //      |-DataItem1
             //          |-DataItem1Value
             //      |-Folder 1
             //          |-DataItemSet1
             //              |-DataItem2
             //                  |-string
             //      |-Model
             //          |-DataItem3
             //          |-StartTime
             //              |-StartTimeValue
             //          |-StopTime
             //              |-StopTimeValue
             //          |-CurrentTime
             //              |-CurrentTimeValue
             //          |-TimeStep
             //              |-TimeStepValue

             Project p = new Project();
             var folder = new Folder("folder1");
             p.RootFolder.Items.Add(new DataItem { Value = "dataItem1Value" });
             var set = new DataItemSet("dataItemSet1");
             var dataItem2 = new DataItem { Name = "DataItem2" };
             dataItem2.Value = "string";
             set.Add(dataItem2);

             //TODO : replace simplermodel with a mock/stubbed object
             SimplerModel model = new SimplerModel();
             model.DataItems.Add(new DataItem() { Name = "DataItem3" });
             folder.Items.Add(set);

             p.RootFolder.Add(folder);
             p.RootFolder.Add(model);
             return p;
         }
        public void TestSequenceLinkFirstTargetThenSourceUseDataSets()
        {
            string result = "";

            SimplerModel sourceModel = new SimplerModel {
                Name = "source"
            };

            sourceModel.Executing += (s, e) => result += ((SimplerModel)s).Name;

            SimplerModel targetModel = new SimplerModel {
                Name = "target"
            };

            targetModel.Executing += (s, e) => result += ((SimplerModel)s).Name;

            IDataItemSet sourceInputSet = new DataItemSet {
                Name = "input", Tag = "intput", Role = DataItemRole.Input
            };
            IDataItem sourceInput = new DataItem {
                Name = "SI", Tag = "SI", Value = new object(), Role = DataItemRole.Input
            };

            sourceInputSet.DataItems.Add(sourceInput);

            IDataItemSet sourceOutputSet = new DataItemSet {
                Name = "output", Tag = "output", Role = DataItemRole.Output
            };
            IDataItem sourceOutput = new DataItem {
                Name = "SO", Tag = "SO", Value = new object(), Role = DataItemRole.Output
            };

            sourceOutputSet.DataItems.Add(sourceOutput);

            IDataItemSet targetInputSet = new DataItemSet {
                Name = "input", Tag = "intput", Role = DataItemRole.Input
            };
            IDataItem targetInput = new DataItem {
                Name = "TI", Value = new object(), Role = DataItemRole.Input
            };

            targetInputSet.DataItems.Add(targetInput);

            IDataItemSet targetOutputSet = new DataItemSet {
                Name = "output", Tag = "output", Role = DataItemRole.Output
            };
            IDataItem targetOutput = new DataItem {
                Name = "TO", Tag = "TO", Value = new object(), Role = DataItemRole.Output
            };

            targetOutputSet.DataItems.Add(targetOutput);

            sourceModel.DataItems.Add(sourceInputSet);
            sourceModel.DataItems.Add(sourceOutputSet);
            targetModel.DataItems.Add(targetInputSet);
            targetModel.DataItems.Add(targetOutputSet);

            var compositeModel = new CompositeModel
            {
                Name   = "composite model",
                Models = { sourceModel, targetModel }
            };

            sourceInput.LinkTo(targetOutput);


            compositeModel.Initialize();
            compositeModel.Execute();

            Assert.AreEqual("targetsource", result);
        }