Exemplo n.º 1
0
        public string Save(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                throw new ArgumentException(Resources.TextMessages.FileIsEmpty);
            }

            if (file.Length > _maxFileSize)
            {
                throw new ArgumentException
                      (
                          string.Format(Resources.TextMessages.FileIsTooBig, FriendlyConvert.BytesToString(_maxFileSize))
                      );
            }

            CheckFileStorageDirectory(_fileStorage);

            var filename = GenerateFileName() + Path.GetExtension(file.FileName);

            var fullPath = Path.Combine(_fileStorage, filename);

            using (var stream = new FileStream(fullPath, FileMode.Create))
            {
                file.CopyTo(stream);
            }

            return(filename);
        }
 public void BytesToString_InValid(long bytes, string[] suffices)
 {
     Assert.Throws <ArgumentException>(() => FriendlyConvert.BytesToString(bytes, suffices));
 }
        public void BytesToString_ValidLocalized(long bytes, string[] suffices, string expected)
        {
            var result = FriendlyConvert.BytesToString(bytes, suffices);

            Assert.Equal(expected, result);
        }