示例#1
0
            public async void ShouldReturnNotFound()
            {
                // Arrange
                var url = new UrlDto
                {
                    Id           = 2,
                    AccessCount  = 1,
                    ActualUrl    = "https://google.com",
                    ShortenedUrl = "GH65ff"
                };

                var urlDto = new UrlDto
                {
                    Id           = 8,
                    AccessCount  = 1,
                    ActualUrl    = "https://google.com",
                    ShortenedUrl = "GH65ff"
                };

                UrlServiceMock.Setup(x => x.UpdateUrl(url)).ReturnsAsync(url);

                // Act
                var result = await UrlControllerToTest.Put(urlDto);

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
示例#2
0
            public async void ShouldReturnOkWithResults()
            {
                // Arrange
                var urls = new List <UrlDto>
                {
                    new UrlDto
                    {
                        Id           = 2,
                        AccessCount  = 1,
                        ActualUrl    = "https://google.com",
                        ShortenedUrl = "GH65ff"
                    },
                    new UrlDto
                    {
                        Id           = 1,
                        AccessCount  = 5,
                        ActualUrl    = "https://youtube.com",
                        ShortenedUrl = "3H6Dwe"
                    }
                };
                Paginated <UrlDto> paginatedResults = new Paginated <UrlDto>(urls, 2, 1, 10);

                UrlServiceMock.Setup(x => x.GetAll(1, 10)).ReturnsAsync(paginatedResults);

                // Act
                var result = await UrlControllerToTest.Get(1, 10);

                // Assert
                var okResult = Assert.IsType <OkObjectResult>(result);

                Assert.Same(paginatedResults, okResult.Value);
            }
示例#3
0
            public async void ShouldReturnOkResult()
            {
                // Arrange
                var url = new UrlCreate
                {
                    ActualUrl = "https://google.com"
                };

                var urlDto = new UrlDto
                {
                    Id           = 1,
                    ActualUrl    = "https://google.com",
                    ShortenedUrl = "fGwY73",
                    AccessCount  = 0
                };

                UrlServiceMock.Setup(x => x.AddUrl(url)).ReturnsAsync(urlDto);

                // Act
                var result = await UrlControllerToTest.Post(url);

                // Assert
                var okResult = Assert.IsType <OkObjectResult>(result);

                Assert.Same(urlDto, okResult.Value);
            }
示例#4
0
            public async void ShouldReturnOkWithResults()
            {
                // Arrange
                var url = new UrlDto
                {
                    Id           = 2,
                    AccessCount  = 1,
                    ActualUrl    = "https://google.com",
                    ShortenedUrl = "GH65ff"
                };

                UrlServiceMock.Setup(x => x.GetUrl("GH65ff")).ReturnsAsync(url);

                // Act
                var result = await UrlControllerToTest.Get("GH65ff");

                // Assert
                var okResult = Assert.IsType <OkObjectResult>(result);

                Assert.Same(url, okResult.Value);
            }