public async Task ErrorHandled()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(true);
            var responses = new Subject <CallbackResult <object> >();
            var executor  = new CallbackExecutor <object>(Mock.Of <IIdGenerator>(), mock.Object, responses);

            var task = executor.Execute(new CallbackExecutionParameters <object>
            {
                Binder     = context => { },
                Id         = 2,
                Parameters = new CallbackParameter[] { }
            });


            responses.OnNext(new CallbackResult <object>
            {
                ExecutionId = 0,
                Success     = false,
                Error       = "Error"
            });

            await Assert.ThrowsAsync <Exception>(() => task).ConfigureAwait(false);
        }
        public async Task ResponseHandled()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(true);
            var responses = new Subject <CallbackResult <object> >();
            var executor  = new CallbackExecutor <object>(Mock.Of <IIdGenerator>(), mock.Object, responses);

            void Binder(BindingContext <object> context)
            {
                if (context.TargetType == typeof(string))
                {
                    context.ObjectValue = "str";
                }
            }

            var task = executor.Execute(new CallbackExecutionParameters <object>()
            {
                Binder           = Binder,
                Id               = 2,
                Parameters       = new CallbackParameter[] { },
                ResultTargetType = typeof(string)
            });

            responses.OnNext(new CallbackResult <object>
            {
                ExecutionId = 0,
                Success     = true,
                Result      = "str"
            });

            Assert.Equal("str", await task);
        }
        public void CanExecuteReturned()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(false);
            var responses = new Subject <CallbackResult <object> >();
            var executor  = new CallbackExecutor <object>(Mock.Of <IIdGenerator>(), mock.Object, responses);

            Assert.False(executor.CanExecute);
        }
示例#4
0
        public Platform()
        {
            var callbackExecutorGameObject = new GameObject("UnityAdsCallbackExecutorObject")
            {
                hideFlags = HideFlags.HideAndDontSave | HideFlags.HideInInspector
            };

            _callbackExecutor = callbackExecutorGameObject.AddComponent <CallbackExecutor>();
            Object.DontDestroyOnLoad(callbackExecutorGameObject);
        }
示例#5
0
        public Platform() : base("com.unity3d.ads.IUnityAdsListener")
        {
            this.m_CurrentActivity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic <AndroidJavaObject>("currentActivity");
            this.m_UnityAds        = new AndroidJavaClass("com.unity3d.ads.UnityAds");
            GameObject target = new GameObject("UnityAdsCallbackExecutorObject")
            {
                hideFlags = HideFlags.HideAndDontSave | HideFlags.HideInInspector
            };

            this.m_CallbackExecutor = target.AddComponent <CallbackExecutor>();
            UnityEngine.Object.DontDestroyOnLoad(target);
        }
示例#6
0
        public Platform()
        {
            s_Instance = this;
            GameObject target = new GameObject("UnityAdsCallbackExecutorObject")
            {
                hideFlags = HideFlags.HideAndDontSave | HideFlags.HideInInspector
            };

            s_CallbackExecutor = target.AddComponent <CallbackExecutor>();
            UnityEngine.Object.DontDestroyOnLoad(target);
            if (< > f__mg$cache0 == null)
            {
示例#7
0
        public RpcBindingHost(IConnection <TMarshal> connection, IPlatformBinder <TMarshal> parameterBinder, IScheduler baseScheduler)
        {
            this.connection   = connection;
            bindingRepository = new BindingRepository(new IntIdGenerator());

            if (baseScheduler is IDisposable disposable)
            {
                disposables.Add(disposable);
            }

            // ReSharper disable once InvokeAsExtensionMethod
            var baseMessages = Observable.ObserveOn(connection, baseScheduler);

            callbackExecutor = new CallbackExecutor <TMarshal>(new IntIdGenerator(),
                                                               connection,
                                                               baseMessages.Select(m => m.CallbackResult)
                                                               .Where(m => m != null));
            var callbackFactory = new CallbackFactory <TMarshal>(callbackExecutor);
            var binder          = new ObjectBinderBuilder <TMarshal>().Use(typeof(CallbackBinder <TMarshal>), callbackFactory)
                                  .Use(typeof(OutgoingValueBinder <TMarshal>), bindingRepository)
                                  .Use(typeof(PlatformBinder <TMarshal>), parameterBinder).Build();

            methodExecutor   = new MethodExecutor <TMarshal>(bindingRepository.Objects, binder);
            propertyExecutor = new PropertyExecutor <TMarshal>(bindingRepository.Objects, binder);

            disposables.Add(Observable.ObserveOn((callbackExecutor as IObservable <DeleteCallback>), baseScheduler)
                            .Subscribe(OnDeleteCallback));
            disposables.Add(Observable.ObserveOn((callbackExecutor as IObservable <CallbackExecution <TMarshal> >), baseScheduler)
                            .Subscribe(OnCallbackExecution));

            // ReSharper disable once InvokeAsExtensionMethod

            disposables.Add(baseMessages
                            .Select(m => m.MethodExecution)
                            .Where(m => m != null)
                            .Subscribe(OnMethodExecution));
            disposables.Add(baseMessages
                            .Select(m => m.PropertyGet)
                            .Where(m => m != null)
                            .Subscribe(OnPropertyGetExecution));
            disposables.Add(baseMessages
                            .Select(m => m.PropertySet)
                            .Where(m => m != null)
                            .Subscribe(OnPropertySetExecution));
            disposables.Add(baseMessages
                            .Select(m => m.DynamicObjectRequest)
                            .Where(m => m != null)
                            .Subscribe(OnDyanmicObjectRequest));

            disposables.Add(connection);
        }
        public void DeletionFails()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(false);
            var executor = new CallbackExecutor <object>(Mock.Of <IIdGenerator>(), mock.Object, Mock.Of <IObservable <CallbackResult <object> > >());

            DeleteCallback delete = null;

            ((IObservable <DeleteCallback>)executor).Subscribe(
                deleteCallback => delete = deleteCallback);

            Assert.Throws <InvalidOperationException>(() => executor.DeleteCallback(1));
        }
        public void CallbackDeleted()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(true);
            var executor = new CallbackExecutor <object>(Mock.Of <IIdGenerator>(), mock.Object, Mock.Of <IObservable <CallbackResult <object> > >());

            DeleteCallback delete = null;

            ((IObservable <DeleteCallback>)executor).Subscribe(
                deleteCallback => delete = deleteCallback);

            executor.DeleteCallback(1);

            Assert.Equal(1, delete.FunctionId);
        }
示例#10
0
        public void ParametersBoundAndAnalyzed()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(true);
            var executor = new CallbackExecutor <object>(Mock.Of <IIdGenerator>(), mock.Object, Mock.Of <IObservable <CallbackResult <object> > >());

            CallbackExecution <object> exec = null;

            ((IObservable <CallbackExecution <object> >)executor).Subscribe(
                callbackExecution => exec = callbackExecution);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            void Binder(BindingContext <object> context)
            {
                if (context.BindValue != null)
                {
                    context.NativeValue = "str";
                }
                else
                {
                    context.NativeValue = "str2";
                }
            }

            executor.Execute(new CallbackExecutionParameters <object>()
            {
                Binder     = Binder,
                Id         = 2,
                Parameters = new[] { new CallbackParameter {
                                         Value = new object(), Bindable = new BindValueAttribute()
                                     }, new CallbackParameter {
                                         Value = new object()
                                     } },
                ResultTargetType = null
            });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            Assert.Collection(exec.Parameters, s => Assert.Equal("str", (string)s), s => Assert.Equal("str2", (string)s));
        }
示例#11
0
        public void ExecuteSent()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(true);
            var idGenerator = Mock.Of <IIdGenerator>();

            Mock.Get(idGenerator).Setup(_ => _.GetNextId()).Returns(1);

            var executor = new CallbackExecutor <object>(idGenerator, mock.Object, Mock.Of <IObservable <CallbackResult <object> > >());

            CallbackExecution <object> exec = null;

            ((IObservable <CallbackExecution <object> >)executor).Subscribe(
                callbackExecution => exec = callbackExecution);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            executor.Execute(new CallbackExecutionParameters <object>()
            {
                Binder = context => {
                    if (context.Direction == ObjectBindingDirection.In)
                    {
                        context.ObjectValue = context.NativeValue;
                    }
                    else
                    {
                        context.NativeValue = context.ObjectValue;
                    }
                },
                Id               = 2,
                Parameters       = new CallbackParameter[] { },
                ResultTargetType = null
            });
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            Assert.Equal(1, exec.ExecutionId);
            Assert.Equal(2, exec.FunctionId);
        }
示例#12
0
        public async Task ExecuteFails()
        {
            var mock = new Mock <IConnectionAvailability>();

            mock.SetupGet(_ => _.IsOpen).Returns(false);
            var idGenerator = Mock.Of <IIdGenerator>();

            Mock.Get(idGenerator).Setup(_ => _.GetNextId()).Returns(1);

            var executor = new CallbackExecutor <object>(idGenerator, mock.Object, Mock.Of <IObservable <CallbackResult <object> > >());

            CallbackExecution <object> exec = null;

            ((IObservable <CallbackExecution <object> >)executor).Subscribe(
                callbackExecution => exec = callbackExecution);

            await Assert.ThrowsAsync <InvalidOperationException>(() => executor.Execute(new CallbackExecutionParameters <object>
            {
                Binder           = context => { },
                Id               = 2,
                Parameters       = new CallbackParameter[] { },
                ResultTargetType = null
            }));
        }
示例#13
0
 public AndroidShowAdCallback(CallbackExecutor callbackExecutor, ShowAdCallbacks?callbacks) : base("com.unity3d.services.monetization.placementcontent.ads.IShowAdListener")
 {
     this.callbackExecutor = callbackExecutor;
     this.callbacks        = callbacks;
 }
示例#14
0
 public AndroidShowAdOperations(CallbackExecutor callbackExecutor, AndroidJavaObject javaObject) : base(javaObject)
 {
     this.callbackExecutor = callbackExecutor;
 }
示例#15
0
 public AndroidPromoAdOperations(CallbackExecutor callbackExecutor, AndroidJavaObject javaObject) : base(callbackExecutor, javaObject)
 {
     metadata      = GetMetadataForJavaObject(javaObject.Call <AndroidJavaObject>("getMetadata"));
     nativeAdapter = new AndroidJavaObject("com.unity3d.services.monetization.placementcontent.purchasing.NativePromoAdapter", javaObject);
 }
 public IosShowAdOperations(IntPtr placementContentPtr, CallbackExecutor executor) : base(placementContentPtr)
 {
     _executor = executor;
 }
 public IosPromoAdOperations(IntPtr placementContentPtr, CallbackExecutor executor) : base(placementContentPtr, executor)
 {
     metadata = GetMetadataForObjCObject(placementContentPtr);
 }