示例#1
0
        public async Task MerchantListApiTest_Exception()
        {
            // Arrange
            int CustomerID = 191809;

            MockMerchantListRepository mockMerchantListRepository            = new MockMerchantListRepository();
            ApiResult <GenericPaginationResponse <Merchant> > expectedResult = mockMerchantListRepository.GetMockData(CustomerID);
            PaginationMerchant page = mockMerchantListRepository.GetPagination();

            IOptions <Settings>     optionsAccessor = Substitute.For <IOptions <Settings> >();
            IMerchantListRepository mockRepo        = Substitute.For <IMerchantListRepository>();
            IMerchantListApi        merchantListApi = Substitute.For <IMerchantListApi>();
            IDistributedCache       mockCache       = Substitute.For <IDistributedCache>();
            ILoggingFacade          loggingFacade   = Substitute.For <ILoggingFacade>();

            loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase();

            mockRepo.GetMerchantListAsync(CustomerID, page).Throws(new Exception());


            merchantListApi = new MerchantListApi(optionsAccessor, mockRepo, loggingFacade);


            //Assert
            await Assert.ThrowsAsync <Exception>(() => merchantListApi.GetMerchantListAsync(CustomerID, page));
        }
示例#2
0
        public void MerchantListApiTest_Success()
        {
            // Arrange
            int    CustomerID = 191809;
            string mid        = "191807";


            MockMerchantListRepository mockMerchantListRepository            = new MockMerchantListRepository();
            ApiResult <GenericPaginationResponse <Merchant> > expectedResult = mockMerchantListRepository.GetMockData(CustomerID);
            PaginationMerchant page = mockMerchantListRepository.GetPagination();

            IOptions <Settings> optionsAccessor = Substitute.For <IOptions <Settings> >();

            IMerchantListRepository mockRepo = Substitute.For <IMerchantListRepository>();

            IMerchantListApi merchantListApi = Substitute.For <IMerchantListApi>();

            ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>();

            loggingFacade.WhenForAnyArgs(x => x.LogAsync(Arg.Any <LogLevels>(), Arg.Any <string>(), Arg.Any <CancellationToken>())).DoNotCallBase();

            mockRepo.GetMerchantListAsync(CustomerID, page).ReturnsForAnyArgs(expectedResult.Result);

            merchantListApi = new MerchantListApi(optionsAccessor, mockRepo, loggingFacade);

            // Act
            var    merchList    = merchantListApi.GetMerchantListAsync(CustomerID, page).Result;
            var    actualRecord = (IList <Wp.CIS.LynkSystems.Model.Merchant>)merchList.Result.ReturnedRecords;
            string merchInfo    = actualRecord.Where(x => x.MID == mid).FirstOrDefault().Name;


            //// Assert

            Assert.Equal(((IList <Merchant>)actualRecord).Count, 2);

            Assert.Equal(merchInfo, "ABC Corp");
        }