public async Task Process()
        {
            var bytes = File.ReadAllBytes(Environment.CurrentDirectory + @"\icon.png");

            var versions = this.Versions();
            var version = versions.Values.First();

            var queued = new ImageQueued
            {
                Identifier = Guid.NewGuid(),
                OriginalExtension = Naming.DefaultExtension,
                
            };
            queued.FileNameFormat = queued.Identifier.ToString() + "_{0}.{1}";

            await this.container.Save(string.Format("{0}_original.jpeg", queued.Identifier), bytes);

            var store = new DataStore(connectionString);

            var processor = new Processor(new DataStore(connectionString), versions);
            await processor.Process(queued);

            var data = await this.container.Get(string.Format("{0}_test.gif", queued.Identifier));
            Assert.IsNotNull(data);

            var entities = await this.table.QueryByRow<ImageEntity>("test");
            var entity = entities.FirstOrDefault();

            Assert.IsNotNull(entity);
            Assert.AreEqual(version.Format.MimeType, entity.MimeType);
            Assert.AreEqual(string.Format(Naming.PathFormat, this.container.Name, entity.FileName), entity.RelativePath);
        }
        public void FileNameFormat()
        {
            var expected = Guid.NewGuid().ToString();
            var data = new ImageQueued()
            {
                FileNameFormat = expected
            };

            Assert.AreEqual(expected, data.FileNameFormat);
        }
        public void OriginalExtension()
        {
            var expected = Guid.NewGuid().ToString();
            var data = new ImageQueued()
            {
                OriginalExtension = expected
            };

            Assert.AreEqual(expected, data.OriginalExtension);
        }
        public void Identifier()
        {
            var expected = Guid.NewGuid();
            var data = new ImageQueued()
            {
                Identifier = expected
            };

            Assert.AreEqual(expected, data.Identifier);
        }
        public async Task Process()
        {
            var bytes = File.ReadAllBytes(Environment.CurrentDirectory + @"\icon.png");
            var data = new ImageQueued()
            {
                Identifier = Guid.NewGuid(),
                FileNameFormat = "good_{0}_file",
                OriginalExtension = string.Empty,
            };
            var versions = new Dictionary<string, IImageVersion>();
            var version = new ImageVersion()
            {
                Width = 100,
                Height = 100,
                Format = new JpegFormat { Quality = 70 },
            };
            versions.Add("temp", version);
            var fileName = string.Format(data.FileNameFormat, "temp");
            var original = string.Format(data.FileNameFormat, Naming.Original);

            var imaging = Substitute.For<IImaging>();
            imaging.Resize(bytes, version).Returns(bytes);
            var naming = Substitute.For<INaming>();
            naming.OriginalFileName(data).Returns(original);
            naming.FileName(data, "temp", version.Format.DefaultExtension).Returns(fileName);
            var streamer = Substitute.For<IStreamer>();
            streamer.Bytes(original).Returns(Task.FromResult(bytes));
            var store = Substitute.For<IDataStore>();
            store.Streamer.Returns(streamer);
            store.Save(fileName, bytes, "temp", version.Format.MimeType, data.Identifier, false, null, (byte)version.Format.Quality);

            var ip = new Processor(store, versions, imaging, naming);
            var result = await ip.Process(data);

            Assert.IsTrue(result);

            imaging.Received().Resize(bytes, version);
            naming.Received().OriginalFileName(data);
            naming.Received().FileName(data, "temp", version.Format.DefaultExtension);
            streamer.Received().Bytes(original);
            var s = store.Streamer.Received();
            store.Received().Save(fileName, bytes, "temp", version.Format.MimeType, data.Identifier, false, null, (byte)version.Format.Quality);
        }
Exemplo n.º 6
0
 /// <summary>
 /// File Name for Image Queued
 /// </summary>
 /// <param name="data">Image Queued</param>
 /// <param name="key">Version Key</param>
 /// <param name="extension">Extension</param>
 /// <returns>File Name</returns>
 public virtual string FileName(ImageQueued data, string key, string extension)
 {
     return string.Format(data.FileNameFormat, key, extension).ToLowerInvariant();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Original File Name
 /// </summary>
 /// <param name="data">Image Queued</param>
 /// <returns>Original File Name</returns>
 public virtual string OriginalFileName(ImageQueued data)
 {
     return string.Format(data.FileNameFormat, Original, data.OriginalExtension).ToLowerInvariant();
 }