예제 #1
0
        public void Should_Error_Get_All_Data()
        {
            var mockFacade = new Mock <IGarmentPOMasterDistributionFacade>();

            mockFacade
            .Setup(s => s.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Throws(new Exception(string.Empty));

            GarmentPOMasterDistributionController controller = GetController(mockFacade, null, null);
            IActionResult response = controller.Get();

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
예제 #2
0
        public void Should_Success_Get_All_Data()
        {
            var mockFacade = new Mock <IGarmentPOMasterDistributionFacade>();

            mockFacade
            .Setup(s => s.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(new ReadResponse <dynamic>(new List <dynamic>(), 1, new Dictionary <string, string>()));

            GarmentPOMasterDistributionController controller = GetController(mockFacade, null, null);
            IActionResult response = controller.Get();

            Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(response));
        }
예제 #3
0
        public void Should_Error_Get_Data_By_Id()
        {
            var mockFacade = new Mock <IGarmentPOMasterDistributionFacade>();

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

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <GarmentPOMasterDistributionViewModel>(It.IsAny <GarmentPOMasterDistribution>()))
            .Returns(new GarmentPOMasterDistributionViewModel());

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

            IActionResult response = controller.Get(It.IsAny <long>());

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
예제 #4
0
        private GarmentPOMasterDistributionController GetController(Mock <IGarmentPOMasterDistributionFacade> mockFacade, Mock <IMapper> mockMapper, Mock <IValidateService> mockValidate)
        {
            var user   = new Mock <ClaimsPrincipal>();
            var claims = new Claim[]
            {
                new Claim("username", "unittestusername")
            };

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

            var mockServiceProvider = GetMockServiceProvider();

            if (mockFacade != null)
            {
                mockServiceProvider.Setup(x => x.GetService(typeof(IGarmentPOMasterDistributionFacade))).Returns(mockFacade.Object);
            }

            if (mockMapper != null)
            {
                mockServiceProvider.Setup(x => x.GetService(typeof(IMapper))).Returns(mockMapper.Object);
            }

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

            GarmentPOMasterDistributionController controller = new GarmentPOMasterDistributionController(mockServiceProvider.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);
        }
예제 #5
0
        public void Should_Sucscess_Get_Data_By_Id()
        {
            var mockFacade = new Mock <IGarmentPOMasterDistributionFacade>();

            mockFacade.Setup(x => x.ReadById(It.IsAny <long>()))
            .Returns(new GarmentPOMasterDistribution {
            });

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <GarmentPOMasterDistributionViewModel>(It.IsAny <GarmentPOMasterDistribution>()))
            .Returns(new GarmentPOMasterDistributionViewModel());

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

            IActionResult response = controller.Get(It.IsAny <long>());

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