Example #1
0
        public void With_non_duplicate_Exception_SavePerson_should_throw_it()
        {
            //person - throw non-duplicated-exception
            _duplicateServiceMock.Setup(x => x.GetDuplicateDetectHashData(It.Is <PersonEntity>(m => m.FirstName == "OtherException")))
            .Returns(
                Task.FromResult("exceptionDuplicatedPersonHashdata")
                );

            _odataClientMock.Setup(x => x.For <SSG_Person>(null).Set(It.Is <PersonEntity>(x => x.DuplicateDetectHash == "exceptionDuplicatedPersonHashdata"))
                                   .InsertEntryAsync(It.IsAny <CancellationToken>()))
            .Throws(WebRequestException.CreateFromStatusCode(
                        System.Net.HttpStatusCode.BadRequest,
                        new WebRequestExceptionMessageSource(),
                        ""
                        ));

            var person = new PersonEntity()
            {
                FirstName     = "OtherException",
                SearchRequest = new SSG_SearchRequest()
                {
                    SearchRequestId = _testId
                }
            };

            Assert.ThrowsAsync <WebRequestException>(async() => await _sut.SavePerson(person, CancellationToken.None));
        }
        public void exception_cancel_SearchRequest_should_throw_exception()
        {
            Guid searchRequestId = Guid.NewGuid();

            _odataClientMock.Setup(x => x.For <SSG_SearchRequest>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_SearchRequest, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchRequest>(new SSG_SearchRequest()
            {
                SearchRequestId = searchRequestId
            }));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequest>(null)
                                   .Key(searchRequestId)
                                   .Set(new Dictionary <string, object>()
            {
                { Keys.DYNAMICS_STATUS_CODE_FIELD, SearchRequestStatusCode.AgencyCancelled.Value },
                { Keys.DYNAMICS_SEARCH_REQUEST_CANCEL_COMMENTS_FIELD, "comments" }
            })
                                   .UpdateEntryAsync(It.IsAny <CancellationToken>()))
            .Throws(WebRequestException.CreateFromStatusCode(
                        System.Net.HttpStatusCode.NotFound,
                        new WebRequestExceptionMessageSource(),
                        ""
                        ));

            Assert.ThrowsAsync <WebRequestException>(async() => await _sut.CancelSearchRequest("fileId", "comments", CancellationToken.None));
        }
        public void upload_invalid_searchReason_SearchRequest_should_throw_exception()
        {
            _odataClientMock.Setup(x => x.For <SSG_Agency>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_Agency, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Agency>(new SSG_Agency()
            {
                AgencyId   = Guid.NewGuid(),
                AgencyCode = "fmep"
            }));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequestReason>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_SearchRequestReason, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Throws(WebRequestException.CreateFromStatusCode(
                        System.Net.HttpStatusCode.NotFound,
                        new WebRequestExceptionMessageSource(),
                        ""
                        ));

            var searchRequest = new SearchRequestEntity()
            {
                AgencyCode               = "fmep",
                SearchReasonCode         = "wrongreasoncode",
                AgencyOfficeLocationText = "NORTHERN AND INTERIOR CLIENT OFFICE, KAMLOOPS, BC",
                AgentFirstName           = "agentName"
            };

            Assert.ThrowsAsync <WebRequestException>(async() => await _sut.CreateSearchRequest(searchRequest, CancellationToken.None));
        }
