Ejemplo n.º 1
0
        public void XpoInitializerUpdateSchema_ShouldPass()
        {
            XpoInitializer XpoInitializer = new XpoInitializer(this.GetConnectionString("UpdateSchema"), typeof(Customer), typeof(Invoice));

            XpoInitializer.InitSchema();
            DevExpress.Xpo.UnitOfWork UnitOfWork = XpoInitializer.CreateUnitOfWork();
            Customer Joche = new Customer(UnitOfWork);

            if (UnitOfWork.InTransaction)
            {
                UnitOfWork.CommitChanges();
            }
            Assert.IsNotNull(Joche);
        }
        public async Task CreateAndReadRecordTest()
        {
            XpoWebApiProvider.Register();

            client = new Client(new NewtonsoftSerializationAdapter(), createHttpClient: (name) => _testServerHttpClientFactory.CreateClient());



            CompressXmlObjectSerializationService simpleObjectSerializationHelper = new CompressXmlObjectSerializationService();
            Dictionary <string, string>           Headers = new Dictionary <string, string>();

            Headers.Add(XpoWebApiProvider.TokenPart, "");
            Headers.Add(XpoWebApiProvider.DataStoreIdPart, "001");
            ApiFunction restFunctionClient = new ApiFunction(client, Url, Headers);



            XpoWebApiProvider restClientNetProvider = new XpoWebApiProvider(restFunctionClient, new CompressXmlObjectSerializationService(), DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema);



            XpoInitializer xpoInitializer = new XpoInitializer(restClientNetProvider, typeof(Customer), typeof(Invoice));

            xpoInitializer.InitSchema();


            var      UoW      = xpoInitializer.CreateUnitOfWork();
            Customer customer = new Customer(UoW);

            customer.Name = "Jose Manuel Ojeda Melgar";
            if (UoW.InTransaction)
            {
                UoW.CommitChanges();
            }



            var            CustomerFromDataStore = UoW.FindObject <Customer>(new BinaryOperator(nameof(customer.Code), customer.Code));
            Response <int> count = await client.GetAsync <int>(new Uri(UrlGet + "/?DataStoreId=001", UriKind.Absolute));

            Assert.AreEqual(count.Body, 1);
            Assert.AreEqual(customer.Name, CustomerFromDataStore.Name);
        }
        public void CreateAndReadRecordTest()
        {
            XpoWebApiProvider.Register();

            client = new Client(new NewtonsoftSerializationAdapter(), createHttpClient: (name) => _testServerHttpClientFactory.CreateClient());



            CompressXmlObjectSerializationService simpleObjectSerializationHelper = new CompressXmlObjectSerializationService();
            Dictionary <string, string>           Headers = new Dictionary <string, string>();

            Headers.Add(XpoWebApiProvider.TokenPart, "");
            Headers.Add(XpoWebApiProvider.DataStoreIdPart, "001");
            ApiFunction restFunctionClient = new ApiFunction(client, Url, Headers);


            //var Cnx = XpoWebApiProvider.GetConnectionString("http://localhost", Controller, "", "001");
            XpoWebApiProvider restClientNetProvider = new XpoWebApiProvider(restFunctionClient, new CompressXmlObjectSerializationService(), DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema);



            XpoInitializer xpoInitializer = new XpoInitializer(restClientNetProvider, typeof(Customer), typeof(Invoice));

            xpoInitializer.InitSchema();


            var      UoW      = xpoInitializer.CreateUnitOfWork();
            Customer customer = new Customer(UoW);

            customer.Name = "Jose Manuel Ojeda Melgar";
            if (UoW.InTransaction)
            {
                UoW.CommitChanges();
            }



            var CustomerFromDataStore = UoW.FindObject <Customer>(new BinaryOperator(nameof(customer.Code), customer.Code));

            Assert.AreEqual(customer.Name, CustomerFromDataStore.Name);
        }
        public void CreateCollectionTest()
        {
            //HACK ToImplmement 001
            XpoWebApiProvider.Register();

            client = new Client(new NewtonsoftSerializationAdapter(), createHttpClient: (name) => _testServerHttpClientFactory.CreateClient());



            CompressXmlObjectSerializationService simpleObjectSerializationHelper = new CompressXmlObjectSerializationService();
            Dictionary <string, string>           Headers = new Dictionary <string, string>();

            Headers.Add(XpoWebApiProvider.TokenPart, "");
            Headers.Add(XpoWebApiProvider.DataStoreIdPart, "002");
            ApiFunction restFunctionClient = new ApiFunction(client, Url, Headers);

            XpoWebApiProvider restClientNetProvider = new XpoWebApiProvider(restFunctionClient, new CompressXmlObjectSerializationService(), DevExpress.Xpo.DB.AutoCreateOption.DatabaseAndSchema);

            XpoInitializer xpoInitializer = new XpoInitializer(restClientNetProvider, typeof(Customer), typeof(Invoice));

            xpoInitializer.InitSchema();


            var      UoW        = xpoInitializer.CreateUnitOfWork();
            Customer JoseManuel = new Customer(UoW);

            JoseManuel.Name = "Jose Manuel Ojeda Melgar";

            Customer OscarOjeda = new Customer(UoW);

            OscarOjeda.Name = "Oscar Ojeda Melgar";

            if (UoW.InTransaction)
            {
                UoW.CommitChanges();
            }

            var people = new XPCollection <Customer>(UoW).ToList();

            Assert.IsNotNull(people);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //Register XpoWebApiProvider
            XpoWebApiProvider.Register();

            //https://localhost:44359/api/XpoWebApi

            var XpoWebApiAspNetCore = XpoWebApiProvider.GetConnectionString("https://localhost:44389", "/XpoWebApi", string.Empty, "001");
            var XpoWebApiAspNet     = XpoWebApiProvider.GetConnectionString("https://localhost:44359", "/api/XpoWebApi", string.Empty, "001");


            XpoInitializer xpoInitializer = new XpoInitializer(XpoWebApiAspNet, typeof(Invoice), typeof(Customer));

            //XpoInitializer xpoInitializer = new XpoInitializer(XpoWebApiAspNetCore, typeof(Invoice), typeof(Customer));


            xpoInitializer.InitSchema();

            using (var UoW = xpoInitializer.CreateUnitOfWork())
            {
                var faker = new Bogus.Faker <Customer>().CustomInstantiator(c => new Customer(UoW))
                            .RuleFor(p => p.Code, f => f.Random.Guid())
                            .RuleFor(p => p.Name, f => f.Name.FullName())
                            .RuleFor(p => p.Active, p => p.Random.Bool());

                var Customers = faker.Generate(100);
                if (UoW.InTransaction)
                {
                    UoW.CommitChanges();
                }

                var UoWFromApi       = xpoInitializer.CreateUnitOfWork();
                var CustomersFromApi = new XPCollection <Customer>(UoWFromApi);
                foreach (var item in CustomersFromApi)
                {
                    Console.WriteLine(item.Name);
                }
            };
        }