Esempio n. 1
0
        public void Should_Download_Object_Successfully()
        {
            string       path    = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Guid.NewGuid().ToString().Replace("-", string.Empty) + ".tmp");
            const string content = "test content";

            try
            {
                File.WriteAllText(path, content);
                var storageService = new FileSystemStorageService();
                var downloadUri    = new Uri(path);
                var download       = storageService.DownloadObject(downloadUri);
                Assert.AreEqual(download.Uri, downloadUri);
                using (TextReader reader = new StreamReader(download.ResponseStream))
                {
                    string contentFromStream = reader.ReadToEnd();
                    Assert.AreEqual(content, contentFromStream);
                }
            }
            finally
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }
Esempio n. 2
0
        public void Should_Check_That_File_Not_Exists()
        {
            var    storageService = new FileSystemStorageService();
            string filePath       = Path.Combine(@"C:\", "temp", Guid.NewGuid().ToString().Replace("-", string.Empty) + ".test");
            var    fileUri        = new Uri(filePath);

            storageService.ObjectExists(fileUri);
        }
Esempio n. 3
0
        public IStorageService CreateStorage()
        {
            IStorageService storage;

            if (_config.Type == "fs")
            {
                storage = new FileSystemStorageService(
                    _config.Location,
                    _loggerFactory.CreateLogger <FileSystemStorageService>());
            }
            else
            {
                throw new ArgumentException("undefined storage type");
            }
            return(storage);
        }
Esempio n. 4
0
        public void Should_Throw_StorageException_If_Given_Uri_Is_Not_Of_File_Scheme()
        {
            var httpUri        = new Uri("http://www.google.com");
            var storageService = new FileSystemStorageService();

            var ex1 = Assert.Throws <StorageException>(() => storageService.ObjectExists(httpUri));
            var ex2 = Assert.Throws <StorageException>(() => storageService.CopyObject(httpUri, httpUri));
            var ex3 = Assert.Throws <StorageException>(() => storageService.DownloadObject(httpUri));
            var ex4 = Assert.Throws <StorageException>(() => storageService.UploadObject(new UploadRequest {
                Uri = httpUri
            }));

            Assert.IsTrue(ex1.Message.StartsWith("An Uri scheme") && ex1.Message.Contains("can't be processed with a"));
            Assert.IsTrue(ex2.Message.StartsWith("An Uri scheme") && ex1.Message.Contains("can't be processed with a"));
            Assert.IsTrue(ex3.Message.StartsWith("An Uri scheme") && ex1.Message.Contains("can't be processed with a"));
            Assert.IsTrue(ex4.Message.StartsWith("An Uri scheme") && ex1.Message.Contains("can't be processed with a"));
        }
Esempio n. 5
0
        public MainRibbonForm()
        {
            //holi
            InitializeComponent();
            LoadSkin();
            tabControl.ShowTabHeader = DevExpress.Utils.DefaultBoolean.False;
            Text = Application.ProductName;
            var scanService = new FileSystemScanService()
            {
                UserName      = System.Security.Principal.WindowsIdentity.GetCurrent().Name,
                ComputerName  = Environment.MachineName,
                OSVersionName = Environment.OSVersion.ToString(),
                ScanDate      = DateTime.Now,
                DetailType    = API.Enums.ScanDetailTypeEnum.Fast
            };
            var storageService = new FileSystemStorageService();

            ViewModel = new ViewModels.MainFormViewModel(scanService, storageService);
            SetEventHandlers();
        }
Esempio n. 6
0
        public void Should_Upload_Object_Successfully()
        {
            string       path    = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test", Guid.NewGuid().ToString().Replace("-", string.Empty) + ".tmp");
            const string content = "test content";

            try
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    using (TextWriter writer = new StreamWriter(memoryStream))
                    {
                        writer.Write(content);
                        writer.Flush();

                        FileSystemStorageService storageService = new FileSystemStorageService();
                        storageService.UploadObject(
                            new UploadRequest
                        {
                            Uri             = new Uri(path),
                            InputStream     = memoryStream,
                            CreateDirectory = true
                        });

                        Assert.IsTrue(File.Exists(path));
                        Assert.AreEqual(content, File.ReadAllText(path));
                    }
                }
            }
            finally
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }