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));
        }
        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));
        }
예제 #3
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));
        }
예제 #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);
        }
        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);
        }
        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));
        }
예제 #7
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));
        }