Esempio n. 1
0
        public static IProxy Create(RuntimeContext context, ProxyOptions options)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            switch (options.Mode)
            {
            case ProxyMode.DataCapture:
                return(new CaptureProxy(context, options));

            case ProxyMode.DataReplay:
                return(new ReplayProxy(context, options));

            case ProxyMode.DataPassthrough:
                return(new NullProxy(context, options));

            default:
                throw new ArgumentOutOfRangeException(nameof(options.Mode));
            }
        }
Esempio n. 2
0
 internal NullProxy(RuntimeContext context, ProxyOptions options)
     : base(context, options)
 {
     if (options.Mode != ProxyMode.DataPassthrough)
     {
         throw new ArgumentException($"`{GetType().Name}` requires `{nameof(ProxyOptions.Mode)} = {ProxyMode.DataPassthrough}`");
     }
 }
Esempio n. 3
0
        public ReplayProxy(RuntimeContext context, ProxyOptions options)
            : base(context, options)
        {
            if (options.Mode != ProxyMode.DataReplay)
            {
                throw new ArgumentException($"`{GetType().Name}` requires `{nameof(ProxyOptions.Mode)} = {ProxyMode.DataReplay}`");
            }

            SetService <INetwork>(new ReplayNetwork(context));
            SetService <ISettings>(new ReplaySettings(context, NormalizePath));
            SetService <IStorage>(new ReplayStorage(context, NormalizePath));
        }
Esempio n. 4
0
        protected Proxy(RuntimeContext context, ProxyOptions options)
        {
            _context = context;

            _data           = new ProxyData();
            _mode           = options.Mode;
            _options        = options;
            _services       = new ConcurrentDictionary <Type, object>();
            _storageFilters = new ConcurrentDictionary <string, string>(Ordinal);

            SetService(_context.Network);
            SetService(_context.Settings);
            SetService(_context.Storage);
        }
Esempio n. 5
0
        protected virtual void InitializeTest(int iteration = -1, [CallerMemberName] string testName = "")
        {
            if (string.IsNullOrWhiteSpace(testName))
            {
                throw new ArgumentNullException(nameof(testName));
            }

            lock (_syncpoint)
            {
                if (_initialized)
                {
                    throw new InvalidOperationException("Test already initialized.");
                }

                _iteration = iteration;

                InitializeTestPaths(testName);

                var projectDirectory = Path.Combine(_solutionDirectory, _projectDirectory);
                var options          = new ProxyOptions(Translate(TestMode), _solutionDirectory, projectDirectory)
                {
                    FauxPrefixPath = FauxDataSolutionPath,
                    FauxResultPath = FauxDataResultPath,
                    FauxHomePath   = FauxDataHomePath,
                };

                if (_proxy is null)
                {
                    _proxy = Test.Proxy.Create(Context, options);
                }

                switch (TestMode)
                {
                case UnitTestMode.Capture:
                {
                    _proxy.Data.ResultPath  = Path.Combine(projectDirectory, TestResultDirectoryName);
                    _proxy.Data.DisplayName = _testName;
                }
                break;

                case UnitTestMode.Replay:
                {
                    using (var readableStream = File.Open(_testDataFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        _proxy.ReadTestData(readableStream);
                    }

                    _proxy.Data.ResultPath = FauxDataResultPath;
                }
                break;

                case UnitTestMode.NoProxy:
                    break;

                default:
                    throw new InvalidOperationException($"`{TestMode}` is an undefined value for `{typeof(UnitTestMode).FullName}`.");
                }

                _initialized = true;
            }
        }