Ejemplo n.º 1
0
        public async Task Endpoints_WebApi_CustomerPost()
        {
            var responseData = new CustomerModel();
            var urlCustomer  = new ConfigurationManagerLocal().AppSettingValue("MyWebService").AddLast("/Customer");

            await this.Endpoints_WebApi_CustomerPut();

            var keyToGet = WebApiEndpointsTests.RecycleBin.Count() > 0 ? WebApiEndpointsTests.RecycleBin[0] : TypeExtension.DefaultGuid;

            var url        = new Uri(urlCustomer.AddLast("/") + keyToGet.ToStringSafe());
            var requestGet = new HttpRequestGet <CustomerModel>(url);

            responseData = await requestGet.SendAsync();

            Assert.IsTrue(interfaceBreakingRelease || !responseData.IsNew);

            var testKey = RandomString.Next();

            responseData.FirstName = responseData.FirstName.AddLast(testKey);
            var request = new HttpRequestPost <CustomerModel>(urlCustomer.TryParseUri(), responseData);

            responseData = await request.SendAsync();

            Assert.IsTrue(interfaceBreakingRelease || !responseData.IsNew);
            Assert.IsTrue(interfaceBreakingRelease || responseData.FirstName.Contains(testKey));
        }
Ejemplo n.º 2
0
        public async Task Endpoints_Framework_WebAPI_CustomerPost()
        {
            var responseData = new Customer();
            var urlCustomer  = new ConfigurationManagerCore(ApplicationTypes.Native).AppSettingValue("MyWebService").AddLast("/Customer");

            await this.Endpoints_Framework_WebAPI_CustomerPut();

            var keyToGet = Endpoints_Framework_for_WebApi.RecycleBin.Count() > 0 ? Endpoints_Framework_for_WebApi.RecycleBin[0] : Guid.Empty;

            try
            {
                var url        = new Uri(urlCustomer.AddLast("/") + keyToGet.ToStringSafe());
                var requestGet = new HttpRequestGet <Customer>(url);
                responseData = await requestGet.SendAsync();

                Assert.IsTrue(interfaceBreakingRelease || responseData != null);

                var testKey = RandomString.Next();
                responseData.FirstName = responseData.FirstName.AddLast(testKey);
                var request = new HttpRequestPost <Customer>(urlCustomer.TryParseUri(), responseData);
                responseData = await request.SendAsync();

                Assert.IsTrue(interfaceBreakingRelease || responseData != null);
                Assert.IsTrue(interfaceBreakingRelease || responseData.FirstName.Contains(testKey));
            }
            catch (HttpRequestException ex)
            {
                Assert.IsTrue(ex.Message.Contains("No such host") || ex.Message.Contains("no data"));
            }
        }
Ejemplo n.º 3
0
        public async Task Endpoints_Framework_WebAPI_CustomerDelete()
        {
            var responseData = new Customer();
            var urlCustomer  = new ConfigurationManagerCore(ApplicationTypes.Native).AppSettingValue("MyWebService").AddLast("/Customer");

            try
            {
                await this.Endpoints_Framework_WebAPI_CustomerPut();

                var keyToDelete = Endpoints_Framework_for_WebApi.RecycleBin.Count() > 0 ? Endpoints_Framework_for_WebApi.RecycleBin[0] : Guid.Empty;

                var requestDelete = new HttpRequestDelete(urlCustomer.AddLast("/") + keyToDelete.ToString());
                await requestDelete.SendAsync();

                Assert.IsTrue(interfaceBreakingRelease || requestDelete.Response.IsSuccessStatusCode);

                var requestGet = new HttpRequestGet <Customer>(urlCustomer);
                responseData = await requestGet.SendAsync();

                Assert.IsTrue(interfaceBreakingRelease || responseData != null);
            }
            catch (HttpRequestException ex)
            {
                Assert.IsTrue(ex.Message.Contains("No such host") || ex.Message.Contains("no data"));
            }
        }
        public async Task Endpoints_Framework_WebAPI_CustomerPost()
        {
            var responseData = new CustomerModel();
            var urlCustomer  = new ConfigurationManagerFull().AppSettingValue("MyWebService").AddLast("/Customer");

            await this.Endpoints_Framework_WebAPI_CustomerPut();

            var idToGet = Endpoints_Framework_for_WebApi.RecycleBin.Count() > 0 ? Endpoints_Framework_for_WebApi.RecycleBin[0] : TypeExtension.DefaultInteger;

            var url        = new Uri(urlCustomer.AddLast("/") + idToGet.ToStringSafe());
            var requestGet = new HttpRequestGet <CustomerModel>(url);

            responseData = await requestGet.SendAsync();

            Assert.IsTrue(!responseData.IsNew);

            var testKey = Guid.NewGuid().ToString();

            responseData.FirstName = responseData.FirstName.AddLast(testKey);
            var request = new HttpRequestPost <CustomerModel>(urlCustomer.TryParseUri(), responseData);

            responseData = await request.SendAsync();

            Assert.IsTrue(!responseData.IsNew);
            Assert.IsTrue(responseData.FirstName.Contains(testKey));
        }
