コード例 #1
0
        public void ShouldRetrieveAPicture()
        {
            var id = Guid.NewGuid();

            var mockStorage = new Mock <IStorageContext>();

            mockStorage.Setup(s => s.Query <Picture>(StorageAccountConfiguration.PicturesTable)).Returns(() =>
            {
                var result = new List <Picture>();
                result.Add(new Picture()
                {
                    Id = id
                });
                result.Add(new Picture()
                {
                    Id = Guid.NewGuid()
                });
                return(result.AsQueryable());
            });

            var repository = new PictureRepository(mockStorage.Object);
            var picture    = repository.Get(id);

            Assert.AreEqual(picture.Id, id);
        }
コード例 #2
0
        public static PictureRepository GetPictureRepository(IUnitOfWork unitOfWork)
        {
            var repository = new PictureRepository();

            repository.UnitOfWork = unitOfWork;
            return(repository);
        }
コード例 #3
0
        public static PictureRepository GetPictureRepository()
        {
            var repository = new PictureRepository();

            repository.UnitOfWork = GetUnitOfWork();
            return(repository);
        }
コード例 #4
0
        public IActionResult Picture(int Id)
        {
            PictureRepository pictureRepository = new PictureRepository(_connectionString);
            Picture           p = pictureRepository.GetPictureById(Id);

            return(View(p));
        }
コード例 #5
0
        public IActionResult Index()
        {
            PictureRepository pictureRepository = new PictureRepository(_connectionString);
            List <Picture>    pictures          = pictureRepository.GetPictures();

            return(View(pictures));
        }
コード例 #6
0
        public IActionResult AddPicture(Picture p)
        {
            PictureRepository picture = new PictureRepository(_connectionString);

            picture.AddPicture(p);
            return(Redirect("/Home/Index"));
        }
コード例 #7
0
ファイル: PictureService.cs プロジェクト: onurh/AF452
        /// <summary>
        /// Gets the loaded picture binary depending on picture storage settings
        /// </summary>
        /// <param name="picture">Picture</param>
        /// <param name="fromDb">Load from database; otherwise, from file system</param>
        /// <returns>Picture binary</returns>
        public virtual byte[] LoadPictureBinary(Picture picture, bool fromDb)
        {
            if (picture == null)
            {
                throw new ArgumentNullException("picture");
            }

            byte[] result = null;
            if (fromDb)
            {
                if (picture.PictureBinary != null)
                {
                    result = picture.PictureBinary;
                }
                else
                {
                    result = new PictureRepository().PictureBinary(picture.Id);
                }
            }
            else
            {
                result = LoadPictureFromFile(picture.Id, picture.MimeType);
            }
            return(result);
        }
コード例 #8
0
        public void ShouldSaveAPicture()
        {
            var picture = new Picture()
            {
                Name = "picture1", Description = "desc of picture1", Tags = string.Empty
            };
            var image = new byte[] { 1, 2, 3 };

            var mockStorage = new Mock <IStorageContext>();

            mockStorage.Setup(s => s.SaveBlob(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <string>())).Returns(() =>
            {
                return("http://foo");
            });

            var repository = new PictureRepository(mockStorage.Object);

            picture = repository.Save(picture, image);

            Assert.AreNotEqual(picture.Id, Guid.Empty);
            Assert.AreEqual(picture.Url, new Uri("http://foo"));

            mockStorage.Verify(s => s.SaveBlob(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <string>()), Times.Once());
            mockStorage.Verify(s => s.AddEntity(It.IsAny <Picture>(), StorageAccountConfiguration.PicturesTable), Times.Once());
            mockStorage.Verify(s => s.AddEntities(It.IsAny <IEnumerable <PictureTag> >(), StorageAccountConfiguration.PictureTagTable), Times.Once());
        }
コード例 #9
0
 public PictureRepository GetPictureRepository()
 {
     if (pictureRepository == null)
     {
         pictureRepository = new PictureRepository();
     }
     return pictureRepository;
 }
