Example #1
0
 public ShipsBundle()
 {
     Bomber = new Bomber();
     Carrier = new Carrier();
     Fighter = new Fighter();
     Interceptor = new Interceptor();
     Juggernaut = new Juggernaut();
     Scout = new Scout();
 }
        public void Interceptor_AddInterceptorTwiceTest()
        {
            var collection = new InterceptorCollection();
            var orig = new Interceptor<Order>();
            collection.Add(orig);
            var second = collection.Add(new Interceptor<Order>());

            Assert.AreNotSame(orig, second);
        }
        public void Interceptor_AddInterceptorTest()
        {
            var collection = new InterceptorCollection();
            var orig = new Interceptor<Order>();
            collection.Add(orig);

            var reference = collection.GetInterceptor<Order>();

            Assert.AreSame(orig, reference);
        }
Example #4
0
        public void DoNotIntercept()
        {
            CheckDispose();

            if (Interceptor != null)
            {
                Interceptor.Dispose();
                Interceptor = null;
            }

            *m_pInterceptCallback = IntPtr.Zero;
        }
Example #5
0
        public void ProxyGenerator_CreateInterfaceProxyWithoutTarget_can_create_delegate_proxy_without_target()
        {
            var options = new ProxyGenerationOptions();

            options.AddDelegateTypeMixin(typeof(Action));
            var _     = new Interceptor();
            var proxy = generator.CreateInterfaceProxyWithoutTarget(
                typeof(IComparable),
                options,
                _
                );
        }
Example #6
0
        public static void Property()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(m => m.Dummy)
                       .Returns(4);

            mock.As <IUnmockable <SomeUnmockableObject> >()
            .Execute(m => m.Dummy);

            mock.Verify();
        }
Example #7
0
        public static async Task NoResultAsync()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(m => m.FooAsync());

            await mock.As <IUnmockable <SomeUnmockableObject> >()
            .Invoking(x => x.Execute(m => m.FooAsync()))
            .Should()
            .ThrowAsync <UninitializedException>()
            .WithMessage("FooAsync()");
        }
Example #8
0
        public static void NoResult()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(m => m.Foo());

            mock.As <IUnmockable <SomeUnmockableObject> >()
            .Invoking(x => x.Execute(m => m.Foo()))
            .Should()
            .Throw <UninitializedException>()
            .WithMessage("Foo()");
        }
Example #9
0
        public static void NoSetupEnumerable()
        {
            var items = new[] { 1, 2, 3, 4 };

            Interceptor
            .For <SomeUnmockableObject>()
            .As <IUnmockable <SomeUnmockableObject> >()
            .Invoking(x => x.Execute(m => m.Foo(items)))
            .Should()
            .Throw <SetupNotFoundException>()
            .WithMessage("Foo([1, 2, 3, 4])");
        }
Example #10
0
        public static void WithException()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(m => m.Foo(Arg.With <int>(x => x.Should().Be(3, ""))))
                       .Returns(5);

            mock.As <IUnmockable <SomeUnmockableObject> >()
            .Invoking(x => x.Execute(m => m.Foo(13)))
            .Should()
            .Throw <XunitException>();
        }
Example #11
0
        protected override async Task OnInitializedAsync()
        {
            Interceptor.RegisterEvent();
            noTextToDisplay = _localizer[LangKey.NO_DATA_TO_DISPLAY];

            var result = await _apiWrapper.ExchangeSettings.GetAllAsync(TenantId, _search);

            if (result.IsSuccess && result.Error == null)
            {
                _dataSource = result.Data;
            }
        }
