Пример #1
0
        public async Task Test_ShortenAction_ValidInputUrl()
        {
            // Setup
            var          inputUrl = "http://www.yahoo.com";
            var          urlShortnerServiceMock = new Mock <IUrlShortnerService>();
            var          mapperMock             = new Mock <IMapper>();
            const string urlHash = "mJ";

            urlShortnerServiceMock.Setup(s => s.AddShortenedUrl(It.IsAny <string>()))
            .Returns(Task.FromResult(new ShortenedUrl
            {
                Url     = inputUrl,
                UrlHash = urlHash
            }));

            // Action
            var urlController = new UrlController(urlShortnerServiceMock.Object, mapperMock.Object);


            var result = await urlController.Shorten(new ShortenUrlRequest
            {
                Url = inputUrl
            });

            // Assert
            Assert.IsTrue(result is OkObjectResult);
            Assert.AreEqual(((OkObjectResult)result).Value, urlHash);
        }
Пример #2
0
        public async Task Test_ShortenAction_NullInputUrl()
        {
            // Setup
            var urlShortnerServiceMock = new Mock <IUrlShortnerService>();
            var mapperMock             = new Mock <IMapper>();

            // Action
            var urlController = new UrlController(urlShortnerServiceMock.Object, mapperMock.Object);

            urlController.ModelState.AddModelError("Url", "Url is missing");

            var result = await urlController.Shorten(new ShortenUrlRequest
            {
                Url = null
            });

            // Assert
            Assert.IsTrue(result is BadRequestObjectResult);
        }