public void Should_Error_Get_Data_By_Id_When_InvalidId()
        {
            //Setup
            var validateMock = new Mock <IValidateService>();

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

            var mockFacade = new Mock <IPurchasingDispositionFacade>();

            mockFacade
            .Setup(x => x.ReadModelById(It.IsAny <int>()))
            .Returns(new PurchasingDisposition());

            var mockMapper = new Mock <IMapper>();

            mockMapper
            .Setup(x => x.Map <PurchasingDispositionViewModel>(It.IsAny <PurchasingDisposition>()))
            .Returns(() => null);

            //Act
            PurchasingDispositionController controller = GetController(mockFacade, validateMock, mockMapper);
            var response = controller.Get(It.IsAny <int>());

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

            mockFacade.Setup(x => x.Read(1, 25, "{}", null, "{}"))
            .Returns(Tuple.Create(new List <PurchasingDisposition>(), 0, new Dictionary <string, string>()));

            var mockMapper = new Mock <IMapper>();

            PurchasingDispositionController controller = new PurchasingDispositionController(GetServiceProvider().Object, mockMapper.Object, mockFacade.Object);
            var response = controller.Get(1, 25, "{}", null, "{}");

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
        public void Should_Success_Get_PDF_Except()
        {
            var validateMock = new Mock <IValidateService>();

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

            var mockFacade = new Mock <IPurchasingDispositionFacade>();

            mockFacade.Setup(x => x.ReadModelById(It.IsAny <int>()))
            .Returns(new PurchasingDisposition());

            var ViewModel = this.ViewModel2;

            ViewModel.IncomeTaxBy          = "Dan Liris";
            ViewModel.Currency.description = "rupiah";



            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <PurchasingDispositionViewModel>(It.IsAny <PurchasingDisposition>()))
            .Returns(ViewModel);

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

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

            PurchasingDispositionController controller = GetController(mockFacade, validateMock, mockMapper);

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

            controller.ControllerContext.HttpContext.Request.Headers["Accept"]            = "application/pdf";
            controller.ControllerContext.HttpContext.Request.Headers["x-timezone-offset"] = "0";

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

            Assert.NotNull(response.GetType().GetProperty("FileStream"));
        }
Exemplo n.º 4
0
        public void Should_Error_Get_Data_By_Id()
        {
            var mockFacade = new Mock <IPurchasingDispositionFacade>();

            mockFacade.Setup(x => x.ReadModelById(It.IsAny <int>()))
            .Returns(Model);

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <PurchasingDispositionViewModel>(It.IsAny <PurchasingDisposition>()))
            .Throws(new Exception("Error Mapping"));

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

            Assert.Equal((int)HttpStatusCode.InternalServerError, GetStatusCode(response));
        }
Exemplo n.º 5
0
        public void Should_Success_Get_Data_By_Id()
        {
            var validateMock = new Mock <IValidateService>();

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

            var mockFacade = new Mock <IPurchasingDispositionFacade>();

            mockFacade.Setup(x => x.ReadModelById(It.IsAny <int>()))
            .Returns(new PurchasingDisposition());

            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <PurchasingDispositionViewModel>(It.IsAny <PurchasingDisposition>()))
            .Returns(ViewModel);

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

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