コード例 #10
0
ファイル: UnitOfWork.cs プロジェクト: ImgSpot/ImgSpotWebAPI
 public UnitOfWork(ImgSpotContext context)
 {
     _context = context;
     Users    = new UserRepository(_context);
     Pictures = new PictureRepository(_context);
     Comments = new CommentRepository(_context);
     Likes    = new LikeRepository(_context);
 }
コード例 #11
0
 public IList <Picture> GetLastestPictures()
 {
     using (PictureRepository repo = new PictureRepository())
     {
         var pictures = repo.GetLastestPictures(1, 50);
         return(pictures);
     }
 }
 public PictureRepository GetPictureRepository()
 {
     if (pictureRepository == null)
     {
         pictureRepository = new PictureRepository();
     }
     return(pictureRepository);
 }
コード例 #13
0
 public StudentRepositoryTest()
 {
     _context      = new Mock <DatabaseEntities>();
     _mySetStudent = new Mock <DbSet <STUDENT> >();
     _mySetPicture = new Mock <DbSet <PICTURE> >();
     _repo         = new StudentRepository(_context.Object);
     _picture      = new PictureRepository(_context.Object);
 }
コード例 #14
0
 public PictureController(IConfiguration config, PictureRepository pictureRepository, UserManager <User> userManager, ILogger <PictureController> logger)
 {
     _config            = config;
     _pictureRepository = pictureRepository;
     _storageAccount    = CloudStorageAccount.Parse(config.GetConnectionString("BlobStorage"));
     _userManager       = userManager;
     _logger            = logger;
 }
コード例 #15
0
        public IActionResult GetLikes(int Id)
        {
            Likes             l       = new Likes();
            PictureRepository picture = new PictureRepository(_connectionString);

            l.number = picture.GetLikesCount(Id);
            return(Json(l));
        }
コード例 #16
0
 public DataLayerService()
 {
     config               = new LocalConfig();
     pictureRepository    = new PictureRepository(config);
     foodRepository       = new FoodRepository(config);
     userRepository       = new UserRepository(config);
     restaurantRepository = new RestaurantRepository(config);
 }
コード例 #17
0
 public IList <Picture> SearchPictures(string name, string familyName, string series, string artist)
 {
     using (PictureRepository repo = new PictureRepository())
     {
         IList <Picture> pictures = repo.SearchPictures(name, familyName, series, artist);
         return(pictures);
     }
 }
コード例 #18
0
 public SearchController(UserManager <User> userManager, IConfiguration config, PictureRepository pictureRepository, SearchRepository searchRepository)
 {
     _userManager       = userManager;
     _config            = config;
     _storageAccount    = CloudStorageAccount.Parse(config.GetConnectionString("BlobStorage"));
     _pictureRepository = pictureRepository;
     _searchRepository  = searchRepository;
 }
コード例 #19
0
        public DataLayerService()
        {
            config = new LocalConfig();

            pictureRepository = new PictureRepository(config);
            placeRepositiry   = new PlaceRepositiry(config);
            userRepository    = new UserRepository(config);
        }
コード例 #20
0
        private void IntializaPictureRepository()
        {
            var mockValidator = new Mock <IHostingEnvironment>();

            var contentRootPath = Directory.GetCurrentDirectory();

            mockValidator.Setup(x => x.ContentRootPath).Returns(contentRootPath);
            _pictureRepository = new PictureRepository(mockValidator.Object);
        }
コード例 #21
0
ファイル: EventFactory.cs プロジェクト: branec/DiplomskiRad
 public EventFactory()
 {
     eRepository  = new EventRepository(new Entities());
     lRepository  = new LocationRepository(new Entities());
     oRepository  = new OrganisationRepository(new Entities());
     teRepository = new TypeEventRepository(new Entities());
     pRepository  = new PictureRepository(new Entities());
     edRepository = new EventDateRepository(new Entities());
 }
コード例 #22
0
        public UnitOfWork(AdvertContext context)
        {
            this.context = context;

            CommentRepository    = new CommentRepository(context);
            RatingRepository     = new RatingRepository(context);
            RealEstateRepository = new RealEstateRepository(context);
            UserRepository       = new UserRepository(context);
            PictureRepository    = new PictureRepository(context);
        }
