protected static void ResetComponents() { client = null; fileSystem = null; factory = null; storage = null; }
public void SetupFixture() { _amazonS3Client = new AmazonS3Client(); _amazonS3Storage = new AmazonS3Storage(_amazonS3Client, _bucketName); UploadTestFile(_testFilePath); }
protected static void InitializeComponents() { client = new Mock<AmazonS3Client>(); fileSystem = new Mock<IFileSystem>(); factory = new AmazonS3RequestFactory(Bucket); storage = new AmazonS3Storage(client.Object, factory, fileSystem.Object, Bucket); }
private void storeString(AmazonS3Storage s3, string key, string value) { MemoryStream mems = new MemoryStream(); Encoding enc = new UTF8Encoding(false); StreamWriter writer = new StreamWriter(mems, enc); writer.Write(value); writer.Flush(); s3.Store(key, mems, "text/plain"); }
public void TestStoreStuffOnAmazon() { var s3 = new AmazonS3Storage(); s3.Open(); s3.DeleteAll(); var names = s3.ListNames(); Assert.AreEqual(0, names.Length); storeString(s3, "blob1", "Hello, world!"); storeString(s3, "blob2", "Gangnam style"); storeString(s3, "blob3", "All your base are belong to us"); names = s3.ListNames(); CollectionAssert.Contains(names, "blob1"); CollectionAssert.Contains(names, "blob2"); CollectionAssert.Contains(names, "blob3"); Assert.AreEqual(3, names.Length); s3.Delete("blob3"); names = s3.ListNames(); CollectionAssert.Contains(names, "blob1"); CollectionAssert.Contains(names, "blob2"); Assert.AreEqual(2, names.Length); s3.Delete("blob3"); // No exception, please names = s3.ListNames(); CollectionAssert.Contains(names, "blob1"); CollectionAssert.Contains(names, "blob2"); Assert.AreEqual(2, names.Length); storeString(s3, "blob3", "20 Return 10"); storeString(s3, "blob3", "10 Goto 20"); // No exception, please string contentType; byte[] data = s3.Fetch("blob3", out contentType); string output = Encoding.UTF8.GetString(data); Assert.AreEqual("10 Goto 20", output); names = s3.ListNames(); CollectionAssert.Contains(names, "blob1"); CollectionAssert.Contains(names, "blob2"); CollectionAssert.Contains(names, "blob3"); Assert.AreEqual(3, names.Length); s3.Close(); }
public void TestBatchRemoval() { _store.EraseData(); byte[] data = UTF8Encoding.UTF8.GetBytes("Hello world!"); ResourceEntry <Binary> e = new ResourceEntry <Binary>(); e.AuthorName = "Ewout"; e.Resource = new Binary { Content = data, ContentType = "text/plain" }; var rl = ResourceLocation.Build("binary", "3141"); e.Id = rl.ToUri(); rl.VersionId = "1"; e.SelfLink = rl.ToUri(); var batchGuid = Guid.NewGuid(); ResourceEntry <Binary> result = (ResourceEntry <Binary>)_store.AddEntry(e, batchGuid); // Store 5 others with another batchguid batchGuid = Guid.NewGuid(); for (int i = 0; i < 5; i++) { rl = ResourceLocation.Build("binary", (10 + i).ToString()); e.Id = rl.ToUri(); rl.VersionId = "1"; e.SelfLink = rl.ToUri(); result = (ResourceEntry <Binary>)_store.AddEntry(e, batchGuid); } _store.PurgeBatch(batchGuid); var result2 = _store.ListCollection("binary"); Assert.AreEqual(1, result2.Count()); Assert.AreEqual("3141", ResourceLocation.GetIdFromResourceId(result2.First().Id)); using (var s3 = new AmazonS3Storage()) { s3.Open(); var names = s3.ListNames(); Assert.AreEqual(1, names.Length); Assert.IsTrue(names.First().Contains("3141")); } }
static void RenderTestFile(string fileName, string bucket, AmazonS3Client client) { var storage = new AmazonS3Storage(client, bucket); var config = new ViewerConfig { EnableCaching = true }; var viewer = new ViewerHtmlHandler(config, storage); var pages = viewer.GetPages(fileName); viewer.ClearCache(fileName); foreach (var page in pages) { Console.WriteLine(page.HtmlContent); } }
public void TestBatchRemoval() { _store.EraseData(); byte[] data = UTF8Encoding.UTF8.GetBytes("Hello world!"); ResourceEntry<Binary> e = new ResourceEntry<Binary>(); e.AuthorName = "Ewout"; e.Resource = new Binary { Content = data, ContentType = "text/plain" }; var rl = ResourceLocation.Build("binary", "3141"); e.Id = rl.ToUri(); rl.VersionId = "1"; e.SelfLink = rl.ToUri(); var batchGuid = Guid.NewGuid(); ResourceEntry<Binary> result = (ResourceEntry<Binary>)_store.AddEntry(e, batchGuid); // Store 5 others with another batchguid batchGuid = Guid.NewGuid(); for (int i = 0; i < 5; i++) { rl = ResourceLocation.Build("binary", (10+i).ToString()); e.Id = rl.ToUri(); rl.VersionId = "1"; e.SelfLink = rl.ToUri(); result = (ResourceEntry<Binary>)_store.AddEntry(e, batchGuid); } _store.PurgeBatch(batchGuid); var result2 = _store.ListCollection("binary"); Assert.AreEqual(1, result2.Count()); Assert.AreEqual("3141", ResourceLocation.GetIdFromResourceId(result2.First().Id)); using (var s3 = new AmazonS3Storage()) { s3.Open(); var names = s3.ListNames(); Assert.AreEqual(1, names.Length); Assert.IsTrue(names.First().Contains("3141")); } }