public void SingleResource_Verify_CanCreate()
        {
            var request = new SDataSingleResourceRequest(_service)
            {
                ResourceKind = "employees"
            };

            var payload = new SDataPayload();

            payload.Values["Title"]            = "create 1";
            payload.Values["NationalIdNumber"] = "44444";
            payload.Values["LoginId"]          = "create 4";
            payload.Values["ContactId"]        = "9999";
            payload.Values["BirthDate"]        = SyndicationDateTimeUtility.ToRfc3339DateTime(new DateTime(1970, 8, 2));
            payload.Values["HireDate"]         = SyndicationDateTimeUtility.ToRfc3339DateTime(DateTime.Now);
            payload.Values["ModifiedDate"]     = SyndicationDateTimeUtility.ToRfc3339DateTime(DateTime.Now);
            payload.Values["MaritalStatus"]    = "Single";
            payload.Values["SalariedFlag"]     = XmlConvert.ToString(true);
            payload.Values["CurrentFlag"]      = XmlConvert.ToString(true);
            payload.Values["Gender"]           = "Male";
            payload.Values["RowGuid"]          = Guid.NewGuid().ToString();

            var entry = new AtomEntry
            {
                UpdatedOn   = DateTime.Now,
                PublishedOn = DateTime.Now
            };

            entry.SetSDataPayload(payload);
            request.Entry = entry;
            _mock.Setup(s => s.CreateEntry(request, request.Entry)).Returns(TestData.Entry);

            entry = request.Create();
            Expect(entry, Is.Not.Null);
        }
        public void SingleResource_Verify_CanConstructWithTemplateEntry()
        {
            var entry   = new AtomEntry();
            var request = new SDataSingleResourceRequest(_service, entry);

            Expect(request, Is.Not.Null);
            Expect(request.Entry, Is.Not.Null);
        }
