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

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

            var mockMapper = new Mock <IMapper>();

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

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

            mockFacade.Setup(x => x.ReadName(null, "{}"))
            .Returns(new List <GarmentInternalPurchaseOrder>());

            var mockMapper = new Mock <IMapper>();

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

            GarmentInternalPurchaseOrderController controller = GetController(mockFacade, null, mockMapper);
            var response = controller.ByName(null, null);

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

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

            var mockMapper = new Mock <IMapper>();

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

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

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

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

            var mockMapper = new Mock <IMapper>();

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

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

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

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

            var mockMapper = new Mock <IMapper>();

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

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

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

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

            var mockMapper = new Mock <IMapper>();

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

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

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
Пример #7
0
        public void Should_Fail_GetByName()
        {
            //Setup
            var facadeMock = new Mock <IGarmentInternalPurchaseOrderFacade>();

            facadeMock
            .Setup(x => x.ReadName(It.IsAny <string>(), It.IsAny <string>()))
            .Throws(new Exception());

            var mapperMock = new Mock <IMapper>();

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

            //Act
            GarmentInternalPurchaseOrderController controller = GetController(facadeMock, null, mapperMock);
            var response = controller.ByName(null, null);

            //Assert
            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
        private GarmentInternalPurchaseOrderController GetController(Mock <IGarmentInternalPurchaseOrderFacade> 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 GarmentInternalPurchaseOrderController(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);
        }