Exemple #1
0
        /// <summary>
        /// Search for project.
        /// </summary>
        /// <param name="v_sProjectName"></param>
        /// <returns></returns>
        public async Task <ObservableCollection <SearchResult> > SearchForProject(string v_sProjectName)
        {
            ProjectSearchResult srProject = null;
            ObservableCollection <SearchResult> oResults = new ObservableCollection <SearchResult>();

            try
            {
                srProject = await DependencyService.Get <IWcfExt116>().SearchForContractAsync(
                    m_cCompanyName,
                    v_sProjectName,
                    Settings.p_sSetting_AuthID,
                    Session.Token);

                if (srProject != null)
                {
                    if (srProject.bSuccessfull == true)
                    {
                        oResults = srProject.SearchResults;
                    }
                }

                return(oResults);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + " - ProjectName(" + v_sProjectName + ")");
            }
        }
        public async Task SearchName_ResultCountMoreThanMax_Success()
        {
            // Arrange
            const int projectId      = 10;
            var       searchCriteria = new SearchCriteria {
                Query = "Test"
            };
            var project = new ProjectSearchResult {
                ItemId = projectId, Name = searchCriteria.Query
            };
            var searchResult = new ProjectSearchResultSet {
                Items = new[] { project }
            };
            var controller = CreateController(searchCriteria, searchResult);

            // Act
            var result = await controller.SearchName(searchCriteria, 1000);

            // Assert
            Assert.IsNotNull(result);
            var projectSearchResults = result.Items.ToList();

            Assert.AreEqual(projectSearchResults.Count, 1);
            Assert.AreEqual(projectId, projectSearchResults[0].ItemId);
        }
        public async Task SearchName_Forbidden()
        {
            // Arrange
            const int projectId      = 10;
            var       searchCriteria = new SearchCriteria {
                Query = "Test"
            };
            var project = new ProjectSearchResult {
                ItemId = projectId, Name = searchCriteria.Query
            };
            var searchResult = new ProjectSearchResultSet {
                Items = new[] { project }
            };
            var controller = CreateController(searchCriteria, searchResult);

            controller.Request.Properties.Remove(ServiceConstants.SessionProperty);

            // Act
            HttpResponseException httpResponseException = null;

            try
            {
                await controller.SearchName(searchCriteria, 1000);
            }
            catch (HttpResponseException e)
            {
                httpResponseException = e;
            }

            // Assert
            Assert.IsNotNull(httpResponseException, "Bad Request Exception should have been thrown");
            Assert.AreEqual(HttpStatusCode.Forbidden, httpResponseException.Response.StatusCode, "Forbidden should be provided as Status code");
        }
Exemple #4
0
        public async Task <ProjectSearchResult> SearchForContractAsync(
            string v_sCompanyName,
            string v_sProjectName,
            string v_sAuthID,
            string v_sToken)
        {
            m_wcfClient = new WcfExt116.ServiceClient();
            ProjectSearchResult result = new ProjectSearchResult();

            try
            {
                WcfExt116.ProjectSearchResult sResults = await m_wcfClient.SearchForContractAsync(
                    v_sCompanyName,
                    v_sProjectName,
                    v_sAuthID,
                    v_sToken);

                if (sResults.bSuccessfull == true)
                {
                    result.bSuccessfull  = sResults.bSuccessfull;
                    result.SearchResults = new ObservableCollection <SearchResult>();
                    foreach (WcfExt116.SearchResult o in sResults.SearchResults)
                    {
                        SearchResult oSR = new SearchResult();
                        oSR.ProjectName = o.ProjectName;
                        oSR.ProjectNo   = o.ProjectNo;
                        oSR.Status      = o.Status;
                        result.SearchResults.Add(oSR);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public async Task SearchName_RepoThrowsException_LogShouldBeCalled()
        {
            // Arrange
            const int projectId      = 10;
            var       searchCriteria = new SearchCriteria {
                Query = "Test"
            };
            var project = new ProjectSearchResult {
                ItemId = projectId, Name = searchCriteria.Query
            };
            var searchResult = new ProjectSearchResultSet {
                Items = new[] { project }
            };
            var logMock = new Mock <IServiceLogRepository>();

            logMock.Setup(t => t.LogError(It.IsAny <string>(), It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(Task.Delay(1));
            var exceptionToBeThrown = new Exception("MyException");

            var       controller      = CreateControllerForExceptionCases(searchCriteria, logMock, exceptionToBeThrown, searchResult);
            Exception actualException = null;

            // Act
            try
            {
                var result = await controller.SearchName(searchCriteria, 20);
            }
            catch (Exception ex)
            {
                actualException = ex;
            }

            // Assert
            Assert.IsNotNull(actualException);
            Assert.AreEqual(exceptionToBeThrown.Message, actualException.Message, "Incorrect message was thrown");
            logMock.Verify(t => t.LogError(It.IsAny <string>(), It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()), Times.Exactly(1));
        }