Пример #1
0
        public void ShortenGet_Always_ShouldReturnShortenView()
        {
            //Arrange
            var mockUrlLogic   = new Mock <IUrlLogic>();
            var urlsController = new UrlsController(mockUrlLogic.Object);

            //Act
            ActionResult actionResult = urlsController.Shorten();

            //Assert
            (actionResult as ViewResult)?.ViewName.ShouldBeEquivalentTo("shorten");
        }
Пример #2
0
        public void ShortenGet_Always_ShouldReturnView()
        {
            //Arrange
            var mockUrlLogic   = new Mock <IUrlLogic>();
            var urlsController = new UrlsController(mockUrlLogic.Object);

            //Act
            ActionResult actionResult = urlsController.Shorten();

            //Assert
            actionResult.Should().BeOfType <ViewResult>(because: "shorten get action should return view");
        }
        public void Shorten_WithValidModel_ShouldReturnOkLink()
        {
            //Arrange
            var mockUrlLogic = new Mock <IUrlLogic>();
            var controller   = new UrlsController(mockUrlLogic.Object);
            var link         = new Link();
            //Act
            IHttpActionResult actionResult = controller.Shorten(link);

            //Assert
            actionResult.Should().BeOfType <OkNegotiatedContentResult <Link> >(because: "model is valid");
        }
Пример #4
0
        public void ShortenPost_WithValidModel_ShouldCallShortenLogic()
        {
            //Arrange
            var mockUrlLogic   = new Mock <IUrlLogic>();
            var urlsController = new UrlsController(mockUrlLogic.Object);
            var link           = new Link()
            {
                LongUrl = "nonEmpty"
            };

            //Act
            ActionResult actionResult = urlsController.Shorten(link);

            //Assert
            mockUrlLogic.Verify(x => x.Shorten(It.IsAny <Link>()), "valid model should reach logic");
        }
Пример #5
0
        public void ShortenPost_Always_ShouldReturnModel()
        {
            //Arrange
            var mockUrlLogic   = new Mock <IUrlLogic>();
            var urlsController = new UrlsController(mockUrlLogic.Object);
            var link           = new Link()
            {
                LongUrl = ""
            };

            //Act
            ActionResult actionResult = urlsController.Shorten(link);

            //Assert
            (actionResult as ViewResult).Model.Should().BeOfType <Link>(because: "action returns model in any case");
        }
Пример #6
0
        public void ShortenPost_WithInalidModel_ShouldReturnModel()
        {
            //Arrange
            var mockUrlLogic   = new Mock <IUrlLogic>();
            var urlsController = new UrlsController(mockUrlLogic.Object);

            urlsController.ModelState.AddModelError("", "");
            var link = new Link()
            {
                LongUrl = "nonEmpty"
            };

            //Act
            ActionResult actionResult = urlsController.Shorten(link);

            //Assert
            (actionResult as ViewResult).Model.Should().BeOfType <Link>(because: "action returns model in any case");
        }
Пример #7
0
        public void ShortenPost_WithInalidModel_ShouldNotCallShortenLogic()
        {
            //Arrange
            var mockUrlLogic   = new Mock <IUrlLogic>();
            var urlsController = new UrlsController(mockUrlLogic.Object);

            urlsController.ModelState.AddModelError("", "");
            var link = new Link()
            {
                LongUrl = "nonEmpty"
            };

            //Act
            ActionResult actionResult = urlsController.Shorten(link);

            //Assert
            mockUrlLogic.Verify(x => x.Shorten(It.IsAny <Link>()), Times.Never, "invalid model should not reach logic");
        }
        public void Shorten_WithInvalidModel_ShouldReturnInvalidModelStateResult()
        {
            //Arrange
            var mockUrlLogic = new Mock <IUrlLogic>();
            var controller   = new UrlsController(mockUrlLogic.Object);

            controller.ModelState.AddModelError("", "");
            var link = new Link()
            {
                LongUrl = "nonEmpty"
            };

            //Act
            IHttpActionResult actionResult = controller.Shorten(link);

            //Assert
            actionResult.Should().BeOfType <InvalidModelStateResult>(because: "model is not valid");
        }