Example #4
0
        public async Task with_duplicated_upload_person_should_return_original_person_guid()
        {
            _duplicateServiceMock.Setup(x => x.GetDuplicateDetectHashData(It.Is <PersonEntity>(m => m.FirstName == "Duplicated")))
            .Returns(
                Task.FromResult("duplicatedPersonHashdata")
                );

            _odataClientMock.Setup(x => x.For <SSG_Person>(null).Set(It.Is <PersonEntity>(x => x.FirstName == "Duplicated"))
                                   .InsertEntryAsync(It.IsAny <CancellationToken>()))
            .Throws(WebRequestException.CreateFromStatusCode(
                        System.Net.HttpStatusCode.PreconditionFailed,
                        new WebRequestExceptionMessageSource(),
                        "{\"error\":{\"code\":\"0x80060892\"}}"
                        ));

            _odataClientMock.Setup(x => x.For <SSG_Person>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_Person, bool> > >())
                                   .Expand(x => x.SSG_Addresses)
                                   .Expand(x => x.SSG_Identifiers)
                                   .Expand(x => x.SSG_Aliases)
                                   .Expand(x => x.SSG_Asset_BankingInformations)
                                   .Expand(x => x.SSG_Asset_ICBCClaims)
                                   .Expand(x => x.SSG_Asset_Others)
                                   .Expand(x => x.SSG_Asset_Vehicles)
                                   .Expand(x => x.SSG_Asset_WorkSafeBcClaims)
                                   .Expand(x => x.SSG_Employments)
                                   .Expand(x => x.SSG_Identities)
                                   .Expand(x => x.SSG_PhoneNumbers)
                                   .Expand(x => x.SSG_SafetyConcernDetails)
                                   .Expand(x => x.SSG_Emails)
                                   .Expand(x => x.SearchRequest)
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_Person()
            {
                FirstName = "FirstName",
                PersonId  = _testPersonId
            }));

            var person = new PersonEntity()
            {
                FirstName     = "Duplicated",
                SearchRequest = new SSG_SearchRequest()
                {
                    SearchRequestId = _testId
                }
            };

            var result = await _sut.SavePerson(person, CancellationToken.None);

            Assert.AreEqual("FirstName", result.FirstName);
            Assert.AreEqual(_testPersonId, result.PersonId);
            Assert.AreEqual(true, result.IsDuplicated);
        }
Example #5
0
    private async Task PostExecute(HttpResponseMessage responseMessage)
    {
        _session.Settings.AfterResponse?.Invoke(responseMessage);
        if (_session.Settings.AfterResponseAsync != null)
        {
            await _session.Settings.AfterResponseAsync(responseMessage).ConfigureAwait(false);
        }

        if (!responseMessage.IsSuccessStatusCode)
        {
            throw await WebRequestException.CreateFromResponseMessageAsync(responseMessage, _session.Settings.WebRequestExceptionMessageSource).ConfigureAwait(false);
        }
    }
        public async Task upload_invalid_locationtext_SearchRequest_should_upload_locationText()
        {
            _odataClientMock.Setup(x => x.For <SSG_Agency>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_Agency, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_Agency>(new SSG_Agency()
            {
                AgencyId   = Guid.NewGuid(),
                AgencyCode = "fmep"
            }));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequestReason>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_SearchRequestReason, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <SSG_SearchRequestReason>(new SSG_SearchRequestReason()
            {
                ReasonId   = Guid.NewGuid(),
                ReasonCode = "reasonCode"
            }));

            _odataClientMock.Setup(x => x.For <SSG_AgencyLocation>(null)
                                   .Filter(It.IsAny <Expression <Func <SSG_AgencyLocation, bool> > >())
                                   .FindEntryAsync(It.IsAny <CancellationToken>()))
            .Throws(WebRequestException.CreateFromStatusCode(
                        System.Net.HttpStatusCode.NotFound,
                        new WebRequestExceptionMessageSource(),
                        ""
                        ));

            _odataClientMock.Setup(x => x.For <SSG_SearchRequest>(null).Set(It.IsAny <SearchRequestEntity>())
                                   .InsertEntryAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new SSG_SearchRequest()
            {
                SearchRequestId = testId,
            })
                     );

            var searchRequest = new SearchRequestEntity()
            {
                AgencyCode               = "fmep",
                SearchReasonCode         = "reason",
                AgencyOfficeLocationText = "WRONG ADDRESS,BC",
                AgentFirstName           = "agentName"
            };

            var result = await _sut.CreateSearchRequest(searchRequest, CancellationToken.None);

            _odataClientMock.Verify(x => x.For <SSG_SearchRequest>(It.IsAny <string>())
                                    .Set(It.Is <SearchRequestEntity>(m => m.AgencyOfficeLocationText == "WRONG ADDRESS,BC"))
                                    .InsertEntryAsync(It.IsAny <CancellationToken>()), Times.Once);
        }
