コード例 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         User us = (User)Session["user"];
         if (Session["user"] != null)
         {
             GridTransactionHistory.Columns[0].Visible = false;
             if (us.RoleID == 1)
             {
                 // admin do something
                 GridTransactionHistory.Columns[0].Visible = true;
                 GridTransactionHistory.DataSource         = TransactionHistoryController.getAllTransactionHistory();
                 GridTransactionHistory.DataBind();
             }
             else
             {
                 int userID = us.UserID;
                 GridTransactionHistory.DataSource = TransactionHistoryController.getTransactionHistory(userID);
                 GridTransactionHistory.DataBind();
             }
         }
         else
         {
             Response.Redirect("home.aspx");
         }
     }
 }
コード例 #2
0
        public async void Patch_No_Errors()
        {
            TransactionHistoryControllerMockFacade mock = new TransactionHistoryControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiTransactionHistoryResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(true);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiTransactionHistoryRequestModel>()))
            .Callback <int, ApiTransactionHistoryRequestModel>(
                (id, model) => model.ActualCost.Should().Be(1m)
                )
            .Returns(Task.FromResult <UpdateResponse <ApiTransactionHistoryResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiTransactionHistoryResponseModel>(new ApiTransactionHistoryResponseModel()));
            TransactionHistoryController controller = new TransactionHistoryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiTransactionHistoryModelMapper());

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var patch = new JsonPatchDocument <ApiTransactionHistoryRequestModel>();

            patch.Replace(x => x.ActualCost, 1m);

            IActionResult response = await controller.Patch(default(int), patch);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            mock.ServiceMock.Verify(x => x.Update(It.IsAny <int>(), It.IsAny <ApiTransactionHistoryRequestModel>()));
        }
コード例 #3
0
        private void load_data()
        {
            List <vTransaction> transactionData = TransactionHistoryController.getTransactionData();

            transactionGrid.DataSource = transactionData;
            transactionGrid.DataBind();
        }
コード例 #4
0
        public async void BulkInsert_No_Errors()
        {
            TransactionHistoryControllerMockFacade mock = new TransactionHistoryControllerMockFacade();

            var mockResponse = new CreateResponse <ApiTransactionHistoryResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiTransactionHistoryResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiTransactionHistoryRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiTransactionHistoryResponseModel> >(mockResponse));
            TransactionHistoryController controller = new TransactionHistoryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var records = new List <ApiTransactionHistoryRequestModel>();

            records.Add(new ApiTransactionHistoryRequestModel());
            IActionResult response = await controller.BulkInsert(records);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var result = (response as OkObjectResult).Value as List <ApiTransactionHistoryResponseModel>;

            result.Should().NotBeEmpty();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTransactionHistoryRequestModel>()));
        }
コード例 #5
0
        public async Task TransactionHistoryControllerTest_NoDataFound()
        {
            // Arrange
            string terminalId      = "LK429486";
            string transactionType = "Credit";


            MockTransactionHistoryRepository mockTransactionHistoryRepository          = new MockTransactionHistoryRepository();
            ApiResult <GenericPaginationResponse <TransactionHistory> > expectedResult = mockTransactionHistoryRepository.GetMockData(transactionType);
            PaginationTransactionHistory page = mockTransactionHistoryRepository.GetPagination();

            TransactionHistoryInput pageinput = new TransactionHistoryInput();

            pageinput.LIDValue    = terminalId;
            pageinput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Customer;
            pageinput.Page        = page;

            IDistributedCache   mockCache     = Substitute.For <IDistributedCache>();
            IOptions <Settings> appSettings   = Substitute.For <IOptions <Settings> >();
            IOperation          fakeOperation = Substitute.For <Operation>(mockCache);
            ILoggingFacade      loggingFacade = Substitute.For <ILoggingFacade>();

            IStringLocalizer <TransactionHistoryController> localizer = Substitute.For <IStringLocalizer <TransactionHistoryController> >();
            string key             = "NoDataFound";
            string value           = "No data found for provided ID";
            var    localizedString = new LocalizedString(key, value);

            localizer[Arg.Any <string>()].ReturnsForAnyArgs(localizedString);

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

            ITransactionHistoryApi terminalListApi = Substitute.For <ITransactionHistoryApi>();


            ApiResult <GenericPaginationResponse <TransactionHistory> > response = new ApiResult <GenericPaginationResponse <TransactionHistory> >();

            response.Result = new GenericPaginationResponse <TransactionHistory>();

            terminalListApi.GetTransactionHistoryAsync(terminalId, page).ReturnsForAnyArgs(response);
            TransactionHistoryController fakecontroller
                = FakeController(mockCache, terminalListApi, localizer, fakeOperation, loggingFacade);


            // Act
            var terminalList = await fakecontroller.GetTransactionHistory(pageinput);

            // Assert

            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).StatusCode, 200);
            var actualTransactionHistory = ((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).Value;

            Assert.Equal(((GenericPaginationResponse <TransactionHistory>)actualTransactionHistory).ModelMessage, localizer["NoDataFound"].Value);
        }
