public void Should_Success_Get_Xls_Report_In()
        {
            var mockFacade = new Mock <IGarmentUnitReceiptNoteFacade>();

            mockFacade.Setup(x => x.GenerateExcelMonIN(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(new MemoryStream());

            var mockMapper = new Mock <IMapper>();


            var user   = new Mock <ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

            user.Setup(u => u.Claims).Returns(claims);
            GarmentUnitReceiptNoteController controller = new GarmentUnitReceiptNoteController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);

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

            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "0";
            var response = controller.GetXlsMonIn(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>());

            Assert.Equal("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", response.GetType().GetProperty("ContentType").GetValue(response, null));
        }
        public void Should_Error_Get_Xls_Report_In()
        {
            var mockFacade = new Mock <IGarmentUnitReceiptNoteFacade>();


            var mockMapper = new Mock <IMapper>();


            var user   = new Mock <ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

            user.Setup(u => u.Claims).Returns(claims);
            GarmentUnitReceiptNoteController controller = new GarmentUnitReceiptNoteController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user.Object
                }
            };
            //controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "0";
            var response = controller.GetXlsMonIn(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>());

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

            mockFacade.Setup(x => x.GetReportIN(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(Tuple.Create(new List <GarmentUnitReceiptNoteINReportViewModel>(), 25));

            var mockMapper = new Mock <IMapper>();


            var user   = new Mock <ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

            user.Setup(u => u.Claims).Returns(claims);
            GarmentUnitReceiptNoteController controller = new GarmentUnitReceiptNoteController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);

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

            var response = controller.GetMonitoringIN(null, null, null, 0, 0, null);

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
        public void Should_Error_Delete_Data()
        {
            var controller = new GarmentUnitReceiptNoteController(GetServiceProvider().Object, null, null);

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

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
        public async Task Should_Error_Delete_Data()
        {
            var controller = new GarmentUnitReceiptNoteController(GetServiceProvider().Object, null, null);

            var response = await controller.DeleteData(It.IsAny <int>(), It.IsAny <GarmentUnitReceiptNoteViewModel>());

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
        public void Should_Error_Get_All_Data()
        {
            var mockFacade = new Mock <IGarmentUnitReceiptNoteFacade>();
            var mockMapper = new Mock <IMapper>();
            GarmentUnitReceiptNoteController controller = new GarmentUnitReceiptNoteController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);
            var response = controller.Get();

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
        public void Should_Error_Revise_CreateDate()
        {
            var mockMapper = new Mock <IMapper>();
            var mockFacade = new Mock <IGarmentUnitReceiptNoteFacade>();

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

            var response = controller.UrnReviseDate(DateTime.Now, new List <GarmentUnitReceiptNoteViewModel>());

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

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

            var response = await controller.Put(It.IsAny <int>(), new GarmentUnitReceiptNoteViewModel());

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

            var mockMapper = new Mock <IMapper>();


            GarmentUnitReceiptNoteController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.GetReportDO(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>());

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

            mockFacade.Setup(x => x.ReadDOItemsByURNItemId(It.IsAny <int>()))
            .Returns(DOItemsModel);

            var mockMapper = new Mock <IMapper>();

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

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

            mockFacade.Setup(x => x.ReadItemByRO(It.IsAny <string>(), It.IsAny <string>()))
            .Throws(new Exception(""));

            var mockMapper = new Mock <IMapper>();

            GarmentUnitReceiptNoteController controller = new GarmentUnitReceiptNoteController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);
            var response = controller.GetByRO();

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

            mockFacade.Setup(x => x.ReadItemByRO(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new List <object>());

            var mockMapper = new Mock <IMapper>();

            GarmentUnitReceiptNoteController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.GetByRO();

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

            mockFacade.Setup(x => x.GetReportFlow(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(Tuple.Create(new List <FlowDetailPenerimaanViewModels>(), 5));

            var mockMapper = new Mock <IMapper>();

            GarmentUnitReceiptNoteController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.GetReportDO(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>());

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

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

            var mockMapper = new Mock <IMapper>();

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

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

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

            var mockMapper = new Mock <IMapper>();

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

            GarmentUnitReceiptNoteController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.GetByUser(filter: "{ 'IsPosted': false }");

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

            mockFacade.Setup(x => x.ReadURNItem(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), null, It.IsAny <string>()))
            .Returns(new ReadResponse <object>(new List <object>(), 0, new Dictionary <string, string>()));

            var mockMapper = new Mock <IMapper>();

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

            GarmentUnitReceiptNoteController controller = new GarmentUnitReceiptNoteController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);
            var response = controller.GetURNItem();

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

            mockFacade.Setup(x => x.ReadURNItem(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new ReadResponse <object>(new List <object>(), 0, new Dictionary <string, string>()).Data);

            var mockMapper = new Mock <IMapper>();

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

            GarmentUnitReceiptNoteController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.GetURNItem();

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
        private GarmentUnitReceiptNoteController GetController(Mock <IGarmentUnitReceiptNoteFacade> facadeM, Mock <IValidateService> validateM, Mock <IMapper> mapper)
        {
            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);
            }

            var controller = new GarmentUnitReceiptNoteController(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_Success_Get_PDF_By_Id()
        {
            var Model = this.Model;

            var mockFacade = new Mock <IGarmentUnitReceiptNoteFacade>();

            mockFacade.Setup(x => x.ReadById(It.IsAny <int>()))
            .Returns(ViewModel);
            mockFacade.Setup(x => x.GeneratePdf(It.IsAny <GarmentUnitReceiptNoteViewModel>()))
            .Returns(new MemoryStream());

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <GarmentUnitReceiptNoteViewModel>(It.IsAny <GarmentUnitReceiptNote>()))
            .Returns(ViewModel);

            GarmentUnitReceiptNoteController controller = GetController(mockFacade, null, mockMapper);

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

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

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