Example #7
0
 public static bool IsDuplicateHashError(this WebRequestException exception)
 {
     if (exception != null && exception.Code == System.Net.HttpStatusCode.PreconditionFailed)
     {
         if (exception.Response != null)
         {
             var rootObj = JsonConvert.DeserializeObject <RootObject>(exception.Response);
             if (rootObj.Error.Code == DUPLICATED_ERROR_CODE)
             {
                 return(true);
             }
             return(false);
         }
         return(false);
     }
     return(false);
 }
        public void exception_UpdateSearchRequest_should_throw_exception()
        {
            _odataClientMock.Setup(x => x.For <SSG_SearchRequest>(null).Key(It.Is <Guid>(m => m == testId)).Set(It.IsAny <Dictionary <string, object> >())
                                   .UpdateEntryAsync(It.IsAny <CancellationToken>()))
            .Throws(WebRequestException.CreateFromStatusCode(
                        System.Net.HttpStatusCode.NotFound,
                        new WebRequestExceptionMessageSource(),
                        ""
                        ));

            var searchRequest = new SSG_SearchRequest()
            {
                AgencyCode      = "fmep",
                SearchRequestId = testId
            };
            IDictionary <string, object> updatedFields = new Dictionary <string, object> {
                { "businessname", "new" }
            };

            Assert.ThrowsAsync <WebRequestException>(async() => await _sut.UpdateSearchRequest(testId, updatedFields, CancellationToken.None));
        }
Example #9
0
 internal static ODataResponse FromStatusCode(ITypeCache typeCache, int statusCode, IEnumerable <KeyValuePair <string, string> > headers, Stream responseStream, WebRequestExceptionMessageSource exceptionMessageSource)
 {
     if (statusCode >= (int)HttpStatusCode.BadRequest)
     {
         var responseContent = Utils.StreamToString(responseStream, true);
         return(new ODataResponse(typeCache)
         {
             StatusCode = statusCode,
             Exception = WebRequestException.CreateFromStatusCode((HttpStatusCode)statusCode, exceptionMessageSource, responseContent),
             Headers = headers
         });
     }
     else
     {
         return(new ODataResponse(typeCache)
         {
             StatusCode = statusCode,
             Headers = headers
         });
     }
 }
        public void exception_systemcancel_SearchRequest_should_throw_exception()
        {
            Guid searchRequestId = Guid.NewGuid();

            _odataClientMock.Setup(x => x.For <SSG_SearchRequest>(null)
                                   .Key(It.IsAny <Guid>())
                                   .Set(new Dictionary <string, object>()
            {
                { Keys.DYNAMICS_STATE_CODE_FIELD, 1 },
                { Keys.DYNAMICS_STATUS_CODE_FIELD, SearchRequestStatusCode.SystemCancelled.Value },
                { Keys.DYNAMICS_SEARCH_REQUEST_CANCEL_COMMENTS_FIELD, "Incomplete Search Request" }
            })
                                   .UpdateEntryAsync(It.IsAny <CancellationToken>()))
            .Throws(WebRequestException.CreateFromStatusCode(
                        System.Net.HttpStatusCode.NotFound,
                        new WebRequestExceptionMessageSource(),
                        ""
                        ));

            Assert.ThrowsAsync <WebRequestException>(async() => await _sut.SystemCancelSearchRequest(new SSG_SearchRequest {
                SearchRequestId = searchRequestId
            }, CancellationToken.None));
        }