Example #12
0
        /* Constructor */
        public MainForm()
        {
            InitializeComponent();

            // Create macro player
            m_MacroPlayer = new MacroPlayer();
            m_MacroPlayer.PropertyChanged += MacroPlayer_PropertyChanged;

            // Set control mode
            SetControlMode(ControlMode.Macro);

            // Create save/load helper
            m_SaveLoadHelper = new SaveLoadHelper(this, m_MacroPlayer);
            m_SaveLoadHelper.PropertyChanged += SaveLoadHelper_PropertyChanged;

            // Enable watchdog based on settings
            if (!Program.Settings.AutoInject)
            {
                Interceptor.InjectionMode = InjectionMode.Compatibility;
            }

            // Attempt to inject into PS4 Remote Play
            try
            {
                Interceptor.Inject();
            }
            // Injection failed
            catch (InterceptorException ex)
            {
                // Only handle when PS4 Remote Play is in used by another injection
                if (ex.InnerException != null && ex.InnerException.Message.Equals("STATUS_INTERNAL_ERROR: Unknown error in injected C++ completion routine. (Code: 15)"))
                {
                    MessageBox.Show("The process has been injected by another executable. Restart PS4 Remote Play and try again.", "Injection Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(-1);
                }
                else
                {
                    // Handle exception if watchdog is disabled
                    if (!Program.Settings.AutoInject)
                    {
                        MessageBox.Show(string.Format("[{0}] - {1}", ex.GetType().ToString(), ex.Message), "Injection Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Environment.Exit(-1);
                    }
                }
            }

            // Start watchdog to automatically inject when possible
            if (Program.Settings.AutoInject)
            {
                Interceptor.Watchdog.Start();
            }
        }
Example #13
0
        /// <summary>
        ///     Register a component
        /// </summary>
        /// <param name="type"></param>
        /// <param name="life"></param>
        /// <param name="interceptor"></param>
        /// <param name="keyedInterfaceType"></param>
        public void RegisterComponent(Type type, LifeStyle life = LifeStyle.Singleton,
                                      Interceptor interceptor   = Interceptor.None)
        {
            var builder = new ContainerBuilder();

            if (type.IsGenericType)
            {
                var registration = builder.RegisterGeneric(type).PropertiesAutowired().WithAttributeFiltering();

                foreach (var interfaceType in type.GetInterfaces())
                {
                    if (interfaceType.IsGenericType)
                    {
                        //registration = keyedInterfaceType != null && keyedInterfaceType==interfaceType.GetGenericTypeDefinition()
                        //    ? registration.Keyed(keyedInterfaceType, interfaceType.GetGenericTypeDefinition()).PropertiesAutowired()
                        //    : registration.As(interfaceType.GetGenericTypeDefinition()).PropertiesAutowired();
                        registration = registration.As(interfaceType.GetGenericTypeDefinition()).PropertiesAutowired().WithAttributeFiltering();
                    }
                }

                SetMeta(type, registration);
                SetLifetimeScope(life, registration);
                SetIntercepter(interceptor, registration);
            }
            else
            {
                var registration = builder.RegisterType(type).PropertiesAutowired().WithAttributeFiltering();

                var interfaceTypes = type.GetInterfaces();
                if (interfaceTypes.Any())
                {
                    foreach (var interfaceType in type.GetInterfaces())
                    {
                        //registration = keyedInterfaceType != null&& keyedInterfaceType == interfaceType
                        //    ? registration.Keyed(keyedInterfaceType, interfaceType).PropertiesAutowired()
                        //    : registration.As(interfaceType).PropertiesAutowired();
                        registration = registration.As(interfaceType).PropertiesAutowired().WithAttributeFiltering();
                    }
                }
                else
                {
                    registration = builder.RegisterType(type).PropertiesAutowired().AsSelf();
                }


                SetMeta(type, registration);
                SetLifetimeScope(life, registration);
                SetIntercepter(interceptor, registration);
            }

            builder.Update(Container);
        }
Example #14
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="port"></param>
        /// <param name="logger"></param>
        public PluginServiceServer(int port, ILogger logger)
        {
            Port   = port;
            Logger = logger;

            Interceptor = new PluginGrpcInterceptor(Logger);

            m_server = new Server(GrpcPluginSettings.GetChannelOptions())
            {
                Services = { PluginService.BindService(this).Intercept(Interceptor) },
                Ports    = { new ServerPort(IPAddress.Loopback.ToString(), Port, ServerCredentials.Insecure) },
            };
        }
        public void Release(Interceptor interceptor)
        {
            if (interceptor == null)
            {
                throw new ArgumentNullException(nameof(interceptor));
            }

            if (interceptor is IDisposable disposableInterceptor && _createdInterceptors != null && _createdInterceptors.Contains(interceptor))
            {
                _createdInterceptors.Remove(interceptor);
                disposableInterceptor.Dispose();
            }
        }
Example #16
0
        private void StartReaderLoop()
        {
            var thread = new Thread(() =>
            {
                while (!Disconnected)
                {
                    var buf = ReadNextPacket(out int packetId);
                    Interceptor?.OnClientPacket(packetId, buf);
                }
            });

            thread.Start();
        }
Example #17
0
        private void StartIntercepting()
        {
            this.intercepting = true;
            var cryptoHandler = new PassiveCryptoHandler();

            cryptoHandler.WorkingKeyDefined += this.OnWorkingKeyDefined;
            var virtualDevice = new DecryptedDevice(cryptoHandler, new SerialDevice(this.UxComboVirtualCom.Text));
            var realDevice    = new DecryptedDevice(cryptoHandler, new SerialDevice(this.UxComboRealCom.Text));

            this.interceptor           = new Interceptor(virtualDevice, realDevice);
            this.interceptor.Request  += this.OnRequest;
            this.interceptor.Response += this.OnResponse;
        }
Example #18
0
        public static void MultipleNotExecuted()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(m => m.Foo())
                       .Returns(3)
                       .Then(4);

            mock.Invoking(x => x.Verify())
            .Should()
            .Throw <NotExecutedException>()
            .WithMessage("Foo(): 3, 4");
        }
        public void When_using_CreateInterfaceProxyWithTargetInterface_Invocation_TargetType_is_equal_to_type_of_target()
        {
            var interceptor = new Interceptor();

            var proxy = generator.CreateInterfaceProxyWithTargetInterface <IFoo>(
                new FooTarget(),
                interceptor
                );

            proxy.Method();

            Assert.AreEqual(typeof(FooTarget), interceptor.ReceivedTargetType);
        }
Example #20
0
        public static void IgnoreArgument()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(m => m.Foo(Arg.Ignore <int>()))
                       .Returns(5);

            mock.As <IUnmockable <SomeUnmockableObject> >()
            .Execute(x => x.Foo(13))
            .Should()
            .Be(5);

            mock.Verify();
        }
