Exemplo n.º 1
0
        public void ConvertHtml()
        {
            var request   = new Mock <HttpRequestBase>();
            var context   = new Mock <HttpContextBase>();
            var routedata = new RouteData();

            routedata.Values.Add("controller", "convert");

            context.Setup(x => x.Request).Returns(request.Object);

            var controller = new ConvertController();

            controller.ControllerContext = new ControllerContext(context.Object, routedata, controller);

            var model = new TemplateViewModel
            {
                Template = "Hello",
                Title    = "none",
                FileName = "htmltest.pdf"
            };

            var result = controller.Convert(model);

            Assert.IsTrue(System.IO.File.Exists(@"D:\pdfs\htmltest.pdf"));
        }
Exemplo n.º 2
0
        public void ConvertUrl()
        {
            var controller = new ConvertController();

            var result = controller.Convert("https://www.google.com", "googletest.pdf");

            Assert.IsTrue(System.IO.File.Exists(@"D:\pdfs\googletest.pdf"));
        }
        public void Convert_WithValidModel_ShouldReturnOkModel()
        {
            //Arrange
            var mockUrlLogic = new Mock <INameCostLogic>();
            var controller   = new ConvertController(mockUrlLogic.Object);
            var model        = new NameCostModel();

            //Act
            IHttpActionResult actionResult = controller.Convert(model);

            //Assert
            actionResult
            .Should()
            .BeOfType <OkNegotiatedContentResult <NameCostModel> >
                (because: "model is valid");
        }
        public void Convert_WithValidModel_ShouldCallConvertLogic()
        {
            //Arrange
            var mockUrlLogic = new Mock <INameCostLogic>();
            var controller   = new ConvertController(mockUrlLogic.Object);
            var model        = new NameCostModel()
            {
                Cost = 1
            };

            //Act
            IHttpActionResult actionResult = controller.Convert(model);

            //Assert
            mockUrlLogic.Verify(
                x =>
                x.GenerateWords(It.IsAny <NameCostModel>()),
                "valid model should reach logic");
        }
        public void Convert_WithInvalidModel_ShouldReturnInvalidModelStateResult()
        {
            //Arrange
            var mockUrlLogic = new Mock <INameCostLogic>();
            var controller   = new ConvertController(mockUrlLogic.Object);

            controller.ModelState.AddModelError("", "");
            var model = new NameCostModel()
            {
                Cost = 1
            };

            //Act
            IHttpActionResult actionResult = controller.Convert(model);

            //Assert
            actionResult
            .Should()
            .BeOfType <InvalidModelStateResult>
                (because: "model is not valid");
        }
        public void Convert_WithInvalidModel_ShouldNotCallConvertLogic()
        {
            //Arrange
            var mockUrlLogic = new Mock <INameCostLogic>();
            var controller   = new ConvertController(mockUrlLogic.Object);

            controller.ModelState.AddModelError("", "");

            var model = new NameCostModel()
            {
                Cost = 1
            };

            //Act
            IHttpActionResult actionResult = controller.Convert(model);

            //Assert
            mockUrlLogic.Verify(
                x =>
                x.GenerateWords(It.IsAny <NameCostModel>()),
                Times.Never,
                "Invalid model should not reach logic");
        }