Example #11
0
        public async void ValidateDelivery()
        {
            _request = GetDefaultRequest();

            Console.Write("\nEnter Api Key: ");
            _apiKey = Console.ReadLine();

            Console.Write("\nEnter External Business Name: ");
            _request.external_business_name = Console.ReadLine();

            Console.WriteLine("\nEnter Pickup Address:");
            Console.WriteLine("---------------------");
            _request.pickup_address = CreateAddress();

            Console.WriteLine("\nEnter Dropoff Address:");
            Console.WriteLine("---------------------");
            _request.dropoff_address = CreateAddress();

            var estimate     = new DeliveryEstimate();
            var executor     = new WebRequestExecutor();
            var errorMessage = string.Empty;

            try
            {
                var response = await executor.PostAsync(_request, _url, _apiKey);

                estimate = ProcessResponse(response);
            }
            catch (Exception exception)
            {
                var webException        = (WebException)exception.InnerException;
                var webRequestException = new WebRequestException(webException);
                errorMessage = webRequestException.Message;
                estimate     = null;
            }

            if (estimate != null && estimate.field_errors == null)
            {
                var timeEnroute = (estimate.delivery_time - estimate.pickup_time).TotalMinutes;
                Console.WriteLine(String.Format("\nDoorDash will deliver from {0} to {1}.\nApproximate time enroute is {2} minutes.", _request.pickup_address.street, _request.dropoff_address.street, timeEnroute));
            }
            else if (estimate != null)
            {
                Console.WriteLine(String.Format("\nDoorDash will NOT deliver from {0} to {1}.", _request.pickup_address.street, _request.dropoff_address.street));

                foreach (var error in estimate.field_errors)
                {
                    Console.WriteLine(String.Format("Problem: {0}: {1}", error["field"], error["error"]));
                }
            }
            else
            {
                Console.WriteLine("\nERROR -- Problem with credentials or formatting.\n");

                if (!string.IsNullOrEmpty(errorMessage))
                {
                    Console.Write(errorMessage);
                }
            }
            Console.ReadLine();
        }
Example #12
0
    public async Task <HttpResponseMessage> ExecuteRequestAsync(ODataRequest request, CancellationToken cancellationToken)
    {
        HttpConnection?httpConnection = null;

        try
        {
            await PreExecuteAsync(request).ConfigureAwait(false);

            _session.Trace("{0} request: {1}", request.Method, request.RequestMessage.RequestUri.AbsoluteUri);
            if (request.RequestMessage.Content != null && (_session.Settings.TraceFilter & ODataTrace.RequestContent) != 0)
            {
                var content = await request.RequestMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

                _session.Trace("Request content:{0}{1}", Environment.NewLine, content);
            }

            HttpResponseMessage response;
            if (_session.Settings.RequestExecutor != null)
            {
                response = await _session.Settings.RequestExecutor(request.RequestMessage).ConfigureAwait(false);
            }
            else
            {
                httpConnection = _session.Settings.RenewHttpConnection
                                        ? new HttpConnection(_session.Settings)
                                        : _session.GetHttpConnection();

                response = await httpConnection.HttpClient.SendAsync(request.RequestMessage, cancellationToken).ConfigureAwait(false);

                if (cancellationToken.IsCancellationRequested)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                }
            }

            _session.Trace("Request completed: {0}", response.StatusCode);
            if (response.Content != null && (_session.Settings.TraceFilter & ODataTrace.ResponseContent) != 0)
            {
                var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                _session.Trace("Response content:{0}{1}", Environment.NewLine, content);
            }

            await PostExecute(response).ConfigureAwait(false);

            return(response);
        }
        catch (WebException ex)
        {
            throw WebRequestException.CreateFromWebException(ex);
        }
        catch (AggregateException ex)
        {
            if (ex.InnerException is WebException)
            {
                throw WebRequestException.CreateFromWebException(ex.InnerException as WebException);
            }
            else
            {
                throw;
            }
        }
        finally
        {
            if (httpConnection != null && _session.Settings.RenewHttpConnection)
            {
                httpConnection.Dispose();
            }
        }
    }