Ejemplo n.º 1
0
        public async Task AddTagToPhoto_InvalidTagId_ShouldReturnFalse_ShouldNotModifyPhoto()
        {
            // arrange
            var context = await InitializeContext();

            var repository    = new Application.Repository.Photo.PhotoRepository(context);
            var tagId         = 10;
            var photoId       = 1;
            var photoFromList = Photos.First(p => p.Id == photoId);

            //act
            var result = await repository.AddTagToPhoto(photoId, tagId);

            await repository.SaveChanges();

            var photoFromDb = await repository.GetById(photoId);

            //assert
            Assert.False(result);
            Assert.True(photoFromList.Tags.Select(t => t.Id).OrderBy(i => i)
                        .SequenceEqual(photoFromDb.Tags.Select(t => t.Id).OrderBy(i => i)));

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 2
0
        public async Task AddTagToPhoto_ValidTagId_TagAlreadyIn_ShouldNotNewAddTag_ShouldReturnTrue()
        {
            // arrange
            var context = await InitializeContext();

            var repository       = new Application.Repository.Photo.PhotoRepository(context);
            var tagId            = 1;
            var currentTagCounts = 2;
            var photoId          = 1;

            //act
            var result = await repository.AddTagToPhoto(photoId, tagId);

            await repository.SaveChanges();

            var photoFromDb = await repository.GetById(photoId);

            //assert
            Assert.True(result);
            Assert.NotNull(photoFromDb.Tags.FirstOrDefault(t => t.Id == tagId));
            Assert.AreEqual(currentTagCounts, photoFromDb.Tags.Count());

            //clean
            DisposeContext(context);
        }
        public async Task AddTagToPhoto_ValidTagId_ShouldAddTag_ShouldReturnTrue()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);
            var tagId      = 3;
            var photoId    = 1;

            //act
            var result = await repository.AddTagToPhoto(photoId, tagId);

            await repository.SaveChanges();

            var photoFromDb = await repository.GetById(photoId);

            //assert
            Assert.True(result);
            Assert.NotNull(photoFromDb.Tags.FirstOrDefault(t => t.Id == tagId));

            //clean
            photoFromDb.Tags = Photos.First(p => p.Id == photoId).Tags;
            await repository.SaveChanges();

            DisposeContext(context);
        }
