Ejemplo n.º 1
0
        public async Task <ServiceResponseDto> DeleteCollectionAsync(DeleteCollectionDto deleteCollectionDto)
        {
            ServiceResponseDto deleteCollectionResultDto = new ServiceResponseDto();

            if (!await _collectionRepository.ExistsAsync(collection => collection.Id.Equals(deleteCollectionDto.Id)))
            {
                deleteCollectionResultDto.Message = "The collection does not exist.";
                return(deleteCollectionResultDto);
            }

            if (!await _collectionRepository.ExistsAsync(collection => collection.Id.Equals(deleteCollectionDto.Id) && collection.UserId.Equals(deleteCollectionDto.UserId)))
            {
                deleteCollectionResultDto.Message = "The collection does not exist or you are not the owner of the collection.";
                return(deleteCollectionResultDto);
            }

            Collection actualCollection = await _collectionRepository.FindSingleByExpressionAsync(collection => collection.Id.Equals(deleteCollectionDto.Id) && collection.UserId.Equals(deleteCollectionDto.UserId));

            if (await _collectionRepository.DeleteAsync(actualCollection))
            {
                deleteCollectionResultDto.Success = true;
                deleteCollectionResultDto.Message = "Successfully deleted the collection.";
                return(deleteCollectionResultDto);
            }

            deleteCollectionResultDto.Message = "Something happened try again later..";
            return(deleteCollectionResultDto);
        }
Ejemplo n.º 2
0
        public async Task DeleteCollectionAsync_Should_Pass()
        {
            // Arrange
            CollectionDto collectionDto = new CollectionDto
            {
                UserId = 1,
                Name   = "Dank Memes"
            };
            await CollectionService.CreateCollectionAsync(collectionDto);

            List <CollectionDto> collections = (await CollectionService.GetAllCollectionsAsync()).ToList();

            Assert.IsTrue(collections.Count.Equals(1));

            // Act
            DeleteCollectionDto deleteCollectionDto = new DeleteCollectionDto {
                Id = 1, UserId = 1
            };
            ServiceResponseDto deleteCollectionResultDto = await CollectionService.DeleteCollectionAsync(deleteCollectionDto);

            // Assert
            Assert.IsTrue(deleteCollectionResultDto.Success);
            collections = (await CollectionService.GetAllCollectionsAsync()).ToList();
            Assert.IsTrue(collections.Count.Equals(0));
        }