Beispiel #1
0
        public bool InkPen(Pen pen, Ink ink)
        {
            Entities.Pen penEntity = DtoToEntityConverter.Convert(pen);
            Entities.Ink inkEntity = DtoToEntityConverter.Convert(ink);

            penEntity.InkUp(inkEntity);

            pen = EntityToDtoConverter.Convert(penEntity);

            return(Storage.UpdatePen(pen));
        }
Beispiel #2
0
        public async Task <MemeDto> GetRandomMemeAsync()
        {
            MemeDto memeDto = await _memeFetcherService.GetRandomMemeAsync();

            while (await _memeRepository.ExistsAsync(meme => meme.Id.Equals(memeDto.Id)))
            {
                memeDto = await _memeFetcherService.GetRandomMemeAsync();
            }
            Meme actualMeme = DtoToEntityConverter.Convert <Meme, MemeDto>(memeDto);
            await _memeRepository.CreateAsync(actualMeme);

            return(memeDto);
        }
Beispiel #3
0
        public async Task <bool> LikeMemeAsync(MemeLikeDto memeLikeDto)
        {
            MemeLike actualMemeLike = DtoToEntityConverter.Convert <MemeLike, MemeLikeDto>(memeLikeDto);

            if (!await _memeLikeRepository.ExistsAsync(memeLike => memeLike.MemeId.Equals(memeLikeDto.MemeId) && memeLike.UserId.Equals(memeLikeDto.UserId)))
            {
                return(await _memeLikeRepository.CreateAsync(actualMemeLike));
            }

            actualMemeLike = await _memeLikeRepository.FindSingleByExpressionAsync(memeLike => memeLike.MemeId.Equals(memeLikeDto.MemeId) && memeLike.UserId.Equals(memeLikeDto.UserId));

            actualMemeLike.IsLike = true;
            return(await _memeLikeRepository.UpdateAsync(actualMemeLike));
        }
        public async Task GetAllCollectionsAsync_Should_Return_3_Collections()
        {
            // Arrange
            CollectionDto expectedCollectionDto1 = new CollectionDto
            {
                UserId = 1,
                Name   = "Dank Memes1"
            };
            Collection entity1 = DtoToEntityConverter.Convert <Collection, CollectionDto>(expectedCollectionDto1);
            await CollectionRepository.CreateAsync(entity1);

            CollectionDto expectedCollectionDto2 = new CollectionDto
            {
                UserId = 1,
                Name   = "Dank Memes2"
            };
            Collection entity2 = DtoToEntityConverter.Convert <Collection, CollectionDto>(expectedCollectionDto2);
            await CollectionRepository.CreateAsync(entity2);

            CollectionDto expectedCollectionDto3 = new CollectionDto
            {
                UserId = 1,
                Name   = "Dank Memes3"
            };
            Collection entity3 = DtoToEntityConverter.Convert <Collection, CollectionDto>(expectedCollectionDto3);
            await CollectionRepository.CreateAsync(entity3);

            // Act
            CollectionDto actualCollectionDto1 = (await CollectionService.GetAllCollectionsAsync()).First();
            CollectionDto actualCollectionDto2 = (await CollectionService.GetAllCollectionsAsync()).Skip(1).First();
            CollectionDto actualCollectionDto3 = (await CollectionService.GetAllCollectionsAsync()).Skip(2).First();

            // Assert
            Assert.AreEqual(expectedCollectionDto1, actualCollectionDto1);
            Assert.AreEqual(expectedCollectionDto2, actualCollectionDto2);
            Assert.AreEqual(expectedCollectionDto3, actualCollectionDto3);
        }