コード例 #6
0
        public async Task TransactionHistoryControllerTest_Success()
        {
            // Arrange

            string terminalId      = "LK429486";
            string transactionType = "Credit";


            MockTransactionHistoryRepository mockTransactionHistoryRepository = new MockTransactionHistoryRepository();
            ApiResult <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.TransactionHistory> > expectedResult = mockTransactionHistoryRepository.GetMockData(transactionType);
            PaginationTransactionHistory page = mockTransactionHistoryRepository.GetPagination();

            TransactionHistoryInput pageinput = new TransactionHistoryInput();

            pageinput.LIDValue    = terminalId;
            pageinput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Customer;
            pageinput.Page        = page;

            IDistributedCache   mockCache   = Substitute.For <IDistributedCache>();
            IOptions <Settings> appSettings = Substitute.For <IOptions <Settings> >();
            IStringLocalizer <TransactionHistoryController> localizer
                = Substitute.For <IStringLocalizer <TransactionHistoryController> >();

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

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

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <ICollection <Wp.CIS.LynkSystems.Model.TransactionHistory> >())).DoNotCallBase();
            fakeOperation.WhenForAnyArgs(x => x.AddCacheAsync(Arg.Any <string>(), Arg.Any <ICollection <Wp.CIS.LynkSystems.Model.TransactionHistory> >())).DoNotCallBase();
            ITransactionHistoryApi terminalListApi = Substitute.For <ITransactionHistoryApi>();

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

            TransactionHistoryController controller
                = new TransactionHistoryController(mockCache, terminalListApi, localizer, fakeOperation, loggingFacade);

            terminalListApi.GetTransactionHistoryAsync(terminalId, page).ReturnsForAnyArgs(expectedResult);
            // Act
            var terminalList = await controller.GetTransactionHistory(pageinput);

            var    actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).Value;
            string terminalInfo = ((IList <TransactionHistory>)((GenericPaginationResponse <TransactionHistory>)actualRecord).ReturnedRecords)
                                  .Where(x => x.REQ_TRAN_TYPE == transactionType).FirstOrDefault().REQ_AMT;


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

            Assert.Equal(recordCount.ToList().Count, 1);
            //Assert.Equal(((IList<Wp.CIS.LynkSystems.Model.TransactionHistory>)actualRecord).Count, 1);

            Assert.Equal(terminalInfo, "589587");
        }
コード例 #7
0
        public async void Get_Not_Exists()
        {
            TransactionHistoryControllerMockFacade mock = new TransactionHistoryControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiTransactionHistoryResponseModel>(null));
            TransactionHistoryController controller = new TransactionHistoryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
コード例 #8
0
        public async void Delete_Errors()
        {
            TransactionHistoryControllerMockFacade mock = new TransactionHistoryControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object));
            TransactionHistoryController controller = new TransactionHistoryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Delete(default(int));

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>()));
        }
コード例 #9
0
        public async void All_Not_Exists()
        {
            TransactionHistoryControllerMockFacade mock = new TransactionHistoryControllerMockFacade();

            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <ApiTransactionHistoryResponseModel> >(new List <ApiTransactionHistoryResponseModel>()));
            TransactionHistoryController controller = new TransactionHistoryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiTransactionHistoryResponseModel>;

            items.Should().BeEmpty();
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
コード例 #10
0
        public async void Update_NotFound()
        {
            TransactionHistoryControllerMockFacade mock = new TransactionHistoryControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiTransactionHistoryResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiTransactionHistoryRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiTransactionHistoryResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiTransactionHistoryResponseModel>(null));
            TransactionHistoryController controller = new TransactionHistoryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiTransactionHistoryModelMapper());

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Update(default(int), new ApiTransactionHistoryRequestModel());

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
コード例 #11
0
        ///Unit Test for the RetrieveCache()
        public async Task TransactionHistoryControllerTest_GetDataFromCache()
        {
            string terminalId      = "LK429486";
            string transactionType = "Credit";

            MockTransactionHistoryRepository mockTransactionHistoryRepository = new MockTransactionHistoryRepository();

            ApiResult <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.TransactionHistory> > expectedResult = mockTransactionHistoryRepository.GetMockData(transactionType);
            PaginationTransactionHistory page = mockTransactionHistoryRepository.GetPagination();

            TransactionHistoryInput pageinput = new TransactionHistoryInput();

            pageinput.LIDValue    = terminalId;
            pageinput.lidTypeEnum = Wp.CIS.LynkSystems.Model.Enums.LidTypeEnum.Customer;
            pageinput.Page        = page;

            IDistributedCache             mockCache = Substitute.For <IDistributedCache>();
            ITransactionHistoryRepository mockRepo  = Substitute.For <ITransactionHistoryRepository>();
            IStringLocalizer <TransactionHistoryController> localizer
                = Substitute.For <IStringLocalizer <TransactionHistoryController> >();
            ITransactionHistoryApi mockTransactionHistoryApi = Substitute.For <ITransactionHistoryApi>();
            ILoggingFacade         loggingFacade             = Substitute.For <ILoggingFacade>();

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

            fakeOperation.WhenForAnyArgs(x => x.RetrieveCache(Arg.Any <string>(), Arg.Any <ICollection <Wp.CIS.LynkSystems.Model.TransactionHistory> >())).DoNotCallBase();

            fakeOperation.RetrieveCache("FakeStringID", new GenericPaginationResponse <Wp.CIS.LynkSystems.Model.TransactionHistory>()).ReturnsForAnyArgs(expectedResult.Result);

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

            TransactionHistoryController controller = new TransactionHistoryController(mockCache, mockTransactionHistoryApi, localizer, fakeOperation, loggingFacade);


            //ACT
            var terminalList = await controller.GetTransactionHistory(pageinput);

            var actualRecord = ((Microsoft.AspNetCore.Mvc.ObjectResult)terminalList).Value;

            //Assert
            Assert.Equal(JsonConvert.SerializeObject(actualRecord), JsonConvert.SerializeObject(expectedResult.Result));
        }
