Exemplo n.º 1
0
        public void TestAddToSubsetSingle()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var base2    = factory.BaseClass();
            var base3    = factory.BaseClass();
            var base4    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var derived2 = factory.DerivedClass();
            var derived3 = factory.DerivedClass();
            var derived4 = factory.DerivedClass();
            var subs     = factory.UnionSingle();

            subs.Subset4 = base1;
            Assert.Equal(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            Assert.Equal(base1, subs.Subset4);
            Assert.Throws <ModelException>(() => subs.Subset1.Add(base2));
            Assert.Equal(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            Assert.Equal(base1, subs.Subset4);
            subs.Subset5 = derived1;
            Assert.Equal(derived1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(derived1, subs.Subset1);
            Assert.Equal(derived1, subs.Subset4);
            Assert.Equal(derived1, subs.Subset5);
            Assert.Throws <ModelException>(() => subs.Subset1.Add(base2));
            subs.Subset5 = derived1;
            Assert.Equal(derived1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(derived1, subs.Subset1);
            Assert.Equal(derived1, subs.Subset4);
            Assert.Equal(derived1, subs.Subset5);
        }
        public void TestList2SetBaseDerived()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var subs     = factory.SubsettingDerived2Base();

            subs.List2SetBase.Add(derived1);
            Assert.True(subs.List2SetDerived.Count == 0);
            Assert.Contains(derived1, subs.List2SetBase);
            var imodel    = model.ToImmutable();
            var ibase1    = base1.ToImmutable(imodel);
            var iderived1 = derived1.ToImmutable(imodel);
            var isubs     = subs.ToImmutable(imodel);

            Assert.True(isubs.List2SetDerived.Count == 0);
            Assert.Contains(iderived1, isubs.List2SetBase);
        }
        public void TestSingle2SingleBaseDerived()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var subs     = factory.SubsettingDerived2Base();

            subs.Single2SingleBase = derived1;
            Assert.Null(subs.Single2SingleDerived);
            Assert.Equal(derived1, subs.Single2SingleBase);
            var imodel    = model.ToImmutable();
            var ibase1    = base1.ToImmutable(imodel);
            var iderived1 = derived1.ToImmutable(imodel);
            var isubs     = subs.ToImmutable(imodel);

            Assert.Null(isubs.Single2SingleDerived);
            Assert.Equal(iderived1, isubs.Single2SingleBase);
        }
        public void TestSingle2List()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var subs     = factory.SubsettingDerived2Base();

            subs.Single2ListDerived.Add(derived1);
            Assert.Contains(derived1, subs.Single2ListDerived);
            Assert.Equal(derived1, subs.Single2ListBase);
            var imodel    = model.ToImmutable();
            var ibase1    = base1.ToImmutable(imodel);
            var iderived1 = derived1.ToImmutable(imodel);
            var isubs     = subs.ToImmutable(imodel);

            Assert.Contains(iderived1, isubs.Single2ListDerived);
            Assert.Equal(iderived1, isubs.Single2ListBase);
        }
        public void TestSingle2ListBaseDerived()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var subs     = factory.SubsettingBase2Derived();

            subs.Single2ListBase = derived1;
            Assert.True(subs.Single2ListDerived.Count == 0);
            Assert.Equal(derived1, subs.Single2ListBase);
            var imodel    = model.ToImmutable();
            var ibase1    = base1.ToImmutable(imodel);
            var iderived1 = derived1.ToImmutable(imodel);
            var isubs     = subs.ToImmutable(imodel);

            Assert.True(isubs.Single2ListDerived.Count == 0);
            Assert.Equal(iderived1, isubs.Single2ListBase);
        }
        public void TestSingle2SetResetBase()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var subs     = factory.SubsettingBase2Derived();

            subs.Single2SetDerived.Add(derived1);
            Assert.Contains(derived1, subs.Single2SetDerived);
            Assert.Equal(derived1, subs.Single2SetBase);
            subs.Single2SetBase = null;
            Assert.True(subs.Single2SetDerived.Count == 0);
            Assert.Null(subs.Single2SetBase);
            var imodel    = model.ToImmutable();
            var ibase1    = base1.ToImmutable(imodel);
            var iderived1 = derived1.ToImmutable(imodel);
            var isubs     = subs.ToImmutable(imodel);

            Assert.True(isubs.Single2SetDerived.Count == 0);
            Assert.Null(isubs.Single2SetBase);
        }
Exemplo n.º 7
0
        public void TestAddToSubset()
        {
            var model    = new MutableModel();
            var factory  = new PropertiesTestFactory(model);
            var base1    = factory.BaseClass();
            var base2    = factory.BaseClass();
            var base3    = factory.BaseClass();
            var base4    = factory.BaseClass();
            var derived1 = factory.DerivedClass();
            var derived2 = factory.DerivedClass();
            var derived3 = factory.DerivedClass();
            var derived4 = factory.DerivedClass();
            var subs     = factory.UnionSet();

            Assert.Throws <ModelException>(() => subs.Union1.Add(base1));
            subs.Subset1.Add(base1);
            Assert.Single(subs.Union1);
            Assert.Contains(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            subs.Subset1.Add(base1);
            Assert.Single(subs.Union1);
            Assert.Contains(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            subs.Subset2.Add(base1);
            Assert.Single(subs.Union1);
            Assert.Contains(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            Assert.Single(subs.Subset2);
            Assert.Contains(base1, subs.Subset2);
            subs.Subset3.Add(base1);
            Assert.Single(subs.Union1);
            Assert.Contains(base1, subs.Union1);
            Assert.Single(subs.Subset1);
            Assert.Contains(base1, subs.Subset1);
            Assert.Single(subs.Subset2);
            Assert.Contains(base1, subs.Subset2);
            Assert.Single(subs.Subset3);
            Assert.Contains(base1, subs.Subset3);
            subs.Subset3.Add(base2);
            Assert.True(subs.Union1.Count == 2);
            Assert.Contains(base1, subs.Union1);
            Assert.Contains(base2, subs.Union1);
            Assert.True(subs.Subset1.Count == 2);
            Assert.Contains(base1, subs.Subset1);
            Assert.Contains(base2, subs.Subset1);
            Assert.Single(subs.Subset2);
            Assert.Contains(base1, subs.Subset2);
            Assert.True(subs.Subset3.Count == 2);
            Assert.Contains(base1, subs.Subset3);
            Assert.Contains(base2, subs.Subset3);
            subs.Subset4.Add(derived1);
            Assert.True(subs.Union1.Count == 3);
            Assert.Contains(base1, subs.Union1);
            Assert.Contains(base2, subs.Union1);
            Assert.True(subs.Subset1.Count == 3);
            Assert.Contains(base1, subs.Subset1);
            Assert.Contains(base2, subs.Subset1);
            Assert.Contains(derived1, subs.Subset1);
            Assert.Single(subs.Subset2);
            Assert.Contains(base1, subs.Subset2);
            Assert.True(subs.Subset3.Count == 2);
            Assert.Contains(base1, subs.Subset3);
            Assert.Contains(base2, subs.Subset3);
            Assert.Single(subs.Subset4);
            Assert.Contains(derived1, subs.Subset4);
            Assert.Throws <ModelException>(() => subs.Union1.Add(base1));
        }