Example #21
0
        public static void NullArgument()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(m => m.Foo(3, null))
                       .Returns(5);

            mock.As <IUnmockable <SomeUnmockableObject> >()
            .Execute(x => x.Foo(3, null))
            .Should()
            .Be(5);

            mock.Verify();
        }
Example #22
0
            internal DirectoryServiceFailOnSearch(LdapAuthIT outerInstance)
            {
                this._outerInstance     = outerInstance;
                FailOnSearchInterceptor = new BaseInterceptorAnonymousInnerClass(this);

                try
                {
                    Service.addFirst(FailOnSearchInterceptor);
                }
                catch (LdapException e)
                {
                    throw new Exception(e);
                }
            }
Example #23
0
            internal DirectoryServiceWaitOnSearch(LdapAuthIT outerInstance, long waitingTimeMillis)
            {
                this._outerInstance     = outerInstance;
                WaitOnSearchInterceptor = new BaseInterceptorAnonymousInnerClass(this, waitingTimeMillis);

                try
                {
                    Service.addFirst(WaitOnSearchInterceptor);
                }
                catch (LdapException e)
                {
                    throw new Exception(e);
                }
            }
        public void interceptors_should_not_be_executed_if_instance_is_chached()
        {
            var interceptor = new Interceptor();

            var container = new Container(x => x.For<object>().Use<object>()
                .Intercept(interceptor)
                .Lifetime.Singleton());

            interceptor.ExecuteCount.Should().Be(0);
            container.Get<object>();
            interceptor.ExecuteCount.Should().Be(1);
            container.Get<object>();
            interceptor.ExecuteCount.Should().Be(1);
        }
Example #25
0
        private static void InitialFactories()
        {
            var policy     = new InterceptionBehavior <PolicyInjectionBehavior>();
            var intercptor = new Interceptor <TransparentProxyInterceptor>();
            var type       = typeof(ServiceFactory);

            Container.Current.RegisterType(
                typeof(IServiceFactory),
                type,
                new ContainerControlledLifetimeManager(),
                policy,
                intercptor
                );
        }