Exemplo n.º 3
0
        private SDataSingleResourceRequest CreateResourceRequest(string entityId)
        {
            var request = new SDataSingleResourceRequest(_sdataService);

            request.ResourceKind = _requestTypeInfo.ResourceKind;
            if (!string.IsNullOrEmpty(entityId))
            {
                request.ResourceSelector = "('" + entityId + "')";
            }
            return(request);
        }
        public void SingleResource_Verify_ToStringWithResourceKind()
        {
            var request = new SDataSingleResourceRequest(_service)
            {
                ResourceKind     = "employees",
                ResourceSelector = "id eq '1234'"
            };

            var url = request.ToString();

            Expect(url, Is.EqualTo("http://localhost:59213/sdata/aw/dynamic/-/employees(id eq '1234')"));
        }
        public void SingleResource_Verify_ToStringWithResourceKindAndInclude()
        {
            var request = new SDataSingleResourceRequest(_service)
            {
                ResourceKind     = "employees",
                ResourceSelector = "1",
                Include          = "contact"
            };

            var url = request.ToString();

            Expect(url, Is.EqualTo("http://localhost:59213/sdata/aw/dynamic/-/employees(1)?include=contact"));
        }
        public void SingleResource_Verify_CanRead()
        {
            var request = new SDataSingleResourceRequest(_service)
            {
                ResourceKind     = "employees",
                ResourceSelector = "1"
            };

            _mock.Setup(s => s.ReadEntry(request)).Returns(TestData.Entry);

            var entry = request.Read();

            Expect(entry, Is.Not.Null);
        }
        public bool InsertRecord <T>(T dataItem)
        {
            bool returnData = false;

            // Create a SData serivce object connection.  Use the proper url and login info.
            ISDataService svc = new SDataService(GetFullSDataUrl(), _userId, _password);

            // Create the SData Payload of data to be sent
            SDataPayload myPayload = new SDataPayload();

            myPayload.Namespace    = string.Empty;
            myPayload.ResourceName = typeof(T).Name;
            myPayload.Uri          = new Uri(svc.Url);

            // Add to an ATOM feed entry b/c that's what SData uses
            AtomEntry myEntry = new AtomEntry();

            myEntry.SetSDataPayload(myPayload);

            // loop through the properties to find matching data from our query
            foreach (PropertyInfo property in dataItem.GetType().GetProperties())
            {
                // If the property value is null, don't add it
                if (property.GetValue(dataItem) == null)
                {
                    continue;
                }

                myPayload.Values.Add(property.Name, property.GetValue(dataItem));
            }

            // prepare the create request
            SDataSingleResourceRequest sendRequest = new SDataSingleResourceRequest(svc, myEntry);

            sendRequest.ResourceKind     = typeof(T).Name;
            sendRequest.ResourceSelector = "";

            try
            {
                AtomEntry response = sendRequest.Create();
                returnData = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                returnData = false;
            }

            return(returnData);
        }
 public override void Refresh()
 {
     try
     {
         _sdataSingleResourceRequest = new SDataSingleResourceRequest(Service)
         {
             ResourceKind     = tbSingleResourceKind.Text,
             ResourceSelector = tbSingleResourceSelector.Text
         };
         tbSingleURL.Text = _sdataSingleResourceRequest.ToString();
     }
     catch (SDataClientException ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        public void SingleResource_Verify_CanProcess_SDataBatchRequest()
        {
            var request1 = new SDataSingleResourceRequest(_service)
            {
                ResourceKind     = "employees",
                ResourceSelector = "1"
            };
            var request2 = new SDataSingleResourceRequest(_service)
            {
                ResourceKind     = "employees",
                ResourceSelector = "2"
            };
            var request3 = new SDataSingleResourceRequest(_service)
            {
                ResourceKind     = "employees",
                ResourceSelector = "3"
            };

            _mock.Setup(s => s.ReadEntry(request1)).Returns(TestData.Entry);
            _mock.Setup(s => s.ReadEntry(request2)).Returns(TestData.Entry);
            _mock.Setup(s => s.ReadEntry(request3)).Returns(TestData.Entry);

            request2.Entry = request2.Read();
            request3.Entry = request3.Read();

            _mock.Setup(s => s.UpdateEntry(request2, request2.Entry)).Returns(TestData.Entry);
            _mock.Setup(s => s.DeleteEntry(request3, request3.Entry)).Returns(true);

            var payload2 = request2.Entry.GetSDataPayload();

            payload2.Values["MaritalStatus"] = "Married";

            AtomFeed batchfeed;

            using (var batch = new SDataBatchRequest(_service))
            {
                batch.ResourceKind = "employees";
                request1.Read();
                request2.Update();
                request3.Delete();

                _mock.Setup(s => s.CreateFeed(batch, It.IsAny <AtomFeed>())).Returns(TestData.Feed);
                batchfeed = batch.Commit();
            }

            Expect(batchfeed, Is.Not.Null);
        }
        public bool UpdateTechnicianRecord(JT_Technician dataItem)
        {
            bool returnData = false;

            // Create a SData serivce object connection.  Use the proper url and login info.
            ISDataService svc = new SDataService(GetFullSDataUrl(), _userId, _password);

            // Create the SData Payload of data to be sent
            SDataPayload myPayload = new SDataPayload();

            myPayload.Namespace    = string.Empty;
            myPayload.ResourceName = typeof(JT_Technician).Name;
            myPayload.Uri          = new Uri(svc.Url);

            // Add to an ATOM feed entry b/c that's what SData uses
            AtomEntry myEntry = new AtomEntry();

            myEntry.SetSDataPayload(myPayload);

            // update only specific properties
            myPayload.Values.Add("CurrentStartTime", dataItem.CurrentStartTime);
            myPayload.Values.Add("CurrentStartDate", dataItem.CurrentStartDate.ToString("yyyy-MM-dd"));
            myPayload.Values.Add("CurrentSalesOrderNo", dataItem.CurrentSalesOrderNo);
            myPayload.Values.Add("CurrentWTNumber", dataItem.CurrentWTNumber);
            myPayload.Values.Add("CurrentWTStep", dataItem.CurrentWTStep);
            myPayload.Values.Add("CurrentStatus", dataItem.CurrentStatus);

            // prepare the create request
            SDataSingleResourceRequest sendRequest = new SDataSingleResourceRequest(svc, myEntry);

            sendRequest.ResourceKind     = typeof(JT_Technician).Name;
            sendRequest.ResourceSelector = dataItem.TechnicianDeptNo + ";" + dataItem.TechnicianNo;

            try
            {
                AtomEntry response = sendRequest.Update();
                returnData = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                returnData = false;
            }

            return(returnData);
        }
        public void SingleResource_Verify_CanDelete()
        {
            var request = new SDataSingleResourceRequest(_service)
            {
                ResourceKind     = "employees",
                ResourceSelector = "1"
            };

            _mock.Setup(s => s.ReadEntry(request)).Returns(TestData.Entry);

            request.Entry = request.Read();

            _mock.Setup(s => s.DeleteEntry(request, request.Entry)).Returns(true);

            var result = request.Delete();

            Expect(result);
        }
        public void SingleResource_Verify_CanUpdate()
        {
            var request = new SDataSingleResourceRequest(_service)
            {
                ResourceKind     = "employees",
                ResourceSelector = "1"
            };

            _mock.Setup(s => s.ReadEntry(request)).Returns(TestData.Entry);

            var entry   = request.Read();
            var payload = entry.GetSDataPayload();

            payload.Values["Title"] = "test update";
            request.Entry           = entry;
            _mock.Setup(s => s.UpdateEntry(request, request.Entry)).Returns(TestData.Entry);

            entry = request.Update();
            Expect(entry, Is.Not.Null);
        }
        public void SingleResource_Verify_CanConstruct()
        {
            var request = new SDataSingleResourceRequest(_service);

            Expect(request, Is.Not.Null);
        }
Exemplo n.º 14
0
        private static void Main()
        {
            var service = new SDataService();

            // set user name to authenticate with
            service.UserName = "******";
            // set password to authenticate with
            service.Password = "";

            service.Protocol         = "HTTP";
            service.ServerName       = "sdata.acme.com";
            service.ApplicationName  = "sageApp";
            service.VirtualDirectory = "sdata";

            AtomFeed     feed;
            AtomEntry    entry;
            SDataPayload payload;

            #region CREATE an Entry

            // read the template for accounts
            var tru1 = new SDataTemplateResourceRequest(service);
            tru1.ContractName = "test";
            tru1.ResourceKind = "accounts";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template

            // read the entry from the server
            entry = service.ReadEntry(tru1);

            // TODO: Make changes to the entry payload
            payload = entry.GetSDataPayload();

            var sru1 = new SDataSingleResourceRequest(service);
            sru1.ContractName = "test";
            sru1.ResourceKind = "accounts";

            var newEntry = service.CreateEntry(sru1, entry);

            #endregion

            #region CREATE a BATCH Operaton (Synchronous)

            // create the BatchURL
            var sbu = new SDataBatchRequest(service);
            sbu.ContractName = "test";
            sbu.ResourceKind = "products";
            // the configuration above generates http://sdata.acme.com/sageApp/test/-/products/$batch

            using (var batch = new SDataBatchRequest(service))
            {
                // read the template for accounts
                var templateResourceRequest = new SDataTemplateResourceRequest(service);
                templateResourceRequest.ContractName = "test";
                templateResourceRequest.ResourceKind = "accounts";
                // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template

                // read the entry from the server
                var templateEntry = service.ReadEntry(templateResourceRequest);

                var insertRequest = new SDataSingleResourceRequest(service);
                insertRequest.ContractName = "test";
                insertRequest.ResourceKind = "accounts";

                // do some stuff with the entry

                service.CreateEntry(insertRequest, templateEntry);

                // build, submit and get
                var result = batch.Commit();
            }

            #endregion

            #region CREATE a BATCH Operation (Asynchronous)

            // create the BatchURL
            sbu = new SDataBatchRequest(service);
            sbu.ContractName = "test";
            sbu.ResourceKind = "products";

            // the configuration above generates http://sdata.acme.com/sageApp/test/-/products/$batch

            using (var batch = new SDataBatchRequest(service))
            {
                // read the template for accounts
                var templateResourceRequest = new SDataTemplateResourceRequest(service);
                templateResourceRequest.ContractName = "test";
                templateResourceRequest.ResourceKind = "accounts";
                // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template

                // read the entry from the server
                var templateEntry = service.ReadEntry(templateResourceRequest);

                var insertRequest = new SDataSingleResourceRequest(service);
                insertRequest.ContractName = "test";
                insertRequest.ResourceKind = "accounts";

                // do some stuff with the entry

                var request = batch.CreateAsync();
                ISyndicationResource result;

                // wait around until the response is ready
                do
                {
                    var progress = request.Progress;
                } while ((result = request.Refresh()) == null);

                feed = result as AtomFeed;
            }

            #endregion

            #region READ a Resource Collection Feed

            // Read a Resource Collection Feed
            var rcu = new SDataResourceCollectionRequest(service);
            rcu.ContractName = "test";
            rcu.DataSet      = "prod";
            rcu.ResourceKind = "accounts";

            // pageing
            rcu.StartIndex = 21;
            rcu.Count      = 10;

            // query
            rcu.QueryValues.Add("where", "accountid='123456789abc'");
            rcu.QueryValues.Add("orderby", "'account'");

            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/prod/accounts?startIndex=21&count=10
            // Read the feed from the server
            feed = service.ReadFeed(rcu);

            #endregion

            #region READ a Single Resource Entry

            // Read a Single Resource Entry
            var sru = new SDataSingleResourceRequest(service);
            sru.ContractName     = "test";
            sru.ResourceKind     = "accounts";
            sru.ResourceSelector = "'A001'";
            // the above configuration generates  http://sdata.acme.com/sdata/sageApp/test/-/accounts('A001')

            // read the entry from the server
            entry = service.ReadEntry(sru);

            #endregion

            #region READ a Resource Property

            var rpu = new SDataResourcePropertyRequest(service);
            rpu.ContractName     = "test";
            rpu.ResourceKind     = "accounts";
            rpu.ResourceSelector = "'A001'";
            rpu.ResourceProperties.Add("postalAddress");
            rpu.ResourceProperties.Add("country");
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/accounts('A001')/postalAddress/country

            // read the entry from the server
            entry = service.ReadEntry(rpu);

            // now reconfigure and read property as a feed
            rpu.ResourceProperties.Add("salesOrders('0023')");
            rpu.ResourceProperties.Add("orderLines");
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts('A001')/salesOrders('0023')/orderLines

            // read the feed from the server
            service.ReadFeed(rpu);

            #endregion

            #region READ a Template Resource

            var tru = new SDataTemplateResourceRequest(service);
            tru.ContractName = "test";
            tru.ResourceKind = "accounts";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$template

            // read the entry from the server
            entry = service.ReadEntry(tru);

            #endregion

            #region READ a Resource Schema

            var rsu = new SDataResourceSchemaRequest(service);
            rsu.ContractName = "test";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/$schema

            // read the feed from the server
            var schema = service.ReadSchema(rsu);

            // now reconfigurate and set resource kind and version
            rsu.ResourceKind = "accounts";
            rsu.Version      = "5";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/-/accounts/$schema?version=5

            // read the entry from the server
            schema = service.ReadSchema(rsu);

            #endregion

            #region READ System Resources or Services

            var su = new SDataSystemRequest(service);

            // the above configuration generates http://sdata.acme.com/sdata/$system
            // read the feed from the server
            service.ReadFeed(su);

            #endregion

            #region READ Intermediate URLS

            #region READ Enumeration of Applications

            var iau = new IntermediateApplicationsRequest(service);

            // the above configuration generates http://sdata.acme.com/sdata

            // read the feed from the server
            service.ReadFeed(iau);

            #endregion

            #region READ Enumeration of DataSets

            var idu = new IntermediateDataSetsRequest(service);
            // the above configuration generates http://sdata.acme.com/sdata/sageApp

            // read the feed from the server
            feed = service.ReadFeed(idu);

            #endregion

            #region READ Enumeration of Contracts

            var icu = new IntermediateContractsRequest(service);

            // the above configuration generates http://sdata.acme.com/sdata/sageApp

            // read the feed from the server
            feed = service.ReadFeed(icu);

            #endregion

            #region READ Enumeration of Resource Collections

            var ircu = new IntermediateResourceCollectionsRequest(service);
            ircu.ContractName = "test";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test

            // read the feed from the server
            feed = service.ReadFeed(ircu);

            #endregion

            #region READ Enumeration of Services

            var isu = new IntermediateServicesRequest(service);
            isu.ContractName = "test";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/$service

            // read the feed from the server
            service.ReadFeed(isu);

            // reconfigure and set the resource kind
            isu.ResourceKind = "accounts";
            // the above configuration generates http://sdata.acme.com/sdata/sageApp/test/accounts/$service
            // read the feed from the server
            service.ReadFeed(isu);

            #endregion

            #endregion

            #region Update an Entry

            // Read a Single Resource Entry
            var sru2 = new SDataSingleResourceRequest(service);
            sru2.ContractName     = "test";
            sru2.ResourceKind     = "accounts";
            sru2.ResourceSelector = "'A001'";
            // the above configuration generates  http://sdata.acme.com/sdata/sageApp/test/accounts('A001')

            // TODO: Make changes to the entry payload
            payload = newEntry.GetSDataPayload();
            // update the server
            service.UpdateEntry(sru2, newEntry);

            #endregion

            #region DELETE an Entry

            service.DeleteEntry(sru2, newEntry);

            #endregion
        }