Ejemplo n.º 5
0
        public async Task Customer_Cloud_CustomerPost()
        {
            CustomerModel responseData = new CustomerModel();
            HttpRequestGet <CustomerModel>  requestGet;
            HttpRequestPost <CustomerModel> request;
            int    idToGet = TypeExtension.DefaultInteger;
            string urlRoot = new ConfigurationManagerFull().AppSettingValue("MyWebService");
            string urlFull = TypeExtension.DefaultString;

            // Ensure customers exist
            await this.Customer_Cloud_CustomerPut();

            idToGet = recycleBin.Count() > 0 ? recycleBin[0] : TypeExtension.DefaultInteger;

            // Call the cloud and get results
            urlFull      = String.Format("{0}/{1}/{2}", urlRoot, "Customer", idToGet);
            requestGet   = new HttpRequestGet <CustomerModel>(urlFull);
            responseData = await requestGet.SendAsync();

            Assert.IsTrue(responseData.ID != TypeExtension.DefaultInteger, "Customer did not get.");
            Assert.IsTrue(responseData.Key != TypeExtension.DefaultGuid, "Customer did not get.");

            // Now edit the customer
            responseData.FirstName = responseData.FirstName + "Edited";
            request      = new HttpRequestPost <CustomerModel>(urlFull, responseData);
            responseData = await request.SendAsync();

            Assert.IsTrue(responseData.ID != TypeExtension.DefaultInteger, "Customer did not get.");
            Assert.IsTrue(responseData.FirstName.Contains("Edited") == true, "Customer did not get.");
        }
