상속: IImageHelper
예제 #1
0
        public void TestInit()
        {
            _imageHelper = new ImageHelper();
            _rootPath = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path));

            if (Directory.Exists(_rootPath + @"\TestImages\New")) Directory.Delete(_rootPath + @"\TestImages\New", true);
            if (Directory.Exists(_rootPath + @"\TestImages\SaveImage")) Directory.Delete(_rootPath + @"\TestImages\SaveImage", true);
            if (Directory.Exists(_rootPath + @"\TestImages\SaveBytes")) Directory.Delete(_rootPath + @"\TestImages\SaveBytes", true);
            if (Directory.Exists(_rootPath + @"\TestImages\DirJpg")) Directory.Delete(_rootPath + @"\TestImages\DirJpg", true);
            if (Directory.Exists(_rootPath + @"\TestImages\DirGif")) Directory.Delete(_rootPath + @"\TestImages\DirGif", true);
            if (Directory.Exists(_rootPath + @"\TestImages\DirVid")) Directory.Delete(_rootPath + @"\TestImages\DirVid", true);
        }
예제 #2
0
        public void ShouldAddMediaByObjectWithAlbumNotFound()
        {
            var guid = Guid.NewGuid().ToString();
            var album = _albums.Where(a => a.AlbumId == 1).ToList();
            var image = Image.FromFile(_rootPath + @"\TestImages\Jpg_Image.jpg");
            var bytes = new ImageHelper().ImageToByteArray(image);
            var objParam = new Common.Contracts.Media
            {
                AlbumId = 1,
                MediaContent = bytes,
                MediaType = "image/jpg"
            };
            var dbResult = new Media
            {
                MediaId = 5,
                AlbumId = 1,
                Album = _albums[0],
                FileName = "foobarbaz.jpg",
                MediaPath = _rootPath + @"\AddedImages\1\foo\" + guid,
                CustomName = guid,
                MediaType = "image/jpg",
                MediaUrl = string.Format("https://{0}/blogapi/api/media/{1}", UserHelper.GetLocalIpAddress(), guid),
                ThumbnailPath = _rootPath + @"\AddedImages\1\foo\" + guid + @"\tn",
                ThumbnailUrl = string.Format("https://{0}/blogapi/api/media/{1}/{2}", UserHelper.GetLocalIpAddress(), guid, "thumb")
            };
            image.Dispose();

            _mediaRepository = new Mock<IMediaRepository>();
            _mediaRepository.Setup(a => a.Add(It.IsAny<Media>()))
                .Returns(dbResult);

            _fileHelper = new Mock<IFileHelper>();
            _fileHelper.Setup(a => a.MoveFile(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
            _fileHelper.Setup(a => a.CreateDirectory(It.IsAny<string>())).Returns(true);

            _albumRepository = new Mock<IAlbumRepository>();
            _albumRepository.Setup(a => a.Find(It.IsAny<Expression<Func<Album, bool>>>(), false)).Returns(new List<Album>());
            _albumRepository.Setup(a => a.Add(It.IsAny<Album>())).Returns(album.FirstOrDefault());

            _imageHelper = new Mock<IImageHelper>();
            _imageHelper.Setup(a => a.GenerateImagePath(It.IsAny<int>(), It.IsAny<string>(),
                It.IsAny<string>())).Returns(_rootPath + @"\AddedImages\1\" + guid);
            _imageHelper.Setup(a => a.CreateThumbnail(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
                .Returns(true);
            _imageHelper.Setup(a => a.SaveImage(It.IsAny<byte[]>(), It.IsAny<string>(), It.IsAny<string>()))
                .Returns(true);

            _configurationHelper = new Mock<IConfigurationHelper>();
            _configurationHelper.Setup(a => a.GetAppSettings(It.IsAny<string>())).Returns("tn_");

            _mediaLogic = new MediaLogic(_mediaRepository.Object, _albumRepository.Object,
                _imageHelper.Object, _configurationHelper.Object, _fileHelper.Object);

            var result = _mediaLogic.Add(objParam, 1);

            Assert.NotNull(result);
        }