Exemplo n.º 1
0
        public DomainEntityFactory(Action <T> initializer = null)
        {
            var concreteType = ProxyTypeBuilder.BuildDomainEntityProxy <T>();

            New      = new TypeConstructor <T, TArg1, TArg2>(concreteType, x => { initializer?.Invoke(x); x.OnCreated(); });
            Existing = new TypeConstructor <T, TArg1, TArg2>(concreteType, x => { initializer?.Invoke(x); x.OnLoaded(); });
        }
 public Type GetActualTypeToCreate(Type objectType)
 {
     //Assert type
     if (objectType.IsSubclassOf(typeof(DomainEntity)))
     {
         return(ProxyTypeBuilder.BuildDomainEntityProxy(objectType));
     }
     else if (objectType.IsSubclassOfGeneric(typeof(DomainValueObject <>)))
     {
         return(ProxyTypeBuilder.BuildSerializableProxy(objectType));
     }
     else
     {
         return(objectType);
     }
 }
Exemplo n.º 3
0
        public void ProxyTypeBuilderTest()
        {
            var customerProxy = ProxyTypeBuilder.BuildDomainEntityProxy <Customer>();
            var customer      = (Customer)customerProxy.GetConstructorsEx().First().InvokeWithDefaults();


            customer.ChangeTracker.BeginTracking();

            customer.MainAddress = new Address("", "", "", "", null, null);
            customer.Code        = 1;
            customer.Name        = "12";
            customer.Name        = "121";
            customer.Name        = "121";

            customer.Quantity = 1;


            //var c = ProxyTypeBuilder.CreateInstance<Customer>(() => new Customer(1, "123"));
            var c1 = ProxyTypeBuilder.CreateInstance(() => new Customer(1, customer.Name));
        }
Exemplo n.º 4
0
        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)));
        }