Пример #1
0
        public void ShouldGenerateConflictException()
        {
            var shortenUrl = new ShortUrl
            {
                Code = "AAA123",
                Url  = "www.example.com"
            };

            var mapper = new Mock <IMapper>();

            mapper.Setup(x => x.Map <ShortUrl>(It.IsAny <ShortUrlDto>()));

            var list = new List <ShortUrl> {
                shortenUrl
            };

            var task = Task.FromResult <IList <ShortUrl> >(list);

            var repository = new Mock <IRepository <ShortUrl> >();

            repository.Setup(x => x.ListAsync(It.IsAny <Expression <Func <ShortUrl, bool> > >()))
            .Returns(task);

            var service = new UrlShortenerCreatorService(mapper.Object,
                                                         repository.Object,
                                                         this.codeValidator);

            var shortenUrlDto = new ShortUrlDto
            {
                Code = "AAA123",
                Url  = "www.example.com"
            };

            Assert.Throws <ConflictException>(() => service.Execute(shortenUrlDto));
        }
Пример #2
0
        public void ShouldReturnShortenUrlEntityFromDto()
        {
            var mapper = new Mock <IMapper>();

            mapper.Setup(x => x.Map <ShortUrl>(It.IsAny <ShortUrlDto>()))
            .Returns(new ShortUrl
            {
                Code = "AAAZZ4",
                Url  = "www.example.com"
            });

            var list = new List <ShortUrl>();

            var task = Task.FromResult <IList <ShortUrl> >(list);

            var repository = new Mock <IRepository <ShortUrl> >();

            repository.Setup(x => x.ListAsync(It.IsAny <Expression <Func <ShortUrl, bool> > >()))
            .Returns(task);

            var service = new UrlShortenerCreatorService(mapper.Object,
                                                         repository.Object,
                                                         this.codeValidator);

            var shortenUrlDto = new ShortUrlDto
            {
                Code = "AAAZZ4",
                Url  = "www.example.com"
            };

            var result = service.Execute(shortenUrlDto);

            Assert.Equal(result.Code, shortenUrlDto.Code);
            Assert.Equal(result.Url, shortenUrlDto.Url);
        }
Пример #3
0
        public void ShouldGenerateUnprocessableEntityException()
        {
            var mapper = new Mock <IMapper>();

            mapper.Setup(x => x.Map <ShortUrl>(It.IsAny <ShortUrlDto>()));

            var repository = new Mock <IRepository <ShortUrl> >();

            var service = new UrlShortenerCreatorService(mapper.Object,
                                                         repository.Object,
                                                         this.codeValidator);

            var shortenUrl = new ShortUrlDto
            {
                Code = "AAA",
                Url  = "www.example.com"
            };

            Assert.Throws <UnprocessableEntityException>(() => service.Execute(shortenUrl));
        }