Пример #1
0
        public void Should_Success_Get_Unit_Payment_Order()
        {
            var mockFacade = new Mock <IPPHBankExpenditureNoteFacade>();

            mockFacade.Setup(x => x.GetUnitPaymentOrder(null, null, "IncomeTaxName", 2, "IDR"))
            .Returns(
                new List <object>()
            {
                new { Id              = 1,
                      No              = "UPONO",
                      UPODate         = DateTime.UtcNow,
                      DueDate         = DateTime.UtcNow,
                      InvoiceNo       = "InvoiceNo",
                      SupplierCode    = "SupplierCode",
                      SupplierName    = "SupplierName",
                      CategoryCode    = "CategoryCode",
                      CategoryName    = "CategoryName",
                      DivisionCode    = "DivisionCode",
                      DivisionName    = "DivisionName",
                      IncomeTax       = 2000,
                      Vat             = 1000,
                      TotalPaid       = 20000,
                      Currency        = "IDR",
                      LastModifiedUtc = DateTime.UtcNow }
            });

            PPHBankExpenditureNoteController controller = new PPHBankExpenditureNoteController(GetServiceProvider().Object, mockFacade.Object);
            var response = controller.GetUPO(null, null, "IncomeTaxName", 2, "IDR");

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
Пример #2
0
        private PPHBankExpenditureNoteController GetController(Mock <IPPHBankExpenditureNoteFacade> facadeM, Mock <IValidateService> validateM)
        {
            var user   = new Mock <ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

            user.Setup(u => u.Claims).Returns(claims);

            var servicePMock = GetServiceProvider();

            servicePMock
            .Setup(x => x.GetService(typeof(IValidateService)))
            .Returns(validateM.Object);

            PPHBankExpenditureNoteController controller = new PPHBankExpenditureNoteController(servicePMock.Object, facadeM.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user.Object
                }
            };
            controller.ControllerContext.HttpContext.Request.Headers["Authorization"] = "Bearer unittesttoken";
            controller.ControllerContext.HttpContext.Request.Path = new PathString("/v1/unit-test");

            return(controller);
        }
        public async Task Should_Error_Get_Data_By_Id()
        {
            var mockFacade = new Mock <IPPHBankExpenditureNoteFacade>();

            mockFacade.Setup(x => x.ReadById(It.IsAny <int>()))
            .Throws(new Exception());

            PPHBankExpenditureNoteController controller = new PPHBankExpenditureNoteController(GetServiceProvider().Object, mockFacade.Object);
            var response = await controller.GetById(It.IsAny <int>());

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
        public void Should_Success_Get_All_Data()
        {
            var mockFacade = new Mock <IPPHBankExpenditureNoteFacade>();

            mockFacade.Setup(x => x.Read(1, 25, "{}", null, "{}"))
            .Returns(new ReadResponse <object>(new List <object>(), 1, new Dictionary <string, string>()));

            PPHBankExpenditureNoteController controller = new PPHBankExpenditureNoteController(GetServiceProvider().Object, mockFacade.Object);
            var response = controller.Get(1, 25, "{}", null, "{}");

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
Пример #5
0
        public async Task Should_NoContent_PostingData()
        {
            var mockFacade = new Mock <IPPHBankExpenditureNoteFacade>();

            mockFacade.Setup(x => x.Posting(It.IsAny <List <long> >()))
            .ReturnsAsync(1);

            PPHBankExpenditureNoteController controller = GetController(mockFacade, new Mock <IValidateService>());

            var response = await controller.Posting(It.IsAny <List <long> >());

            Assert.Equal((int)HttpStatusCode.NoContent, GetStatusCode(response));
        }
        public async Task Should_Not_Found_Get_Data_By_Id()
        {
            var mockFacade = new Mock <IPPHBankExpenditureNoteFacade>();

            mockFacade.Setup(x => x.ReadById(It.IsAny <int>()))
            .ReturnsAsync((PPHBankExpenditureNote)null);

            PPHBankExpenditureNoteController controller = new PPHBankExpenditureNoteController(GetServiceProvider().Object, mockFacade.Object);

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

            controller.ControllerContext.HttpContext.Request.Headers["Accept"] = "test";

            var response = await controller.GetById(It.IsAny <int>());

            Assert.Equal((int)HttpStatusCode.NotFound, GetStatusCode(response));
        }
        public void Should_Success_Get_Data_By_Id()
        {
            var mockFacade = new Mock <IPPHBankExpenditureNoteFacade>();

            mockFacade.Setup(x => x.ReadById(It.IsAny <int>()))
            .ReturnsAsync(this.Model);

            PPHBankExpenditureNoteController controller = new PPHBankExpenditureNoteController(GetServiceProvider().Object, mockFacade.Object);

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

            controller.ControllerContext.HttpContext.Request.Headers["Accept"] = "test";

            var response = controller.GetById(It.IsAny <int>()).Result;

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
        public async Task Should_Success_Get_PDF_By_Id()
        {
            var mockFacade = new Mock <IPPHBankExpenditureNoteFacade>();

            mockFacade.Setup(x => x.ReadById(It.IsAny <int>()))
            .ReturnsAsync(this.Model);

            PPHBankExpenditureNoteController controller = new PPHBankExpenditureNoteController(GetServiceProvider().Object, mockFacade.Object);

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

            controller.ControllerContext.HttpContext.Request.Headers["Accept"]            = "application/pdf";
            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "0";

            var response = await controller.GetById(It.IsAny <int>());

            Assert.NotNull(response.GetType().GetProperty("FileStream"));
        }