コード例 #23
0
        public async Task GetAllPicturesAsync()
        {
            //Arrage
            var yapartContext = new YapartStoreContext();
            var pictures      = new PictureRepository(yapartContext);
            //Act
            var result = await pictures.GetAll().ToListAsync();

            //Assert
            var aa = 0;
        }
コード例 #24
0
        public IEnumerable <Picture> Get()
        {
            List <Picture> pictures;

            using (IRepository <Picture> picturesRepository = new PictureRepository(_context))
            {
                pictures = picturesRepository.GetAll().ToList();
            }

            return(pictures);
        }
コード例 #25
0
        public async Task <bool> Add(Picture picture)
        {
            bool result;

            using (IRepository <Picture> picturesRepository = new PictureRepository(_context))
            {
                result = await picturesRepository.Insert(picture);
            }

            return(result);
        }
コード例 #26
0
        public Picture Get(int id)
        {
            Picture picture;

            using (IRepository <Picture> pictureRepository = new PictureRepository(_context))
            {
                picture = pictureRepository.Get(id);
            }

            return(picture);
        }
コード例 #27
0
 public MainViewModel(ShopNetworkContext dbCont)
 {
     _subGroupRepository = new SubGroupRepository(dbCont);
     _groupRepository    = new GroupRepository(dbCont);
     _personRepository   = new PersonRepository(dbCont);
     _pictureRepository  = new PictureRepository(dbCont);
     _adminRepository    = new AdminRepository(dbCont);
     _discountRepository = new DiscountRepository(dbCont);
     _productRepository  = new ProductRepository(dbCont);
     _newsRepository     = new NewsRepository(dbCont);
     _cartRepository     = new CartRepository(dbCont);
 }
コード例 #28
0
        public ActionResult UserPicture(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                var filename = Path.GetFileName(file.FileName);
                var pathname = Path.Combine(Server.MapPath("~/Content/Images"), filename); //Saves the picture in Images
                file.SaveAs(pathname);


                PictureRepository.UploadPicture(User.Identity.Name, filename);
            }
            return(RedirectToAction("Profile", "User"));
        }
コード例 #29
0
 public async Task <bool> BanPicture(int id)
 {
     using (IRepository <Picture> picturesRepository = new PictureRepository(_context))
     {
         var pic = picturesRepository.GetById(id);
         if (pic == null)
         {
             return(false);
         }
         pic.Removed = true;
         return(await picturesRepository.Update(pic));
     }
 }
コード例 #30
0
        public Respone AddProduct(ProductCreateViewModel product, string username)
        {
            User current = UserRepository.GetItemByID(username);

            if (current == null)
            {
                return new Respone {
                           IsDone = false, Message = "Only signed users can add products"
                }
            }
            ;
            else
            {
                try
                {
                    product.Product.PublicationDate = DateTime.Now;
                    product.Product.UploadedByUser  = current;
                    if (Validator.TryValidateObject(product.Files, new ValidationContext(product.Files), null))
                    {
                        ProductRepository.InsertItem(product.Product);
                        PictureRepository.InsertItem(new Picture()
                        {
                            IsMainPicture = true, ProductID = product.Product, Image = PicturesSerializationAdapter.Serialize(product.Files.MainImage)
                        });
                        PictureRepository.InsertItem(new Picture()
                        {
                            ProductID = product.Product, Image = PicturesSerializationAdapter.Serialize(product.Files.Image2)
                        });
                        PictureRepository.InsertItem(new Picture()
                        {
                            ProductID = product.Product, Image = PicturesSerializationAdapter.Serialize(product.Files.Image3)
                        });
                        Save();
                        return(new Respone {
                            IsDone = true
                        });
                    }
                    else
                    {
                        throw new Exception("Invalid files");
                    }
                }
                catch (Exception e)
                {
                    Rollback();
                    return(new Respone {
                        IsDone = false, Message = e.Message
                    });
                }
            }
        }