コード例 #12
0
        public async void Patch_Record_Not_Found()
        {
            TransactionHistoryControllerMockFacade mock = new TransactionHistoryControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiTransactionHistoryResponseModel>(null));
            TransactionHistoryController controller = new TransactionHistoryController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var patch = new JsonPatchDocument <ApiTransactionHistoryRequestModel>();

            patch.Replace(x => x.ActualCost, 1m);

            IActionResult response = await controller.Patch(default(int), patch);

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
コード例 #13
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!TransactionHistoryController.isUserLoggedIn())
     {
         userWarnLbl.Text  = "You're not logged in. Please login to see this page";
         loginBtn.Visible  = true;
         logoutBtn.Visible = false;
     }
     else
     {
         if (!TransactionHistoryController.isUserAnAdmin())
         {
             int userId = TransactionHistoryController.getUserID();
             load_data(userId);
         }
         else
         {
             load_data();
             transactionReportBtn.Visible = true;
         }
     }
 }
コード例 #14
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["user"] != null)
     {
         int userId = Convert.ToInt32(Session["user"]);
         if (UserController.isAdmin(userId) == false)
         {
             viewTransactionHistory.DataSource = TransactionHistoryController.getAllTransactionHistoryById(userId);
             viewTransactionHistory.DataBind();
             viewTransactionReport.Visible = false;
         }
         else
         {
             viewTransactionHistory.DataSource = TransactionHistoryController.getAllTransactionHistory();
             viewTransactionHistory.DataBind();
         }
     }
     else
     {
         Response.Redirect("/View/Home.aspx");
     }
 }
コード例 #15
0
        //UnitTest for validating the Invalid Model Data.
        public void TransactionHistoryController_ModelState_Invalid()
        {
            //Arrange
            string terminalId      = "LK429486";
            string transactionType = "Credit";


            MockTransactionHistoryRepository mockTransactionHistoryRepository = new MockTransactionHistoryRepository();
            ApiResult <GenericPaginationResponse <Wp.CIS.LynkSystems.Model.TransactionHistory> > expectedResult = mockTransactionHistoryRepository.GetMockData(transactionType);
            PaginationTransactionHistory page = mockTransactionHistoryRepository.GetPagination();

            TransactionHistoryInput pageinput = new TransactionHistoryInput();

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

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

            IStringLocalizer <TransactionHistoryController> localizer
                = Substitute.For <IStringLocalizer <TransactionHistoryController> >();
            ILoggingFacade loggingFacade = Substitute.For <ILoggingFacade>();

            IDistributedCache      mockCache       = FakeCache();
            ITransactionHistoryApi terminalListApi = Substitute.For <ITransactionHistoryApi>();
            IOperation             fakeOperation   = Substitute.For <Operation>(mockCache);

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

            TransactionHistoryController controller = new TransactionHistoryController(mockCache, terminalListApi, localizer, fakeOperation, loggingFacade);

            //Act
            controller.ModelState.AddModelError("key", "error message");
            var result = controller.GetTransactionHistory(pageinput);

            //Assert
            Assert.Equal(((Microsoft.AspNetCore.Mvc.ObjectResult)result.Result).StatusCode.ToString(), "400");
        }
コード例 #16
0
 public TransactionControl()
 {
     InitializeComponent();
     m_newTransactionController     = new NewTransactionController(this);
     m_transactionHistoryController = new TransactionHistoryController(this);
 }