Esempio n. 1
0
        public void GivenNullInvoke_MustThrowException()
        {
            var root  = ConfigHelper.CreateEmptyRoot();
            var proxy = ProxyUtil.CreateProx();

            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.EnsureCreateProx <object>(null, root, NullNameTransfer.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.EnsureCreateProx <object>(proxy, null, NullNameTransfer.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.EnsureCreateProx <object>(proxy, root, null));

            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.EnsureCreateProxWithAttribute <object>(proxy, null));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.EnsureCreateProxWithAttribute <object>(null, root));

            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy <object>(null));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy <object>(proxy, null));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy <object>(null, NullNameTransfer.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy <object>(proxy, NullNameTransfer.Instance, null));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy <object>(proxy, null, IdentityNamedCreator.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy <object>(null, NullNameTransfer.Instance, IdentityNamedCreator.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy <object>(proxy, NullNameTransfer.Instance, IdentityNamedCreator.Instance, null));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy <object>(proxy, NullNameTransfer.Instance, null, CompilePropertyVisitor.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy <object>(proxy, null, IdentityNamedCreator.Instance, CompilePropertyVisitor.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy(proxy, null, NullNameTransfer.Instance, IdentityNamedCreator.Instance, CompilePropertyVisitor.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy(proxy, null, NullNameTransfer.Instance, IdentityNamedCreator.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.EnsureCreateProx(proxy, null, root, NullNameTransfer.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy(proxy, null, NullNameTransfer.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy <object>(null, NullNameTransfer.Instance, IdentityNamedCreator.Instance, CompilePropertyVisitor.Instance));
            Assert.ThrowsException <ArgumentNullException>(() => ProxHelperExtensions.CreateComplexProxy(proxy, null));
        }
        public void CreateWithRedirectPath_MustProxThatPaths(Type type, string prefx)
        {
            var root  = ConfigHelper.CreateEmptyRoot();
            var prox  = ProxyUtil.CreateProx();
            var named = new Dictionary <PropertyIdentity, string>
            {
                [new PropertyIdentity(typeof(SomeBox), nameof(RedirectClass.Age))]   = "Age",
                [new PropertyIdentity(typeof(SomeBox), nameof(RedirectClass.Name))]  = prefx + "Name",
                [new PropertyIdentity(typeof(SomeBox), nameof(RedirectClass.Score))] = prefx + "Score",
            };
            var map     = new IdentityMapNameTransfer(named);
            var creator = new ProxyCreator(prox, type, map, IdentityNamedCreator.Instance, CompilePropertyVisitor.Instance);

            creator.Analysis();
            var x = (dynamic)creator.Build(root);

            x.Red.Age             = 123;
            x.Red.Name            = "456";
            x.Red.Score           = 789.123d;
            root["Age"]           = "123";
            root[prefx + "Name"]  = "456";
            root[prefx + "Score"] = "789.123";
            Assert.AreEqual("123", root["Age"]);
            Assert.AreEqual("456", root[prefx + "Name"]);
            Assert.AreEqual("789.123", root[prefx + "Score"]);
        }
        public void InitWithSimple_AutoAnalysisMustTrue()
        {
            var prox = ProxyUtil.CreateProx();
            var cp   = new ComplexProxyHelper(prox);

            Assert.IsTrue(cp.AutoAnalysis);
        }
Esempio n. 4
0
        public void CreateWhenNotBuild_MustReturnNull()
        {
            var prox = ProxyUtil.CreateProx();
            var root = ConfigHelper.CreateEmptyRoot();
            var val  = prox.CreateProxy(typeof(Setting1), root, NullNameTransfer.Instance);

            Assert.IsNull(val);
        }
Esempio n. 5
0
        public void EnsureCreateProx_MustCreated()
        {
            var root  = ConfigHelper.CreateEmptyRoot();
            var proxy = ProxyUtil.CreateProx();
            var val   = proxy.EnsureCreateProx <NullClass>(root, IdentityMapNameTransfer.FromTypeAttributes(typeof(NullClass)));

            Assert.IsTrue(proxy.ProxMap.ContainsKey(typeof(NullClass)));
            Assert.IsNotNull(val);
        }
Esempio n. 6
0
        public void ExistsEnsureCreateProx_WithIdentity_MustCreated()
        {
            var root  = ConfigHelper.CreateEmptyRoot();
            var proxy = ProxyUtil.CreateProx();

            proxy.BuildProx(typeof(NullClass));
            var val = proxy.EnsureCreateProxWithAttribute <NullClass>(root);

            Assert.IsNotNull(val);
        }
Esempio n. 7
0
        public void CreateProxType_MustOk()
        {
            var root     = ConfigHelper.CreateEmptyRoot();
            var proxType = ProxyUtil.CreateProx();
            var res      = proxType.BuildProx(typeof(Setting1));

            Assert.IsTrue(res);
            var newType = proxType.CreateProxy(typeof(Setting1), root, IdentityMapNameTransfer.FromTypeAttributes(typeof(Setting1)));

            Assert.IsNotNull(newType);
            Assert.IsInstanceOfType(newType, typeof(Setting1));
        }
Esempio n. 8
0
        public void BuildType_MustOk()
        {
            var proxType = ProxyUtil.CreateProx();
            var res      = proxType.BuildProx(typeof(Setting1));

            Assert.IsTrue(res);
            Assert.AreEqual(1, proxType.ProxMap.Count);
            Assert.AreEqual(typeof(Setting1), proxType.ProxMap.Keys.First());
            var newType = proxType.GetProxyType(typeof(Setting1));

            Assert.IsTrue(newType.BaseType == typeof(Setting1));
        }
Esempio n. 9
0
        public void BuildTwice_MustReturnFail()
        {
            var prox = ProxyUtil.CreateProx();

            _ = ConfigHelper.CreateEmptyRoot();
            Assert.IsNull(prox.GetProxyType(typeof(Setting1)));
            var val = prox.BuildProx(typeof(Setting1));

            Assert.IsTrue(val);
            Assert.IsNotNull(prox.GetProxyType(typeof(Setting1)));
            val = prox.BuildProx(typeof(Setting1));
            Assert.IsFalse(val);
        }
Esempio n. 10
0
        public void CreateComplaxClassProx_MustOk()
        {
            var root  = ConfigHelper.CreateEmptyRoot();
            var proxy = ProxyUtil.CreateProx();
            var val   = proxy.CreateComplexProxy <ComplexClass>();

            Assert.IsNotNull(val);
            Assert.AreEqual(proxy, val.ProxyHelper);
            var v = val.Build(root);

            Assert.IsNotNull(v);
            Assert.IsInstanceOfType(v, typeof(ComplexClass));
        }
Esempio n. 11
0
        public void GivenNullInit_MustThrowException()
        {
            var prox         = ProxyUtil.CreateProx();
            var type         = typeof(object);
            var nameTransfer = NullNameTransfer.Instance;
            var nameCreator  = IdentityNamedCreator.Instance;
            var propVisitor  = CompilePropertyVisitor.Instance;

            Assert.ThrowsException <ArgumentNullException>(() => new ProxyCreator(null, type, nameTransfer, nameCreator, propVisitor));
            Assert.ThrowsException <ArgumentNullException>(() => new ProxyCreator(prox, null, nameTransfer, nameCreator, propVisitor));
            Assert.ThrowsException <ArgumentNullException>(() => new ProxyCreator(prox, type, null, nameCreator, propVisitor));
            Assert.ThrowsException <ArgumentNullException>(() => new ProxyCreator(prox, type, nameTransfer, null, propVisitor));
            Assert.ThrowsException <ArgumentNullException>(() => new ProxyCreator(prox, type, nameTransfer, nameCreator, null));
        }
Esempio n. 12
0
        public void GivenArgsInit_PopertyValueMustEqualInput()
        {
            var prox         = ProxyUtil.CreateProx();
            var type         = typeof(object);
            var nameTransfer = NullNameTransfer.Instance;
            var nameCreator  = IdentityNamedCreator.Instance;
            var propVisitor  = CompilePropertyVisitor.Instance;
            var creator      = new ProxyCreator(prox, type, nameTransfer, nameCreator, propVisitor);

            Assert.AreEqual(prox, creator.ProxyHelper);
            Assert.AreEqual(type, creator.Type);
            Assert.AreEqual(nameTransfer, creator.NameTransfer);
            Assert.AreEqual(propVisitor, creator.PropertyVisitor);
            Assert.AreEqual(nameCreator, creator.NamedCreator);
            Assert.AreEqual(type, creator.Type);
            Assert.IsNotNull(creator.PropertyInfos);
            Assert.IsFalse(creator.HasConfigPath);
        }
        public void BuildComplexProxy()
        {
            var root = ConfigHelper.CreateEmptyRoot();
            var prox = ProxyUtil.CreateProx();
            var cp   = new ComplexProxyHelper(prox, true);

            Assert.IsTrue(cp.AutoAnalysis);
            Assert.AreEqual(prox, cp.ProxyHelper);
            var cr = cp.GetCreatorOrDefault <ComplexClass>();

            Assert.IsNull(cr);
            var c = cp.Build <ComplexClass>(root);

            Assert.IsNotNull(c);
            _ = cp.GetCreatorOrDefault <ComplexClass>();
            Assert.IsNotNull(c);
            Assert.IsTrue(cp.IsCreated <ComplexClass>());
        }