コード例 #31
0
        protected IAdminCarsService GetService(ApplicationDbContext dbContext)
        {
            var carRepository        = new CarRepository(dbContext);
            var carOptionsRepository = new CarOptionRepository(dbContext);
            var adminDeleteService   = new AdminCommonDeleteService(dbContext);
            var pictureRepository    = new PictureRepository(dbContext);
            var service = new AdminCarsService(
                carRepository,
                carOptionsRepository,
                pictureRepository,
                adminDeleteService);

            return(service);
        }
コード例 #32
0
 public static PictureRepository GetPictureRepository()
 {
     var repository = new PictureRepository();
     repository.UnitOfWork = GetUnitOfWork();
     return repository;
 }
コード例 #33
0
 public static PictureRepository GetPictureRepository(IUnitOfWork unitOfWork)
 {
     var repository = new PictureRepository();
     repository.UnitOfWork = unitOfWork;
     return repository;
 }
コード例 #34
0
        public RepositoryRegistry()
        {
            For<ICredentialRepository>()
                .Use(factory =>
                {
                    return new CredentialRepository(factory.GetInstance<Entities>());
                });

            For<IProfileRepository>()
                .Use(factory =>
                {
                    var repository = new ProfileRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IProfileActivityRepository>()
                .Use(factory =>
                {
                    var repository = new ProfileActivityRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IGrunkerRepository>()
                .Use(factory =>
                {
                    var repository = new GrunkerRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IActivityTypeRepository>()
                .Use(factory =>
                {
                    var repository = new ActivityTypeRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IPictureRepository>()
                .Use(factory =>
                {
                    var repository = new PictureRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IGenreRepository>()
                .Use(factory =>
                {
                    var repository = new GenreRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IArtistRepository>()
                .Use(factory =>
                {
                    var repository = new ArtistRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IAlbumRepository>()
                .Use(factory =>
                {
                    var repository = new AlbumRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IPurchaseRepository>()
                .Use(factory =>
                {
                    var repository = new PurchaseRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IReviewRepository>()
                .Use(factory =>
                {
                    var repository = new ReviewRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IReviewLinkRepository>()
                .Use(factory =>
                {
                    var repository = new ReviewLinkRepository(factory.GetInstance<Entities>());
                    return repository;
                });

            For<IStoreDetailsRepository>()
                .Use(factory =>
                {
                    var repository = new StoreDetailsRepository(HttpContext.Current.Server.MapPath("~/App_Data/storedetails.xml"));
                    return repository;
                });

            For<IStaticTextRepository>()
                .Use(factory =>
                {
                    var repository = new StaticTextRepository(factory.GetInstance<Entities>());
                    return repository;
                });
        }
コード例 #35
0
        public void PictureRepository_can_query_List_from_datasource()
        {
            //Arrange
            var picRepo = new PictureRepository(_unitOfWorkMock.Object);

            //Action
            var picList = picRepo.GetAllInOrder(0, HomePageViewModel.TOP_SLIDE_PIC_COUNT);

            //Assertions
            _unitOfWorkMock.Verify(uow => uow.GetAll<Picture, int>(p => p.OrdinalIndex, true, 0, HomePageViewModel.TOP_SLIDE_PIC_COUNT));
            Assert.That(picList.Count == 1);
            Assert.AreEqual(picList[0], _testPic);
        }
コード例 #36
0
        public void The_PictureRepository_can_query_next_random_picture()
        {
            //Arrange
            var picRepo = new PictureRepository(_unitOfWorkMock.Object);

            //Act
            var randomPicture = picRepo.GetNextRandomPicture(_referencePictureIDs);

            //Assert
            _unitOfWorkMock.Verify(uow =>
                uow.GetRandom<Picture>(It.Is<Expression<Func<Picture, bool>>>(e => ReferencePictureIDsDoesNotContainRandomPictureID(e)))
                , Times.Once());

            Assert.AreEqual(_randomPicture, randomPicture);
        }