-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAdminTasks.cs
71 lines (62 loc) · 2.1 KB
/
AdminTasks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Linq;
using NUnit.Framework;
using ServiceStack;
using ServiceStack.Aws.DynamoDb;
using ServiceStack.Aws.S3;
using ServiceStack.Configuration;
using ServiceStack.Testing;
using ServiceStack.Text;
using ServiceStack.VirtualPath;
namespace AwsApps
{
[TestFixture]
public class AdminTasks
{
private readonly ServiceStackHost appHost;
S3VirtualPathProvider s3;
public AdminTasks()
{
appHost = new BasicAppHost().Init();
s3 = AwsConfig.CreateS3VirtualPathProvider(appHost, AwsConfig.S3BucketName);
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
appHost.Dispose();
}
[Test]
public void Drop_and_Create_ssawsdemo_Bucket()
{
try
{
s3.ClearBucket();
s3.AmazonS3.DeleteBucket(AwsConfig.S3BucketName);
}
catch { }
s3.AmazonS3.PutBucket(AwsConfig.S3BucketName);
}
[Test]
public void Import_RestFiles_into_S3()
{
var fs = new FileSystemVirtualPathProvider(appHost, "~/restfiles".MapHostAbsolutePath());
var skipDirs = new[] { "restfiles/files" };
foreach (var file in fs.GetAllFiles())
{
if (skipDirs.Any(x => file.VirtualPath.StartsWith(x))) continue;
s3.WriteFile(file, "restfiles/files".CombineWith(file.VirtualPath));
}
}
[Test]
public void Import_AppSettings_into_DynamoDb()
{
var fileSettings = new TextFileSettings("~/../../deploy/appsettings.txt".MapHostAbsolutePath());
var dynamoSettings = new DynamoDbAppSettings(AwsConfig.CreatePocoDynamo());
dynamoSettings.InitSchema();
//dynamoSettings.Set("SmtpConfig", "{Username:REPLACE_USER,Password:REPLACE_PASS,Host:email-smtp.us-east-1.amazonaws.com,Port:587}");
foreach (var config in fileSettings.GetAll())
{
dynamoSettings.Set(config.Key, config.Value);
}
}
}
}