public void TypeConstructorTest()
        {
            var ctor1 = new TypeConstructor <Customer, int, string>(ProxyTypeBuilder.BuildDomainEntityProxy <Customer>(), (Customer x) => x.OnLoaded());

            var id   = 1;
            var name = "someone";

            var c1 = ctor1.Construct(new object[] { id, name });

            Assert.IsTrue(c1.Id == id && c1.Name == name && c1.GetEntityState() == EntityState.Existing);

            c1 = ctor1.Construct(("id", id), ("name", name));
            Assert.IsTrue(c1.Id == id && c1.Name == name && c1.GetEntityState() == EntityState.Existing);

            c1 = ctor1.Construct(1, name);
            Assert.IsTrue(c1.Id == id && c1.Name == name && c1.GetEntityState() == EntityState.Existing);

            c1 = ctor1.ConstructWithDefaults(("id", id));
            Assert.IsTrue(c1.Id == id && c1.Name == null && c1.GetEntityState() == EntityState.Existing);

            Assert.Throws <InvalidOperationException>(() => c1 = ctor1.Construct(("id", id)));
        }
示例#2
0
        public void TypeConstructorTest()
        {
            var id   = 1;
            var name = "someone";
            var code = "somecode";

            var ctor1 = new TypeConstructor <Customer, int, string>(typeof(Customer1), initializer: x => x.Code = code);


            var c1 = ctor1.Construct(new object[] { id, name });

            Assert.IsTrue(c1.Id == id && c1.Name == name && c1.Code == code);

            c1 = ctor1.Construct(("id", id), ("name", name));
            Assert.IsTrue(c1.Id == id && c1.Name == name && c1.Code == code);

            c1 = ctor1.Construct(1, name);
            Assert.IsTrue(c1.Id == id && c1.Name == name && c1.Code == code);

            c1 = ctor1.ConstructWithDefaults(("id", id));
            Assert.IsTrue(c1.Id == id && c1.Name == null && c1.Code == code);

            Assert.Throws <InvalidOperationException>(() => c1 = ctor1.Construct(("id", id)));
        }