Example #26
0
        public static async Task FuncAsyncThrows()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(x => x.FooAsync())
                       .Throws <FileNotFoundException>();

            await mock.As <IUnmockable <SomeUnmockableObject> >()
            .Invoking(x => x.Execute(m => m.FooAsync()))
            .Should()
            .ThrowAsync <FileNotFoundException>();

            mock.Verify();
        }
Example #27
0
        public static void With()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(m => m.Foo(Arg.With <int>(x => x.Should().Be(3, "that's what it's always been"))))
                       .Returns(5);

            mock.As <IUnmockable <SomeUnmockableObject> >()
            .Execute(x => x.Foo(3))
            .Should()
            .Be(5);

            mock.Verify();
        }
        /// <summary>
        /// Creates a new object instance according to the lifetime manager's properties.
        /// If the target type is decorated with the <see cref="InterceptedAttribute"/>,
        /// it is automatically intercepted.
        /// </summary>
        /// <returns></returns>
        protected virtual object CreateObjectInstance()
        {
            var instance = ConfigurationHelper.CreateInstance(
                ServiceObjectType,
                ConstructionParameters,
                Properties);

            if (ServiceObjectType.GetCustomAttributes(typeof(InterceptedAttribute), true).Length > 0 &&
                ServiceObjectType.GetCustomAttributes(typeof(DisableInterceptionAttribute), false).Length == 0)
            {
                // --- This is an intercepted object
                instance = Interceptor.GetInterceptedObject(ServiceType, instance, null);
            }
            return(instance);
        }
Example #29
0
        /// <summary>
        /// Detach from the logging event source.
        /// Implicitly take a snapshot.
        /// </summary>
        public void Detach()
        {
            if (_appender == null)
            {
                throw new InvalidOperationException("Not attached");
            }

            // RemoveAppender throws an exception if the appender
            // to be removed is not in the list of appenders!
            Interceptor.RemoveAppender(_appender);

            TakeSnapshot();

            _appender = null;
        }
Example #30
0
        public static void Execute()
        {
            var args = new Stack <int>();

            Interceptor
            .For <SomeUnmockableObject>()
            .Setup(y => y.Foo(Arg.With <int>(x => args.Push(x))))
            .Returns(3)
            .Execute(y => y.Foo(3))
            .Should()
            .Be(3);

            args.Should()
            .BeEquivalentTo(3);
        }
Example #31
0
        public static void ActionThrows()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(m => m.Bar(5))
                       .Throws <FileNotFoundException>();

            mock
            .As <IUnmockable <SomeUnmockableObject> >()
            .Invoking(x => x.Execute(m => m.Bar(5)))
            .Should()
            .Throw <FileNotFoundException>();

            mock.Verify();
        }
Example #32
0
        public static IUnityContainer RegisterComponents()
        {
            var container = new UnityContainer();

            container.AddNewExtension <Interception>();

            var interceptor = new Interceptor <InterfaceInterceptor>();
            var behaver     = new InterceptionBehavior <LoggingInterceptionBehavior>();

            container.RegisterType <DbContext, DatabaseContext>(new HierarchicalLifetimeManager());

            container.RegisterType(typeof(IRepository <>), typeof(EfRepository <>));

            return(container);
        }
Example #33
0
        public static void MoreInvocationsOnSingleResult()
        {
            var mock = Interceptor
                       .For <SomeUnmockableObject>()
                       .Setup(m => m.Foo())
                       .Returns(3);

            var sut = mock.As <IUnmockable <SomeUnmockableObject> >();

            sut.Execute(m => m.Foo())
            .Should().Be(3);

            sut.Execute(m => m.Foo())
            .Should().Be(3);
        }
Example #34
0
        public void ProxyGenerator_CreateInterfaceProxyWithoutTarget_cannot_proceed_to_delegate_type_mixin()
        {
            var options = new ProxyGenerationOptions();

            options.AddDelegateTypeMixin(typeof(Action));

            var interceptor = new Interceptor(shouldProceed: true);

            var proxy  = generator.CreateInterfaceProxyWithoutTarget(typeof(IComparable), options, interceptor);
            var action = ProxyUtil.CreateDelegateToMixin <Action>(proxy);

            Assert.NotNull(action);

            Assert.Throws <NotImplementedException>(() => action.Invoke());
        }
Example #35
0
        public static void Main(string[] args)
        {
            var interceptor = new Interceptor();

            interceptor.Register<Person>();

            var person = interceptor.Resolve<Person>();
            //var person = new Person();

            person.FirstName = "Bill";
            person.LastName = "Gates";

            person.Introduce();

            Console.ReadKey();
        }
        public void configured_interceptors_and_lifetimes_should_be_cloned_and_clone_should_be_executed()
        {
            var lifetime = new Lifetime();
            var interceptor = new Interceptor();

            new Container(x => x.For(typeof(IList<>)).Use(typeof(List<>))
                .Lifetime.Use(lifetime)
                .Intercept(interceptor))
                .Get<IList<int>>();

            lifetime.IsCloned.Should().BeTrue();
            lifetime.Executed.Should().BeFalse();
            lifetime.Clone.IsCloned.Should().BeFalse();
            lifetime.Clone.Executed.Should().BeTrue();

            interceptor.IsCloned.Should().BeTrue();
            interceptor.Executed.Should().BeFalse();
            interceptor.Clone.IsCloned.Should().BeFalse();
            interceptor.Clone.Executed.Should().BeTrue();
        }
Example #37
0
 public void PressKey(Interceptor.Keys key)
 {
 }
 internal Interceptor SetSuccessor(Interceptor successor)
 {
     _successor = successor;
     return this;
 }
 internal InterceptionFlow(Interceptor[] interceptors) {
     m_increment = 1;
     m_interceptors = interceptors;
     ResetToStart();
 }
 internal RequestInterceptionFlow(Interceptor[] interceptors) : base(interceptors) {
 }
 /// <summary>
 /// Creates the interceptor.
 /// </summary>
 /// <param name="interceptor">The interceptor delegate</param>
 public DelegateInterceptor(Interceptor interceptor)
 {
     this.interceptor = interceptor;
 }
 /// <summary>
 /// Constructs a connection handler for the given client.
 /// </summary>
 /// <param name="client">client connection</param>
 /// <param name="interceptor">a request/reply interceptor, or null if none is required</param>
 public ClientConnectionHandler(TcpClient client, Interceptor interceptor)
 {
     this.tcpClient = client;
     this.interceptor = interceptor;
     ContinueConnection = true;
 }
 /// <summary>
 /// Create a socket listener. Listens for incoming connection
 /// attempts. Accepts connections and creates an RpcConnectionHandler
 /// to process requests from that connection.
 /// </summary>
 /// <param name="listenPort"></param>
 /// <param name="interceptor"></param>
 public SocketListener(int listenPort, Interceptor interceptor)
 {
     this.listenPort = listenPort;
     this.interceptor = interceptor;
 }
Example #44
0
 public static bool RemoveInterceptor(Interceptor interceptor)
 {
     return mInterceptors.Remove(interceptor);
 }
Example #45
0
 public static bool AddInterceptor(Interceptor interceptor)
 {
     return mInterceptors.Add(interceptor);
 }
Example #46
0
 public void ReleaseKey(Interceptor.Keys key)
 {
 }
        public void Test_Interceptor()
        {
            ClearAll();

            var dispatcher = new CountingMockMainThreadDispatcher();
            Ioc.RegisterSingleton<IMvxMainThreadDispatcher>(dispatcher);

            var interceptor = new Interceptor();
            Ioc.RegisterSingleton<IMvxInpcInterceptor>(interceptor);

            var notified = new List<string>();
            var t = new TestInpc();
            t.PropertyChanged += (sender, args) => notified.Add(args.PropertyName);
            interceptor.Handler = (s, e) => MvxInpcInterceptionResult.RaisePropertyChanged;
            t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));

            Assert.That(dispatcher.Count == 1);

            interceptor.Handler = (s, e) => MvxInpcInterceptionResult.DoNotRaisePropertyChanged;
            t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));

            Assert.That(dispatcher.Count == 1);

            interceptor.Handler = (s, e) => MvxInpcInterceptionResult.RaisePropertyChanged;
            t.RaisePropertyChanged(new PropertyChangedEventArgs("Foo"));

            Assert.That(dispatcher.Count == 2);
        }
 IInterceptor IInterceptor.Clone()
 {
     Clone = new Interceptor();
     return Clone;
 }