private GarmentReturnCorrectionNoteController GetController(Mock <IGarmentReturnCorrectionNoteFacade> facadeM, Mock <IValidateService> validateM, Mock <IMapper> mapper, Mock <IGarmentDeliveryOrderFacade> garmentDeliveryOrderFacadeM = null, Mock <IGarmentInternalPurchaseOrderFacade> garmentInternalPurchaseOrderFacadeM = null, Mock <IGarmentInvoice> garmentInvoiceMock = null)
        {
            var user   = new Mock <ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

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

            var servicePMock = GetServiceProvider();

            if (validateM != null)
            {
                servicePMock
                .Setup(x => x.GetService(typeof(IValidateService)))
                .Returns(validateM.Object);
            }

            if (garmentDeliveryOrderFacadeM != null)
            {
                servicePMock
                .Setup(x => x.GetService(typeof(IGarmentDeliveryOrderFacade)))
                .Returns(garmentDeliveryOrderFacadeM.Object);
            }

            if (garmentInternalPurchaseOrderFacadeM != null)
            {
                servicePMock
                .Setup(x => x.GetService(typeof(IGarmentInternalPurchaseOrderFacade)))
                .Returns(garmentInternalPurchaseOrderFacadeM.Object);
            }

            if (garmentInvoiceMock != null)
            {
                servicePMock
                .Setup(x => x.GetService(typeof(IGarmentInvoice)))
                .Returns(garmentInvoiceMock.Object);
            }

            var controller = new GarmentReturnCorrectionNoteController(servicePMock.Object, mapper.Object, facadeM.Object)
            {
                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");
            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "7";

            return(controller);
        }
        public void Should_Error_Get_All_Data()
        {
            var mockFacade = new Mock <IGarmentReturnCorrectionNoteFacade>();
            var mockMapper = new Mock <IMapper>();
            GarmentReturnCorrectionNoteController controller = new GarmentReturnCorrectionNoteController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);
            var response = controller.Get();

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
        public async Task Should_Error_Create_Data()
        {
            var mockMapper = new Mock <IMapper>();
            var mockFacade = new Mock <IGarmentReturnCorrectionNoteFacade>();

            var controller = new GarmentReturnCorrectionNoteController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);

            var response = await controller.Post(new GarmentCorrectionNoteViewModel());

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
        private void Get_Ppn_PDF_By_Id_NullInvoice(string correctionType)
        {
            var Model = this.Model;

            Model.CorrectionType = correctionType;

            var ViewModel = this.ViewModel;

            ViewModel.UseVat = true;

            var mockFacade = new Mock <IGarmentReturnCorrectionNoteFacade>();

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

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <GarmentCorrectionNoteViewModel>(It.IsAny <GarmentCorrectionNote>()))
            .Returns(ViewModel);

            var garmentdeliveryOrder = new GarmentDeliveryOrder
            {
                DOCurrencyRate = 1,
                Items          = new List <GarmentDeliveryOrderItem>
                {
                    new GarmentDeliveryOrderItem
                    {
                        Details = Model.Items.Select(i => new GarmentDeliveryOrderDetail
                        {
                            Id = i.DODetailId
                        }).ToList()
                    }
                }
            };

            var mockGarmentDeliveryOrderFacade = new Mock <IGarmentDeliveryOrderFacade>();

            mockGarmentDeliveryOrderFacade.Setup(x => x.ReadById(It.IsAny <int>()))
            .Returns(garmentdeliveryOrder);

            var mockGarmentInvoiceFacade = new Mock <IGarmentInvoice>();

            mockGarmentInvoiceFacade.Setup(x => x.ReadByDOId(1))
            .Returns(new GarmentInvoice());

            GarmentReturnCorrectionNoteController controller = GetController(mockFacade, null, mockMapper, mockGarmentDeliveryOrderFacade, null, mockGarmentInvoiceFacade);

            controller.ControllerContext.HttpContext.Request.Headers["Accept"] = "application/pdf";

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

            Assert.NotNull(response.GetType().GetProperty("FileStream"));
        }
        public void Should_Error_Get_Pph_Data_By_Id()
        {
            var mockFacade = new Mock <IGarmentReturnCorrectionNoteFacade>();

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

            var mockMapper = new Mock <IMapper>();

            GarmentReturnCorrectionNoteController controller = new GarmentReturnCorrectionNoteController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);
            var response = controller.GetReturnNotePph(It.IsAny <int>());

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

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

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <GarmentCorrectionNoteViewModel>(It.IsAny <GarmentCorrectionNote>()))
            .Returns(ViewModel);

            GarmentReturnCorrectionNoteController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.Get(It.IsAny <int>());

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

            mockFacade.Setup(x => x.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), null, It.IsAny <string>()))
            .Returns(Tuple.Create(new List <GarmentCorrectionNote>(), 0, new Dictionary <string, string>()));

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <List <GarmentCorrectionNoteViewModel> >(It.IsAny <List <GarmentCorrectionNote> >()))
            .Returns(new List <GarmentCorrectionNoteViewModel> {
                ViewModel
            });

            GarmentReturnCorrectionNoteController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.Get();

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
        public void Should_Error_Get_Pph_Data_Invalid_By_Id()
        {
            var ViewModel = this.ViewModel;

            ViewModel.UseIncomeTax = false;

            var mockFacade = new Mock <IGarmentReturnCorrectionNoteFacade>();

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

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <GarmentCorrectionNoteViewModel>(It.IsAny <GarmentCorrectionNote>()))
            .Returns(ViewModel);

            GarmentReturnCorrectionNoteController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.GetReturnNotePph(It.IsAny <int>());

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }