//Would be revisiting to modify the actual way of call method.
        public void MerchantListRepositoryTest_Success()
        {
            // Arrange
            int    CustomerID = 191809;
            string mid        = "191807";


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

            IOptions <DataContext>     optionsAccessor   = Substitute.For <IOptions <DataContext> >();
            IDatabaseConnectionFactory connectionFactory = Substitute.For <IDatabaseConnectionFactory>();
            IMerchantListRepository    mockRepo          = Substitute.For <IMerchantListRepository>();
            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);

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


            //// Assert

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

            Assert.Equal(merchInfo, "ABC Corp");
        }
Beispiel #2
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));
        }
Beispiel #3
0
 public MerchantListApi(IOptions <Settings> optionsAccessor, IMerchantListRepository merchantRepository,
                        ILoggingFacade loggingFacade)
 {
     _loggingFacade = loggingFacade;
     _loggingFacade.LogAsync(new LogEntry(LogLevels.Info, "Starting Merchant List API Service",
                                          "MerchantListApi.cs", "MerchantListApi"), CancellationToken.None);
     _merchantRepository = merchantRepository;
 }
Beispiel #4
0
        //Mock API Call and unit test for the API call with returning mock MerchantList.
        public async Task MerchantListControllerTest_Success()
        {
            // Arrange
            int    CustomerID = 191809;
            string mid        = "191807";

            IConfigurationRoot configurationRoot = Substitute.For <IConfigurationRoot>();

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

            pageinput.LIDValue    = CustomerID.ToString();
            pageinput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Customer;
            pageinput.Page        = page;

            IDistributedCache       mockCache = Substitute.For <IDistributedCache>();
            IMerchantListRepository mockRepo  = Substitute.For <IMerchantListRepository>();
            IStringLocalizer <MerchantListController> localizer
                = Substitute.For <IStringLocalizer <MerchantListController> >();
            IMerchantListApi mockMerchantListApi = Substitute.For <IMerchantListApi>();
            ILoggingFacade   loggingFacade       = Substitute.For <ILoggingFacade>();

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

            IOperation fakeOperation = Substitute.For <Operation>(mockCache);

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <GenericPaginationResponse <Merchant> >())).DoNotCallBase();
            fakeOperation.WhenForAnyArgs(x => x.AddCacheAsync(Arg.Any <string>(), Arg.Any <GenericPaginationResponse <Merchant> >())).DoNotCallBase();
            MerchantListController controller = new MerchantListController(mockCache, mockMerchantListApi, localizer, fakeOperation, loggingFacade);

            mockMerchantListApi.GetMerchantListAsync(CustomerID, page).ReturnsForAnyArgs(expectedResult);
            // Act
            var merchList = await controller.GetMerchantList(pageinput);

            var    actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)merchList).Value;
            string merchInfo    = ((IList <Merchant>)((GenericPaginationResponse <Merchant>)actualRecord).ReturnedRecords).Where(x => x.MID == mid).FirstOrDefault().Name;


            // Assert
            var recordCount = ((GenericPaginationResponse <Merchant>)actualRecord).ReturnedRecords;

            Assert.Equal(recordCount.ToList().Count, 2);


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