Пример #1
0
        public void DynamicMapEqualsCallsItemEquals()
        {
            {
                MyFalseEquatableItem e = new MyFalseEquatableItem();

                DynamicMap <MyFalseEquatableItem> dm1 = new DynamicMap <MyFalseEquatableItem> {
                    { "eq", e }
                };
                DynamicMap <MyFalseEquatableItem> dm2 = new DynamicMap <MyFalseEquatableItem> {
                    { "eq", e }
                };
                Assert.False(dm1.Equals(dm2));
            }

            {
                DynamicMap <MyTrueEquatableItem> dm1 = new DynamicMap <MyTrueEquatableItem> {
                    { "eq", new MyTrueEquatableItem() }
                };
                DynamicMap <MyTrueEquatableItem> dm2 = new DynamicMap <MyTrueEquatableItem> {
                    { "eq", new MyTrueEquatableItem() }
                };
                Assert.True(dm1.Equals(dm2));
            }
        }
Пример #2
0
        public void DynamicMapEqualsWorks()
        {
            {
                DynamicMap <ConfigItem> dm1 = new DynamicMap <ConfigItem> {
                };
                DynamicMap <ConfigItem> dm2 = new DynamicMap <ConfigItem> {
                    { "number", (SingleValue <int>) 42 }
                };
                Assert.NotEqual(dm1, dm2);
                Assert.NotEqual(dm2, dm1);
                Assert.False(dm1.Equals(dm2));
                Assert.False(dm2.Equals(dm1));
            }

            {
                DynamicMap <ConfigItem> dm1 = new DynamicMap <ConfigItem> {
                    { "number", null }
                };
                DynamicMap <ConfigItem> dm2 = new DynamicMap <ConfigItem> {
                    { "number", (SingleValue <int>) 42 }
                };
                Assert.NotEqual(dm1, dm2);
                Assert.NotEqual(dm2, dm1);
                Assert.False(dm1.Equals(dm2));
                Assert.False(dm2.Equals(dm1));
            }

            {
                DynamicMap <ConfigItem> dm1 = new DynamicMap <ConfigItem> {
                    { "name", null }
                };
                DynamicMap <ConfigItem> dm2 = new DynamicMap <ConfigItem> {
                    { "name", null }
                };
                Assert.Equal(dm1, dm2);
                Assert.Equal(dm2, dm1);
                Assert.True(dm1.Equals(dm2));
                Assert.True(dm2.Equals(dm1));
            }

            {
                MyComposite sm = new MyComposite {
                    si = 42, ss1 = "foo", ss2 = null, nested = new MyComposite.MyNested {
                        x = 10, y = 20, s = "bar"
                    }, ci = null
                };
                DynamicMap <ConfigItem> dm1 = new DynamicMap <ConfigItem> {
                    { "name", (SingleItem <string>) "foo" }, { "number", (SingleValue <int>) 42 }, { "smap", sm }
                };
                DynamicMap <ConfigItem> dm2 = new DynamicMap <ConfigItem> {
                    { "number", (SingleValue <int>)   42 }, { "smap", sm }, { "name", (SingleItem <string>) "foo" }
                };
                Assert.Equal(dm1, dm2);
                Assert.True(dm1.Equals(dm2));
            }

            {
                DynamicMap <SingleItem <string> > dm1 = new DynamicMap <SingleItem <string> > {
                    { "name", "foo" }, { "number", "42" }
                };
                DynamicMap <SingleItem <string> > dm2 = new DynamicMap <SingleItem <string> > {
                    { "name", "bar" }, { "number", "42" }
                };
                Assert.NotEqual(dm1, dm2);
                Assert.False(dm1.Equals(dm2));
            }

            {
                DynamicMap <SingleItem <string> > dm1 = new DynamicMap <SingleItem <string> > {
                    { "name", "foo" }, { "number", "42" }
                };
                DynamicMap <SingleItem <string> > dm2 = new DynamicMap <SingleItem <string> > {
                    { "foo", null }, { "bar", null }
                };
                Assert.NotEqual(dm1, dm2);
                Assert.False(dm1.Equals(dm2));
            }

            {
                DynamicMap <ConfigItem> dm = new DynamicMap <ConfigItem> {
                    { "name", (SingleItem <string>) "foo" }, { "number", (SingleValue <int>) 42 }
                };
                Assert.False(dm.Equals(null));
                Assert.False(dm.Equals((DynamicMap <ConfigItem>)null));
                Assert.False(dm.Equals((DynamicMap <DynamicMap <ConfigItem> >)null));
                Assert.False(dm.Equals((ConfigItem)null));
            }
        }