コード例 #1
0
        static void Main(string[] args)
        {
            //Register XpoWebApiProvider
            XpoWebApiProvider.Register();



            var ConnectionString = XpoWebApiProvider.GetConnectionString("https://localhost:44389", "/XpoWebApi", string.Empty, "001");

            XpoInitializer xpoInitializer = new XpoInitializer(ConnectionString, 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);
                }
                Console.ReadKey();
            }
        }
コード例 #2
0
        public void ICommandChannelTest()
        {
            XpoWebApiProvider.Register();

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

            if (File.Exists("db011.db"))
            {
                File.Delete("db011.db");
            }

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

            Headers.Add(XpoWebApiProvider.TokenPart, "");
            Headers.Add(XpoWebApiProvider.DataStoreIdPart, "011");
            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));

            var ExecuteQueryData = UoW.ExecuteQuery("Select * from customer");

            var ExecuteScalarData = UoW.ExecuteScalar("Select * from customer");

            //
            var ExecuteNonQueryData = UoW.ExecuteNonQuery($"UPDATE customer SET Name = 'Joche Ojeda' WHERE Name = '{customer.Name}';");

            Assert.NotNull(CustomerFromDataStore);
            Assert.NotNull(ExecuteQueryData);
            Assert.NotNull(ExecuteScalarData);
            Assert.AreEqual(1, ExecuteNonQueryData);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }