private async Task <int> GetStatusCodePatch(Mock <IGarmentPurchaseRequestFacade> mockFacade, Mock <IMapper> mockMapper, long id)
        {
            GarmentPurchaseRequestController controller = GetController(mockFacade, null, mockMapper);

            JsonPatchDocument <GarmentPurchaseRequest> patch = new JsonPatchDocument <GarmentPurchaseRequest>();
            IActionResult response = await controller.Patch(id, patch);

            return(this.GetStatusCode(response));
        }
Example #2
0
        public void Should_Error_Get_All_Data_By_Tags()
        {
            var mockFacade = new Mock <IGarmentPurchaseRequestFacade>();
            var mockMapper = new Mock <IMapper>();

            GarmentPurchaseRequestController controller = new GarmentPurchaseRequestController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);
            var response = controller.GetByTags(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>());

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
Example #3
0
        public void Should_Error_Get_Data_By_RONo()
        {
            var mockFacade = new Mock <IGarmentPurchaseRequestFacade>();

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

            var mockMapper = new Mock <IMapper>();

            GarmentPurchaseRequestController controller = new GarmentPurchaseRequestController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);
            var response = controller.Get(It.IsAny <string>());

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
Example #4
0
        public void Should_Error_Get_All_Data_Dynamic()
        {
            var mockFacade = new Mock <IGarmentPurchaseRequestFacade>();

            mockFacade.Setup(x => x.ReadDynamic(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), null, It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Throws(new Exception());

            var mockMapper = new Mock <IMapper>();

            GarmentPurchaseRequestController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.GetDynamic();

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
Example #5
0
        public void Should_Success_Get_All_Data_Dynamic()
        {
            var mockFacade = new Mock <IGarmentPurchaseRequestFacade>();

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

            var mockMapper = new Mock <IMapper>();

            GarmentPurchaseRequestController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.GetDynamic();

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
Example #6
0
        public void Should_Success_Get_All_Data_By_Tags_With_ShipmentDate()
        {
            var mockFacade = new Mock <IGarmentPurchaseRequestFacade>();

            mockFacade.Setup(x => x.ReadByTags(It.IsAny <string>(), It.IsAny <DateTimeOffset>(), It.IsAny <DateTimeOffset>()))
            .Returns(new List <GarmentInternalPurchaseOrder>());

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <List <GarmentInternalPurchaseOrderViewModel> >(It.IsAny <List <GarmentInternalPurchaseOrder> >()))
            .Returns(new List <GarmentInternalPurchaseOrderViewModel>());

            GarmentPurchaseRequestController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.GetByTags(null, "2018-10-31", "2018-10-31");

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
Example #7
0
        public void Should_Success_Get_Data_By_Id()
        {
            var mockFacade = new Mock <IGarmentPurchaseRequestFacade>();

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

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <GarmentPurchaseRequestViewModel>(It.IsAny <GarmentPurchaseRequest>()))
            .Returns(ViewModel);

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

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
Example #8
0
        public void Should_Error_Get_All_Data_By_User()
        {
            var mockFacade = new Mock <IGarmentPurchaseRequestFacade>();

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

            var mockMapper = new Mock <IMapper>();

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

            GarmentPurchaseRequestController controller = new GarmentPurchaseRequestController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);
            var response = controller.GetByUser();

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

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

            var mockMapper = new Mock <IMapper>();

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

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

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
Example #10
0
        public async Task Should_Error_Update_Data()
        {
            var validateMock = new Mock <IValidateService>();

            validateMock.Setup(s => s.Validate(It.IsAny <GarmentPurchaseRequestViewModel>())).Verifiable();

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <GarmentPurchaseRequest>(It.IsAny <GarmentPurchaseRequestViewModel>()))
            .Returns(Model);

            var mockFacade = new Mock <IGarmentPurchaseRequestFacade>();

            mockFacade.Setup(x => x.Create(It.IsAny <GarmentPurchaseRequest>(), "unittestusername", 7))
            .ReturnsAsync(1);

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

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

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
Example #11
0
        public void Should_Success_Get_PDF_By_Id()
        {
            var mockFacade = new Mock <IGarmentPurchaseRequestFacade>();

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

            mockFacade.Setup(x => x.GeneratePdf(It.IsAny <GarmentPurchaseRequestViewModel>()))
            .Returns(new System.IO.MemoryStream());

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <GarmentPurchaseRequestViewModel>(It.IsAny <GarmentPurchaseRequest>()))
            .Returns(ViewModel);

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

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

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

            Assert.NotEqual(null, response.GetType().GetProperty("FileStream"));
        }
Example #12
0
        private GarmentPurchaseRequestController GetController(Mock <IGarmentPurchaseRequestFacade> 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);
            }

            GarmentPurchaseRequestController controller = new GarmentPurchaseRequestController(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);
        }