Ejemplo n.º 6
0
        public async Task Endpoints_WebApi_CustomerSearchGet()
        {
            var url         = new ConfigurationManagerLocal().AppSettingValue("MyWebService");
            var request     = new HttpRequestGet <CustomerSearchModel>(url + "/CustomerSearch/-1/i/x/");
            var returnValue = await request.SendAsync();

            Assert.IsTrue(interfaceBreakingRelease || request.Response.IsSuccessStatusCode, request.Response.ReasonPhrase);
            Assert.IsTrue(interfaceBreakingRelease || returnValue.Results.Count > 0);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Instantiates and transmits all data to the middle tier web service that will execute the workflow
        /// </summary>
        /// <returns></returns>
        public virtual async Task <TDataOut> SendGetAsync <TDataOut>(Uri fullUrl) where TDataOut : new()
        {
            var returnValue = default(TDataOut);
            var request     = new HttpRequestGet <TDataOut>(fullUrl);

            OnSendBegin(request);
            returnValue = await request.SendAsync();

            OnSendEnd(request);

            return(returnValue);
        }
Ejemplo n.º 8
0
        public async Task Endpoints_WebApi_CustomerGet()
        {
            var urlCustomer = new ConfigurationManagerLocal().AppSettingValue("MyWebService").AddLast("/Customer");

            await this.Endpoints_WebApi_CustomerPut();

            var keyToGet = (WebApiEndpointsTests.RecycleBin.Count() > 0 ? WebApiEndpointsTests.RecycleBin[0] : TypeExtension.DefaultGuid).ToString();
            var request  = new HttpRequestGet <CustomerModel>(urlCustomer.AddLast("/") + keyToGet.ToString());

            var responseData = await request.SendAsync();

            Assert.IsTrue(interfaceBreakingRelease || !responseData.IsNew);
        }
        public async Task Endpoints_Framework_WebAPI_CustomerGet()
        {
            var urlCustomer = new ConfigurationManagerFull().AppSettingValue("MyWebService").AddLast("/Customer");

            await this.Endpoints_Framework_WebAPI_CustomerPut();

            var idToGet = (Endpoints_Framework_for_WebApi.RecycleBin.Count() > 0 ? Endpoints_Framework_for_WebApi.RecycleBin[0] : TypeExtension.DefaultInteger).ToString();
            var request = new HttpRequestGet <CustomerModel>(urlCustomer.AddLast("/") + idToGet.ToString());

            var responseData = await request.SendAsync();

            Assert.IsTrue(!responseData.IsNew);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Reads an item from the system
        /// Constrained to 1 item. Search using Queryflow
        /// </summary>
        /// <param name="key">Key of the item to return</param>
        /// <returns>Item from the system</returns>
        public async Task <TDto> ReadAsync(Guid key)
        {
            TDto returnData;
            var  uriKey = new Uri($"{Uri.ToString().RemoveLast("/")}/{key.ToString()}");

            using (var client = new HttpRequestGet <TDto>(uriKey))
            {
                returnData = await client.SendAsync();

                Response = client.Response;
            }
            return(await Task.Run(() => returnData));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Reads an item from the system
        /// Constrained to 1 item. Search using Queryflow
        /// </summary>
        /// <param name="query">Querystring parameters that will result in one item returned</param>
        /// <returns>Item from the system</returns>
        public async Task <TDto> ReadAsync(string query)
        {
            TDto returnData;

            query = query.Replace("//", "/ /");
            var uriQuery = new Uri($"{Uri.ToString().RemoveLast("/")}{query.AddFirst("/")}");

            using (var client = new HttpRequestGet <TDto>(uriQuery))
            {
                returnData = await client.SendAsync();

                Response = client.Response;
            }
            return(await Task.Run(() => returnData));
        }
Ejemplo n.º 12
0
        public async Task Customer_Cloud_CustomerSearchGet()
        {
            CustomerSearchModel returnData = new CustomerSearchModel();
            HttpRequestGet <CustomerSearchModel> request;
            string urlRoot = new ConfigurationManagerFull().AppSettingValue("MyWebService");
            string urlFull = TypeExtension.DefaultString;

            // Find customer by first name. -1 for ID does not exist, and empty string Last Name doesnt exist
            urlFull    = String.Format("{0}/{1}/{2}?firstName={3}&lastName={4}", urlRoot, "CustomerSearch", -1, "i", "");
            request    = new HttpRequestGet <CustomerSearchModel>(urlFull);
            returnData = await request.SendAsync();

            Assert.IsTrue(returnData.Results.Count > 0, "Customer did not get.");
            Assert.IsTrue(returnData.FirstName != TypeExtension.DefaultString, "Customer did not get.");
        }
        public async Task Endpoints_Framework_WebAPI_CustomerDelete()
        {
            var responseData = new CustomerModel();
            var urlCustomer  = new ConfigurationManagerLocal().AppSettingValue("MyWebService").AddLast("/Customer");

            await this.Endpoints_Framework_WebAPI_CustomerPut();

            var keyToDelete = Endpoints_Framework_for_WebApi.RecycleBin.Count() > 0 ? Endpoints_Framework_for_WebApi.RecycleBin[0] : TypeExtension.DefaultGuid;

            var requestDelete = new HttpRequestDelete(urlCustomer.AddLast("/") + keyToDelete.ToString());
            await requestDelete.SendAsync();

            Assert.IsTrue(interfaceBreakingRelease || requestDelete.Response.IsSuccessStatusCode);

            var requestGet = new HttpRequestGet <CustomerModel>(urlCustomer);

            responseData = await requestGet.SendAsync();

            Assert.IsTrue(interfaceBreakingRelease || responseData.IsNew);
        }
Ejemplo n.º 14
0
        public async Task Core_Net_HttpRequestGet_SendAsync()
        {
            var    configuration = new ConfigurationManagerCore(ApplicationTypes.Native);
            object dataOut       = null;
            var    request       = new HttpRequestGet <object>(configuration.AppSettingValue("MyWebService") + "/HomeApi");

            try
            {
                dataOut = await request.SendAsync();

                Assert.IsTrue(request.Response.IsSuccessStatusCode);
                throw new HttpRequestException();
            }
            catch (HttpRequestException ex)
            {
                Assert.IsTrue(dataOut != null || ex.Message.Contains("No such host") || ex.Message.Contains("no data"));
            }
            finally
            {
                request.Dispose();
            }
        }
Ejemplo n.º 15
0
        public async Task Net_HttpRequestGet_SendAsync()
        {
            var    configuration = ConfigurationManagerSafeTests.ConfigurationManagerSafeConstruct();
            object dataOut       = null;
            var    request       = new HttpRequestGet <object>(configuration.AppSettingValue("MyWebService") + "/HomeApi");

            try
            {
                dataOut = await request.SendAsync();

                Assert.IsTrue(request.Response.IsSuccessStatusCode);
                throw new WebException();
            }
            catch (WebException)
            {
                Assert.IsTrue(dataOut != null);
            }
            finally
            {
                request.Dispose();
            }
        }