public async Task Test_GetPostcodes_PositiveScenario()
        {
            // Setup for PostcodeHierarchy with mocked AsNoTracking()
            var mockAsynEnumerable4   = new DbAsyncEnumerable <PostcodeHierarchy>(postcodeHierarchyList);
            var mockPostcodeHierarchy = MockDbSet(postcodeHierarchyList);

            mockPostcodeHierarchy.As <IQueryable>().Setup(mock => mock.Provider).Returns(mockAsynEnumerable4.AsQueryable().Provider);
            mockPostcodeHierarchy.As <IQueryable>().Setup(mock => mock.Expression).Returns(mockAsynEnumerable4.AsQueryable().Expression);
            mockPostcodeHierarchy.As <IQueryable>().Setup(mock => mock.ElementType).Returns(mockAsynEnumerable4.AsQueryable().ElementType);
            mockPostcodeHierarchy.As <IDbAsyncEnumerable>().Setup(mock => mock.GetAsyncEnumerator()).Returns(((IDbAsyncEnumerable <PostcodeHierarchy>)mockAsynEnumerable4).GetAsyncEnumerator());
            mockUnitManagerDbContext.Setup(x => x.Set <PostcodeHierarchy>()).Returns(mockPostcodeHierarchy.Object);
            mockUnitManagerDbContext.Setup(x => x.PostcodeHierarchies).Returns(mockPostcodeHierarchy.Object);
            mockUnitManagerDbContext.Setup(c => c.PostcodeHierarchies.AsNoTracking()).Returns(mockPostcodeHierarchy.Object);

            var result = await testCandidate.GetPostcodes(new List <Guid>() { new Guid("1534AA41-391F-4579-A18D-D7EDF5B5F918") }, postcodeTypeGUID);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.ToList().Count, 1);
            Assert.AreEqual(result.ToList()[0].ID, new Guid("1534AA41-391F-4579-A18D-D7EDF5B5F918"));
        }
Exemple #2
0
        /// <summary>
        /// Gets postcode details by postcode guids
        /// </summary>
        /// <param name="postcodeGuids"></param>
        /// <returns>List</returns>
        public async Task <IEnumerable <PostcodeDTO> > GetPostcodes(List <Guid> postcodeGuids)
        {
            string methodName = typeof(UnitLocationBusinessService) + "." + nameof(GetPostcodes);

            using (loggingHelper.RMTraceManager.StartTrace("Business.GetPostcodes"))
            {
                loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.UnitManagerAPIPriority, LoggerTraceConstants.UnitManagerBusinessServiceMethodEntryEventId);

                // reference data value for Postcode with Category - Postcode Type
                Guid postcodeTypeGUID = unitManagerIntegrationService.GetReferenceDataGuId(PostCodeType, PostCodeTypeCategory.PostcodeSector.GetDescription()).Result;

                var postcodeDataDto = await unitLocationDataService.GetPostcodes(postcodeGuids, postcodeTypeGUID);

                var postCodeDto = GenericMapper.MapList <PostcodeDataDTO, PostcodeDTO>(postcodeDataDto.ToList());

                loggingHelper.LogMethodEntry(methodName, LoggerTraceConstants.UnitManagerAPIPriority, LoggerTraceConstants.UnitManagerBusinessServiceMethodExitEventId);
                return(postCodeDto);
            }
        }