Ejemplo n.º 4
0
        public async Task Delete_ValidId_SharedTag_ShouldRemove_ShouldNotRemoveAnyTag()
        {
            // arrange
            var context = await InitializeContext();

            var repository   = new Application.Repository.Photo.PhotoRepository(context);
            var idToDelete   = 3;
            var expectedSize = Photos.Count - 1;

            //act
            var result = await repository.Delete(idToDelete);

            await repository.SaveChanges();

            var allPhotos = await repository.Take(10);

            //assert
            Assert.True(result);
            Assert.AreEqual(expectedSize, allPhotos.Count());
            Assert.Null(allPhotos.FirstOrDefault(p => p.Id == idToDelete));
            Assert.True(await repository.IsTagExist(3));

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 5
0
        public async Task Take_NegativeArgument_ShouldReturnEmptyCollection()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);

            //act
            var result = await repository.Take(-5);

            //assert
            Assert.AreEqual(0, result.Count());

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 6
0
        public async Task Take_PositiveArgumentNotGreaterThanDataSize()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);

            //act
            var result = await repository.Take(2);

            //assert
            Assert.AreEqual(2, result.Count());

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 7
0
        public async Task TakeRandom_NegativeArgument()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);
            int amount     = -1;

            //act
            var result = await repository.TakeRandom(amount);

            //assert
            Assert.AreEqual(0, result.Count());

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 8
0
        public async Task Take_PositiveArgumentGreaterThanDataSize_ShouldNotFail_ShouldReturnFullList()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);

            //act
            var result = await repository.Take(10);

            //assert
            Assert.True(Photos.Select(p => p.Id).OrderBy(i => i)
                        .SequenceEqual(result.Select(p => p.Id).OrderBy(i => i)));

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 9
0
        public async Task TakeWithTagLike_PatternNotMatch()
        {
            // arrange
            var context = await InitializeContext();

            var    repository = new Application.Repository.Photo.PhotoRepository(context);
            int    amount     = 2;
            string pattern    = "NotMatched";

            //act
            var result = await repository.TakeWithTagLike(pattern, amount);

            //assert
            Assert.AreEqual(0, result.Count());

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 10
0
        public async Task TakeWhereTag_NegativeTagId_ShouldReturnEmptyList()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);
            int tagId      = -1;
            int maxAmount  = 2;

            //act
            var result = await repository.TakeWhereTag(tagId, maxAmount);

            //assert
            Assert.AreEqual(0, result.Count());

            //clean
            DisposeContext(context);
        }
        public async Task FilterByExistence_NullAgument_ShouldReturnEmptyList()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);
            var expected   = new string[] {};

            //act
            var result = await repository.FilterByExistence(null);

            //assert
            Assert.NotNull(result);
            Assert.True(result.SequenceEqual(expected));

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 12
0
        public async Task TakeRandomWithTag_ValidTagId_NegativeAmount()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);
            int amount     = -1;
            int tagId      = 10;

            //act
            var result = await repository.TakeRandomWithTag(tagId, amount);

            //assert
            Assert.AreEqual(0, result.Count());

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 13
0
        public async Task TakeWithTagLike_PatternFullMatch()
        {
            // arrange
            var context = await InitializeContext();

            var    repository = new Application.Repository.Photo.PhotoRepository(context);
            int    amount     = 5;
            string pattern    = "Warsaw";

            //act
            var result = await repository.TakeWithTagLike(pattern, amount);

            //assert
            Assert.AreEqual(1, result.Count());
            Assert.True(result.First().Id == 1);

            //clean
            DisposeContext(context);
        }
        public async Task FilterByExistence_NoNameInDb_ShouldReturnEmptyList()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);
            var input      = new [] { "Madrid", "Tokyo", "London" };
            var expected   = new string[] {};

            //act
            var result = await repository.FilterByExistence(input);

            //assert
            Assert.NotNull(result);
            Assert.True(result.SequenceEqual(expected));

            //clean
            DisposeContext(context);
        }
        public async Task FilterByExistence_NullInArguments_ShouldDiscardNull()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);

            var input = new[] { "Paris", null, "Warsaw" };
            var expected = new[] { "warsaw", "paris" }.OrderBy(s => s);

            //act
            var result = (await repository.FilterByExistence(input)).OrderBy(s => s);

            //assert
            Assert.NotNull(result);
            Assert.True(result.SequenceEqual(expected));

            //clean
            DisposeContext(context);
        }
        public async Task FilterByExistence_DoubledValues_ResultCollectionShouldHaveUniqueValues()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);

            var input = new[] { "Paris", "Warsaw", "Paris", "Warsaw" };
            var expected = new[] { "warsaw", "paris" }.OrderBy(s => s);

            //act
            var result = (await repository.FilterByExistence(input)).OrderBy(s => s);

            //assert
            Assert.NotNull(result);
            Assert.True(result.SequenceEqual(expected));

            //clean
            DisposeContext(context);
        }
        public async Task FilterByExistence_HalfPartInDb_Configuration1()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);

            var input = new[] { "Madrid", "Paris", "Los Angeles", "Warsaw", "Tokyo" };
            var expected = new[] { "warsaw", "paris" }.OrderBy(s => s);

            //act
            var result = (await repository.FilterByExistence(input)).OrderBy(s => s);

            //assert
            Assert.NotNull(result);
            Assert.True(result.SequenceEqual(expected));

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 18
0
        public async Task TakeWithTagLike_PatternMatchInTheMiddleOfString()
        {
            // arrange
            var context = await InitializeContext();

            var    repository = new Application.Repository.Photo.PhotoRepository(context);
            int    amount     = 5;
            string pattern    = "erli";

            //act
            var result = await repository.TakeWithTagLike(pattern, amount);

            //assert
            Assert.AreEqual(2, result.Count());
            Assert.True(result.Any(p => p.Id == 1));
            Assert.True(result.Any(p => p.Id == 2));

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 19
0
        public async Task TakeWithTagLike_PatternMatchMoreThanOne()
        {
            // arrange
            var context = await InitializeContext();

            var    repository   = new Application.Repository.Photo.PhotoRepository(context);
            int    amount       = 5;
            int    expectedSize = 3;
            string pattern      = "ar";

            //act
            var result = await repository.TakeWithTagLike(pattern, amount);

            //assert
            Assert.AreEqual(3, result.Count());
            Assert.Null(result.FirstOrDefault(p => p.Id == 2));

            //clean
            DisposeContext(context);
        }
        public async Task FilterByExistence_EveryNameInDb_ShouldReturnTheSameCollection()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);

            var input = new[] { "Paris", "Berlin", "Warsaw" };
            var expected = new[] { "warsaw", "berlin", "paris" }.OrderBy(s => s);

            //act
            var result = (await repository.FilterByExistence(input)).OrderBy(s => s).ToList();

            //assert
            Assert.NotNull(result);
            Assert.True(result.SequenceEqual(expected));

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 21
0
        public async Task TakeIncludeTags_PositiveArgumentNotGreaterThanDataSize()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);

            //act
            var result = await repository.TakeIncludeTags(2);

            var tagsOfFirstPhoto = result.FirstOrDefault(p => p.Id == 1).Tags;

            //assert
            Assert.AreEqual(2, result.Count());
            Assert.True(tagsOfFirstPhoto.Any(t => t.Id == 1));
            Assert.True(tagsOfFirstPhoto.Any(t => t.Id == 2));
            Assert.AreEqual(2, tagsOfFirstPhoto.Count());

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 22
0
        public async Task TakeWithTagLike_NullPattern()
        {
            // arrange
            var context = await InitializeContext();

            var repository   = new Application.Repository.Photo.PhotoRepository(context);
            int amount       = 2;
            int expectedSize = 2;

            for (int i = 0; i < 10; i++)
            {
                //act
                var result = await repository.TakeWithTagLike(null, amount);

                //assert
                Assert.AreEqual(2, result.Count());
            }

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 23
0
        public async Task TakeRandomWithTag_ValidArguments()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);
            int amount     = 1;
            int tagId      = 2;

            for (int i = 0; i < 10; i++)
            {
                //act
                var result = await repository.TakeRandomWithTag(tagId, amount);

                //assert
                Assert.AreEqual(amount, result.Count());
                Assert.True(result.First().Tags.Any(t => t.Id == tagId));
            }

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 24
0
        [Test] public async Task TakeIncludeTags_PositiveArgumentGreaterThanDataSize_ShouldNotFail_ShouldReturnFullList()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);

            //act
            var result = await repository.TakeIncludeTags(10);

            var tagsOfFirstPhoto = result.FirstOrDefault(p => p.Id == 1).Tags;

            //assert
            Assert.True(Photos.Select(p => p.Id).OrderBy(i => i)
                        .SequenceEqual(result.Select(p => p.Id).OrderBy(i => i)));
            Assert.True(tagsOfFirstPhoto.Any(t => t.Id == 1));
            Assert.True(tagsOfFirstPhoto.Any(t => t.Id == 2));
            Assert.AreEqual(2, tagsOfFirstPhoto.Count());

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 25
0
        public async Task TakeWhereTag_ValidTagId_AmountLessThanCollectionSize()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);
            int tagId      = 2;
            int amount     = 1;

            //act
            var result = await repository.TakeWhereTag(tagId, amount);

            var firstResult = result.First();

            //assert
            Assert.AreEqual(1, result.Count());
            Assert.NotNull(firstResult);
            Assert.True(firstResult.Tags.Any(t => t.Id == tagId));

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 26
0
        public async Task TakeRandomWithTag_ValidArguments_FullListForThatTag()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);
            int maxAmount  = 3;
            int tagId      = 2;

            for (int i = 0; i < 10; i++)
            {
                //act
                var result = await repository.TakeRandomWithTag(tagId, maxAmount);

                //assert
                Assert.AreEqual(2, result.Count());
                Assert.True(result.First().Id != result.Skip(1).First().Id);
            }

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 27
0
        public async Task Delete_InvalidId_ShouldNotModifyCollection()
        {
            // arrange
            var context = await InitializeContext();

            var repository   = new Application.Repository.Photo.PhotoRepository(context);
            var idToDelete   = 10;
            var expectedSize = Photos.Count;

            //act
            var result = await repository.Delete(idToDelete);

            await repository.SaveChanges();

            var allPhotos = await repository.Take(10);

            //assert
            Assert.False(result);
            Assert.AreEqual(expectedSize, allPhotos.Count());

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 28
0
        public async Task TakeRandom_ValidArgument_ShouldReturnDifferentValues()
        {
            // arrange
            var context = await InitializeContext();

            var repository = new Application.Repository.Photo.PhotoRepository(context);
            int amount     = 3;

            for (int i = 0; i < 10; i++)
            {
                //act
                var result = await repository.TakeRandom(amount);

                //assert
                Assert.AreEqual(amount, result.Count());
                Assert.True(result.First().Id != result.Skip(1).First().Id);
                Assert.True(result.First().Id != result.Skip(2).First().Id);
                Assert.True(result.Skip(1).First().Id != result.Skip(2).First().Id);
            }

            //clean
            DisposeContext(context);
        }
Ejemplo n.º 29
0
        public async Task TakeWhereTag_ValidTagId_AmountGreaterThanCollectionSize()
        {
            // arrange
            var context = await InitializeContext();

            var repository    = new Application.Repository.Photo.PhotoRepository(context);
            int tagId         = 2;
            int expectedCount = 2;
            int maxAmount     = 10;

            //act
            var result = await repository.TakeWhereTag(tagId, maxAmount);

            var firstResult = result.First(p => p.Id == 1);
            var secResult   = result.First(p => p.Id == 2);

            //assert
            Assert.AreEqual(expectedCount, result.Count());
            Assert.NotNull(firstResult);
            Assert.NotNull(secResult);

            //clean
            DisposeContext(context);
        }