Exemple #1
0
        public void Test_CreateProxy()
        {
            var raw   = new ConcreteEntity();
            var proxy = EntityProxyFactory.CreateProxy(raw);

            // the proxy and raw instance are not the same
            Assert.IsFalse(ReferenceEquals(raw, proxy));
        }
Exemple #2
0
        public void Test_GetClass_returns_type_of_raw_instance()
        {
            var raw   = new ConcreteEntity();
            var proxy = EntityProxyFactory.CreateProxy(raw);

            // the type of the proxy is not the type of the raw instance
            Assert.AreNotEqual(typeof(ConcreteEntity), proxy.GetType());

            // the GetClass method returns the type of the raw instance
            Assert.AreEqual(typeof(ConcreteEntity), proxy.GetClass());
        }
Exemple #3
0
        public void Test_GetHashCode_identical_between_proxy_and_raw_instances()
        {
            var raw   = new ConcreteEntity();
            var proxy = EntityProxyFactory.CreateProxy(raw);

            // the proxy and raw instance are not the same
            Assert.IsFalse(ReferenceEquals(raw, proxy));

            var x = raw.GetHashCode();
            var y = proxy.GetHashCode();

            // hash codes are same
            Assert.AreEqual(x, y);
        }
Exemple #4
0
        public void Test_Equals_correctly_compares_proxy_and_raw_instances()
        {
            var raw   = new ConcreteEntity();
            var proxy = EntityProxyFactory.CreateProxy(raw);

            // the proxy and raw instance are not the same
            Assert.IsFalse(ReferenceEquals(raw, proxy));

            // check every possible permutation
            Assert.IsTrue(raw.Equals(raw));
            Assert.IsTrue(proxy.Equals(proxy));
            Assert.IsTrue(raw.Equals(proxy));
            Assert.IsTrue(proxy.Equals(raw));
        }
Exemple #5
0
        public void Test_AreEqual_compare_entity_and_proxy()
        {
            var e1 = new ConcreteEntity();
            var e2 = EntityProxyFactory.CreateProxy(e1);

            // all permutations should be equal
            Assert.IsTrue(EqualityUtils <ConcreteEntity> .AreEqual(e1, e1));
            Assert.IsTrue(EqualityUtils <ConcreteEntity> .AreEqual(e2, e2));
            Assert.IsTrue(EqualityUtils <ConcreteEntity> .AreEqual(e1, e2));
            Assert.IsTrue(EqualityUtils <ConcreteEntity> .AreEqual(e2, e1));

            // also works using Entity as generic arg
            Assert.IsTrue(EqualityUtils <Entity> .AreEqual(e1, e1));
            Assert.IsTrue(EqualityUtils <Entity> .AreEqual(e2, e2));
            Assert.IsTrue(EqualityUtils <Entity> .AreEqual(e1, e2));
            Assert.IsTrue(EqualityUtils <Entity> .AreEqual(e2, e1));
        }
Exemple #6
0
        public void Test_AreEqual_does_not_initialize_EnumValue_proxy_if_not_needed()
        {
            var raw = new ConcreteEnumValue("1");

            EntityProxyFactory.EntityProxyInterceptor interceptor;
            var proxy = EntityProxyFactory.CreateProxy(raw, out interceptor);

            // check equality between proxies
            Assert.IsTrue(EqualityUtils <ConcreteEnumValue> .AreEqual(proxy, proxy));
            Assert.IsTrue(EqualityUtils <EnumValue> .AreEqual(proxy, proxy));

            // ensure interceptor did not intercept anything (ie initialize proxy)
            Assert.IsFalse(interceptor.Intercepted);

            // check equality between proxy and raw
            Assert.IsTrue(EqualityUtils <ConcreteEnumValue> .AreEqual(raw, proxy));

            // in this case, interceptor is invoked
            Assert.IsTrue(interceptor.Intercepted);
        }