Beispiel #1
0
        public void OnCondition(GatewaySection config, GatewayCapabilities capability, Action action)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var capabilityExcluded = config.Exclusions.HasFlag(capability);

            try
            {
                action();
                Assert.IsFalse(capabilityExcluded, $"Unexpected capability {capability}".ToString(CultureInfo.CurrentCulture));
            }
            catch (NotSupportedException) when(capabilityExcluded)
            {
                // Ignore NotSupportedException
            }
            catch (AggregateException ex) when(capabilityExcluded && ex.InnerExceptions.Count == 1 && ex.InnerException is NotSupportedException)
            {
                // Ignore AggregateException containing a single NotSupportedException
            }
        }
Beispiel #2
0
        public RootName GetRootName(GatewaySection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            return(new RootName(config.Schema, config.UserName, config.Mount));
        }
Beispiel #3
0
 public IAsyncCloudGateway GetAsyncGateway(GatewaySection config)
 {
     if (!AsyncGateways.ContainsKey(config.Schema))
     {
         switch (config.Schema)
         {
         case "async":
             AsyncGateways[config.Schema] = new Moq.Mock <IAsyncCloudGateway>().Object;
             break;
         }
     }
     return(AsyncGateways[config.Schema]);
 }
Beispiel #4
0
 public ICloudGateway GetGateway(GatewaySection config)
 {
     if (!Gateways.ContainsKey(config.Schema))
     {
         switch (config.Schema)
         {
         //case "file":
         //    Gateways[config.Schema] = new Gateways.File.FileGateway();
         //    break;
         case "memory":
             Gateways[config.Schema] = new Gateways.Memory.MemoryGateway();
             break;
         }
     }
     return(Gateways[config.Schema]);
 }
Beispiel #5
0
        public IDictionary <string, string> GetParameters(GatewaySection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var parameters = config.Parameters;

            if (string.IsNullOrEmpty(parameters))
            {
                return(null);
            }

            var result = new Dictionary <string, string>();

            foreach (var parameter in parameters.Split('|'))
            {
                var components = parameter.Split(new[] { '=' }, 2);
                result.Add(components[0], components.Length == 2 ? components[1] : null);
            }

            return(result);
        }
Beispiel #6
0
 internal static TestDirectoryFixture CreateTestDirectory(ICloudGateway gateway, GatewaySection config, GatewayTestsFixture fixture)
 {
     return(new TestDirectoryFixture(gateway, fixture.GetRootName(config), config.ApiKey, fixture.GetParameters(config), config.TestDirectory));
 }
Beispiel #7
0
        void CallTimedTestOnConfig <TGateway>(Action <TGateway, RootName, GatewaySection> test, GatewaySection config, Func <GatewaySection, TGateway> getGateway, IDictionary <string, Exception> failures)
        {
            try
            {
                var startedAt = DateTime.Now;
                var gateway   = getGateway(config);
                var rootName  = GetRootName(config);
                test(gateway, rootName, config);
                var completedAt = DateTime.Now;
                Log($"Test for schema '{config.Schema}' completed in {completedAt - startedAt}".ToString(CultureInfo.CurrentCulture));
            }
            catch (Exception ex)
            {
                var aggregateException = ex as AggregateException;
                var message            = aggregateException != null?string.Join(", ", aggregateException.InnerExceptions.Select(e => e.Message)) : ex.Message;

                Log($"Test for schema '{config.Schema}' failed:\n\t {message}".ToString(CultureInfo.CurrentCulture));
                failures.Add(config.Schema, ex);
            }
        }