예제 #1
0
        public async Task DashboardInfoControllerTest_GetDashBoardInfoSearch_GetAnException()
        {
            // Arrange
            MockDashboardInfoRepository repository = new MockDashboardInfoRepository();
            var expectedResult = repository.GetMockTerminalData();
            IDashboardInfoRepository mockRepo = FakeRepository();
            IDistributedCache        _cache   = FakeCache();

            IDistributedCache mockCache = Substitute.For <IDistributedCache>();
            IStringLocalizer <DashboardInfoController> localizer
                = Substitute.For <IStringLocalizer <DashboardInfoController> >();
            string key             = "GetDashboardInfoErrorMessage";
            string value           = "Test Localized String";
            var    localizedString = new LocalizedString(key, value);

            localizer[Arg.Any <string>()].ReturnsForAnyArgs(localizedString);
            IOperation          fakeOperation = FakeOperation(_cache);
            IOptions <Settings> appSettings   = Substitute.For <IOptions <Settings> >();
            ILoggingFacade      fakeLogger    = FakeLogger();
            IDashboardInfoApi   dAPI          = new DashboardInfoApi(appSettings, mockRepo);

            dAPI.GetDashboardSearchResultsPagination(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, 0).Throws(new Exception());
            DashboardInfoController controller = FakeController(dAPI, mockRepo, _cache, fakeOperation, fakeLogger);


            // Act
            var dinfo = await controller.GetDashBoardInfoSearch(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.TerminalNbr, "0");

            var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo);

            // Assert
            Assert.Equal(actualRecord.StatusCode, 500);
            Assert.Equal(actualRecord.Value, "Test Localized String");
        }
예제 #2
0
        public async Task DashboardInfoControllerTerminalDetailsTest_GetAnException()
        {
            // Arrange
            MockDashboardInfoRepository repository = new MockDashboardInfoRepository();
            var expectedResult = repository.GetMockTerminalDetails();
            IDashboardInfoRepository mockRepo = FakeRepository();
            IDistributedCache        _cache   = FakeCache();

            IDistributedCache mockCache = Substitute.For <IDistributedCache>();
            IStringLocalizer <DashboardInfoController> localizer
                = Substitute.For <IStringLocalizer <DashboardInfoController> >();
            string key             = "GenericError";
            string value           = "Error occured";
            var    localizedString = new LocalizedString(key, value);

            localizer[Arg.Any <string>()].ReturnsForAnyArgs(localizedString);
            IOperation          fakeOperation = FakeOperation(_cache);
            IOptions <Settings> appSettings   = Substitute.For <IOptions <Settings> >();
            ILoggingFacade      fakeLogger    = FakeLogger();
            IDashboardInfoApi   dAPI          = new DashboardInfoApi(appSettings, mockRepo);

            dAPI.GetTerminalDetails(0).ThrowsForAnyArgs(new System.Exception());
            DashboardInfoController controller = FakeController(dAPI, mockRepo, _cache, fakeOperation, fakeLogger);


            // Act
            var dinfo = await controller.GetTerminalDetails(0);

            var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)dinfo);

            // Assert
            Assert.Equal(actualRecord.StatusCode, 500);
            Assert.Equal(actualRecord.Value, "Error occured");
        }
예제 #3
0
        public void DashboardInfoApiTest_CustomerSuccess()
        {
            // Arrange
            int lid = 589547;
            MockDashboardInfoRepository repository = new MockDashboardInfoRepository();

            IDashboardInfoRepository mockRepo = Substitute.For <IDashboardInfoRepository>();
            IDashboardInfoApi        api      = Substitute.For <IDashboardInfoApi>();


            var appSettings = new Settings()
            {
                MaxNumberOfRecordsToReturn = maxRecordsToReturn
            };
            IOptions <Settings> options = Options.Create(appSettings);

            var expectedResult = repository.GetMockCustomerData().Result;

            mockRepo.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.CustomerNbr, lid, maxRecordsToReturn).ReturnsForAnyArgs(expectedResult);

            api = new DashboardInfoApi(options, mockRepo);

            // Act
            var actualRecord = (api.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.CustomerNbr, lid).Result).Result;

            // Assert
            Assert.Equal((actualRecord), expectedResult);
            Assert.Equal((actualRecord).MerchInfo, null);
            Assert.Equal((actualRecord).CustProfile.customerID, 393727);
            Assert.Equal((actualRecord).TermInfo, null);
        }
예제 #4
0
        public async Task DashboardInfoApiTest_TerminalDetailsException()
        {
            // Arrange
            int CustomerID = 191809;

            // IOptions<Settings> optionsAccessor = Options.Create(appSettings);
            IOptions <Settings>      optionsAccessor  = Substitute.For <IOptions <Settings> >();
            IDashboardInfoRepository mockRepo         = Substitute.For <IDashboardInfoRepository>();
            IDashboardInfoApi        dashboardInfoApi = Substitute.For <IDashboardInfoApi>();

            mockRepo.GetTerminalDetails(CustomerID).ThrowsForAnyArgs(new Exception());
            dashboardInfoApi = new DashboardInfoApi(optionsAccessor, mockRepo);


            // Assert

            await Assert.ThrowsAsync <Exception>(() => dashboardInfoApi.GetTerminalDetails(CustomerID));
        }
예제 #5
0
        public async Task DashboardInfoApiTest_Exception()
        {
            // Arrange
            int CustomerID = 191809;

            var appSettings = new Settings()
            {
                MaxNumberOfRecordsToReturn = maxRecordsToReturn
            };
            IOptions <Settings>      optionsAccessor  = Options.Create(appSettings);
            IDashboardInfoRepository mockRepo         = Substitute.For <IDashboardInfoRepository>();
            IDashboardInfoApi        dashboardInfoApi = Substitute.For <IDashboardInfoApi>();

            mockRepo.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.CustomerID, CustomerID, maxRecordsToReturn).ThrowsForAnyArgs(new Exception());
            dashboardInfoApi = new DashboardInfoApi(optionsAccessor, mockRepo);


            // Assert
            await Assert.ThrowsAsync <Exception>(() => dashboardInfoApi.GetDashboardSearchResults(Wp.CIS.LynkSystems.Model.Helper.LIDTypes.CustomerID, CustomerID));
        }
예제 #6
0
        public void DashboardInfoApiTest_TerminalDetailsSuccess()
        {
            // Arrange
            int lid = 589547;
            MockDashboardInfoRepository repository = new MockDashboardInfoRepository();

            IDashboardInfoRepository mockRepo    = Substitute.For <IDashboardInfoRepository>();
            IDashboardInfoApi        api         = Substitute.For <IDashboardInfoApi>();
            IOptions <Settings>      appSettings = Substitute.For <IOptions <Settings> >();

            var expectedResult = repository.GetMockTerminalDetails().Result;

            mockRepo.GetTerminalDetails(lid).ReturnsForAnyArgs(expectedResult);
            api = new DashboardInfoApi(appSettings, mockRepo);

            // Act
            var actualRecord = (api.GetTerminalDetails(lid).Result).Result;

            // Assert
            Assert.Equal((actualRecord), expectedResult);
        }