コード例 #1
0
        public void ValidateGetPublicUrl()
        {
            var storageConfiguration = new PiranhaS3StorageOptions
            {
                BucketName    = ValidUnitTestBucketName,
                KeyPrefix     = ValidUnitTestKeyPrefix,
                PublicUrlRoot = ValidUnitTestUriHost
            };
            S3Storage s3Storage = new S3Storage(storageConfiguration, null, null);

            // Test null id input
            var returnUri = s3Storage.GetPublicUrl(null);

            Assert.Null(returnUri);

            // Test empty id input
            returnUri = s3Storage.GetPublicUrl(" ");
            Assert.Null(returnUri);

            // Test Valid Url generation
            string testId = Guid.NewGuid().ToString();

            returnUri = s3Storage.GetPublicUrl(testId);
            var expectedUri = Url.Combine(ValidUnitTestUriHost, ValidUnitTestKeyPrefix, testId);

            Assert.Equal(expectedUri, returnUri);
        }
コード例 #2
0
        /// <summary>
        /// Contructor initializing test fixture.
        /// </summary>
        public BucketIntegrationFixture()
        {
            // Setup Configuration
            var configBuilder = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json", optional: false);
            var configuration = configBuilder.Build();

            AWSOptions options = configuration.GetAWSOptions();

            // S3 Configuration
            BucketName    = Environment.GetEnvironmentVariable("BUCKET_NAME");
            BucketWebsite = $"http://{BucketName}.s3-website.{options.Region.SystemName}.amazonaws.com/";

            var storageConfig = new PiranhaS3StorageOptions {
                BucketName    = BucketName,
                PublicUrlRoot = BucketWebsite
            };

            // Service Provider
            IServiceCollection services = new ServiceCollection();

            services.AddPiranhaS3StorageOptions(storageConfig);
            services.AddDefaultAWSOptions(configuration.GetAWSOptions());
            services.AddPiranhaS3Storage();
            services.AddAWSService <IAmazonS3>();
            var serviceProvider = services.BuildServiceProvider();

            // Get the services
            S3Storage = serviceProvider.GetService <IStorage>();
            S3Client  = serviceProvider.GetService <IAmazonS3>();
        }
 /// <summary>
 /// Validates <see cref="PiranhaS3StorageOptions"/> has the expected test values when
 /// not found.
 /// </summary>
 /// <param name="options">The <see cref="PiranhaS3StorageOptions"/> to test.</param>
 private void ValidateNullS3StorageOptions(PiranhaS3StorageOptions options)
 {
     Assert.NotNull(options);
     Assert.Null(options.BucketName);
     Assert.Null(options.KeyPrefix);
     Assert.Null(options.PublicUrlRoot);
 }
 /// <summary>
 /// Validates <see cref="PiranhaS3StorageOptions"/> has the expected test values.
 /// </summary>
 /// <param name="options">The <see cref="S3StorageOptions"/> to test.</param>
 private void ValidateS3StorageOptions(PiranhaS3StorageOptions options)
 {
     Assert.NotNull(options);
     Assert.Equal("BucketNameTest", options.BucketName);
     Assert.Equal("KeyPrefixTest", options.KeyPrefix);
     Assert.Equal("http://flagscript.technology", options.PublicUrlRoot);
 }
        public void TestGetStorageConfigurationBadPublicUrlRoot()
        {
            var noBucketStorageOptions = new PiranhaS3StorageOptions
            {
                BucketName    = ValidUnitTestBucketName,
                KeyPrefix     = ValidUnitTestKeyPrefix,
                PublicUrlRoot = "notaurl"
            };

            try
            {
                IServiceCollection services             = new ServiceCollection();
                var storageFactory                      = new S3StorageFactory(noBucketStorageOptions, TestFixture.FakeAwsOptions);
                Func <IServiceProvider, object> factory = storageFactory.CreateS3Storage;
                services.Add(new ServiceDescriptor(typeof(S3Storage), factory, ServiceLifetime.Singleton));
                var serviceProvider = services.BuildServiceProvider();

                serviceProvider.GetService <S3Storage>();
                Assert.False(true, "Bad PublicUrlRoot did not throw an exception");
            }
            catch (Exception ex)
            {
                Assert.IsAssignableFrom <FlagscriptConfigurationException>(ex);
            }
        }
コード例 #6
0
        public void TestPublicUrlPrefix()
        {
            var storageOptions = new PiranhaS3StorageOptions
            {
                PublicUrlRoot = "https://flagscript.technology",
                KeyPrefix     = "uploads"
            };

            Assert.Equal("https://flagscript.technology/uploads", storageOptions.PublicUrlPrefix);
        }