Ejemplo n.º 1
0
        public async Task InsertImage()
        {
            IImageDataAccess imageDataAccess = Setup();

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var id   = Guid.NewGuid();
                var rows = await imageDataAccess.SaveImageAsync(new ImageRepServiceLibrary.Model.Image()
                {
                    Id          = id,
                    Name        = "Bob",
                    Description = "A picture of Bob",
                    Picture     = "dfdsgfs",
                    DateCreated = DateTime.Now,
                    Tags        = new List <Tag>()
                    {
                        new Tag()
                        {
                            TagId    = Guid.NewGuid(),
                            Name     = "Person",
                            ImageKey = id
                        },
                        new Tag()
                        {
                            TagId    = Guid.NewGuid(),
                            Name     = "Friend",
                            ImageKey = id
                        }
                    }
                });

                Assert.Equal(3, rows);



                id   = Guid.NewGuid();
                rows = await imageDataAccess.SaveImageAsync(new ImageRepServiceLibrary.Model.Image()
                {
                    Id          = id,
                    Name        = "Ozzy the puppy",
                    Description = "A picture of Ozzy when he was 3 months old",
                    Picture     = "vdfgdgfdsf",
                    DateCreated = DateTime.Now
                });

                Assert.Equal(1, rows);
                if (_commiteToDB)
                {
                    scope.Complete();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns true if the Image was saved succesfully. False otherwise
        /// </summary>
        public async Task <bool> SaveImageAsync(Image image)
        {
            int rowsChanged;

            try
            {
                rowsChanged = await _imageDataAccess.SaveImageAsync(image);
            }
            catch (Exception e)
            {
                return(false);
            }
            return(rowsChanged > 0);
        }
Ejemplo n.º 3
0
        public async Task RemoveImage()
        {
            IImageDataAccess imageDataAccess = Setup();

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var id = Guid.NewGuid();
                await imageDataAccess.SaveImageAsync(new ImageRepServiceLibrary.Model.Image()
                {
                    Id          = id,
                    Name        = "Bob",
                    Description = "A picture of Bob",
                    Picture     = "dfdsgfs",
                    DateCreated = DateTime.Now,
                    Tags        = new List <Tag>()
                    {
                        new Tag()
                        {
                            TagId    = Guid.NewGuid(),
                            Name     = "Person",
                            ImageKey = id
                        },
                        new Tag()
                        {
                            TagId    = Guid.NewGuid(),
                            Name     = "Friend",
                            ImageKey = id
                        }
                    }
                });

                int count = await imageDataAccess.DeleteImageAsync(id);

                Assert.Equal(3, count);

                id    = new Guid();
                count = await imageDataAccess.DeleteImageAsync(id);

                Assert.Equal(0, count);


                if (_commiteToDB)
                {
                    scope.Complete();
                }
            }
        }
Ejemplo n.º 4
0
        public async Task SearchImages()
        {
            IImageDataAccess imageDataAccess = Setup();

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var imageList = GenerateImages();

                foreach (var item in imageList)
                {
                    await imageDataAccess.SaveImageAsync(item);
                }

                var imagesFromDb = await imageDataAccess.SearchImagesAsync(false, tagName : "Dog");

                Assert.Equal(2, imagesFromDb.Count());

                imagesFromDb = await imageDataAccess.SearchImagesAsync(false, name : "png");

                Assert.Equal(2, imagesFromDb.Count());

                imagesFromDb = await imageDataAccess.SearchImagesAsync(false, description : " ");

                Assert.Equal(4, imagesFromDb.Count());


                imagesFromDb = await imageDataAccess.SearchImagesAsync(false, name : "png", tagName : "Dog");

                Assert.Equal(2, imagesFromDb.Count());

                imagesFromDb = await imageDataAccess.SearchImagesAsync(true, name : "png", tagName : "dog ", description : "family");

                Assert.Single(imagesFromDb);
                Assert.Equal(imagesFromDb.First(), imageList[2]);

                if (_commiteToDB)
                {
                    scope.Complete();
                }
            }
        }
Ejemplo n.º 5
0
        public async Task InsertImages()
        {
            IImageDataAccess imageDataAccess = Setup();

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var imageList = GenerateImages();

                int rows = 0;

                foreach (var item in imageList)
                {
                    rows += await imageDataAccess.SaveImageAsync(item);
                }
                Assert.Equal(21, rows);

                if (_commiteToDB)
                {
                    scope.Complete();
                }
            }
        }
Ejemplo n.º 6
0
        public async Task LoadSingleImage()
        {
            IImageDataAccess imageDataAccess = Setup();

            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var   id        = Guid.NewGuid();
                Image testImage = new Image()
                {
                    Id          = id,
                    Name        = "Bob",
                    Description = "A picture of Bob",
                    Picture     = "dfdsgfs",
                    DateCreated = DateTime.Now,
                    Tags        = new List <Tag>()
                    {
                        new Tag()
                        {
                            TagId    = Guid.NewGuid(),
                            Name     = "Person",
                            ImageKey = id
                        },
                        new Tag()
                        {
                            TagId    = Guid.NewGuid(),
                            Name     = "Friend",
                            ImageKey = id
                        }
                    }
                };
                await imageDataAccess.SaveImageAsync(testImage);

                Image imageFromDb = await imageDataAccess.GetImageAsync(id, false);

                Assert.Equal(0, imageFromDb.Tags.Count);
                Assert.True(compareImages(imageFromDb, testImage));

                imageFromDb = await imageDataAccess.GetImageAsync(id, true);

                Assert.Equal(2, imageFromDb.Tags.Count);
                Assert.True(compareImages(imageFromDb, testImage));

                id        = Guid.NewGuid();
                testImage = new Image()
                {
                    Id          = id,
                    Name        = "Bob",
                    Description = "A picture of Bob",
                    Picture     = "dfdsgfs",
                    DateCreated = DateTime.Now,
                };
                await imageDataAccess.SaveImageAsync(testImage);

                imageFromDb = await imageDataAccess.GetImageAsync(id, true);

                Assert.Equal(0, imageFromDb.Tags.Count);

                if (_commiteToDB)
                {
                    scope.Complete();
                }
            }
        }