public void Should_Success_Get_All_Data_By_User()
        {
            var mockFacade = new Mock <IGarmentClosingDateFacade>();

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

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <List <GarmentClosingDateViewModel> >(It.IsAny <List <GarmentClosingDate> >()))
            .Returns(new List <GarmentClosingDateViewModel> {
                viewModel
            });

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

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

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

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <GarmentClosingDate>(It.IsAny <GarmentClosingDateViewModel>()))
            .Returns(Model);

            var mockFacade = new Mock <IGarmentClosingDateFacade>();

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

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

            var response = await controller.Post(this.viewModel);

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

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