Inheritance: MonoBehaviour
コード例 #1
0
ファイル: PipelineTest.cs プロジェクト: pwarner/Pandora
 public void SetUp()
 {
     _subject = new ResolverPipeline();
     _subject.AddHandlers(
         new TestComponentHandler("Foo", _foo = new TestComponent()),
         new TestComponentHandler("Bar", _bar = new TestComponent())
         );
 }
コード例 #2
0
ファイル: LazyHandlerTest.cs プロジェクト: pwarner/Pandora
 public void SetUp()
 {
     _subject = new ResolverPipeline();
     _subject.AddHandlers(
         new LazyHandler(_subject),
         new TestComponentHandler("Foo", _testable = new TestComponent())
         );
 }
コード例 #3
0
        public void TestHandleMessage( )
        {
            IMessageHandler handler = new TestComponent( );

            TestSenderMessage( handler, new Message0( ), MethodId.TestComponent_Handle_Message0 );
            TestSenderMessage( handler, new Message1( ), MethodId.TestComponent_Handle_Message1 );
            TestSenderMessage( handler, new Message2( ), MethodId.TestComponent_Handle_Message1 );
            TestSenderMessage( handler, new Message3( ), MethodId.TestComponent_Handle_Message3 );
        }
コード例 #4
0
ファイル: SpecificCloningTest.cs プロジェクト: undue/duality
		[Test] public void CloneComponent()
		{
			Random rnd = new Random();
			TestComponent source = new TestComponent(rnd);
			TestComponent target = source.DeepClone();

			Assert.AreEqual(source, target);
			Assert.AreNotSame(source, target);
			Assert.AreNotSame(source.TestReferenceList, target.TestReferenceList);
		}
コード例 #5
0
		protected void SetUp()
		{
			events = new StringBuilder();
			one = new TestComponent("One", events);
			two = new TestComponent("Two", events);
			three = new TestComponent("Three", events);

			mock = new DynamicMock(typeof (IPicoContainer));
			pico = (IPicoContainer) mock.MockInstance;
		}
コード例 #6
0
        public void CanBroadcastFromGameObjects()
        {
            var gameObject = new GameObject();
            var receiver = new TestComponent();
            gameObject.AddComponent(receiver);
            Scene.Current.AddObject(gameObject);

            gameObject.SendMessage(new TestGameMessage(), gameObject);

            Assert.IsTrue(receiver.MessageHandled);
        }
コード例 #7
0
		public void CanBroadcastMessagesToGameObjects()
		{
			var gameObject = new GameObject();
			var receiver = new TestComponent();
			gameObject.AddComponent(receiver);
			Scene.Current.RegisterObj(gameObject);

			receiver.TestBroadcastMessage();

			Assert.IsTrue(receiver.MessageHandled);
		}
コード例 #8
0
		 // to wrap it in a receive event and spoof the source.
		 JTS.Receive ie = new JTS.Receive();
		 ie.getBody().getReceiveRec().getMessagePayload().set( bufsize, buffer );
		 ie.getBody().getReceiveRec().setSrcSubsystemID(160);
		 ie.getBody().getReceiveRec().setSrcNodeID(1);
		 ie.getBody().getReceiveRec().setSrcComponentID(1);
		 // Now wedge the event into the component...
		 dest.processInternalEvent( ie );
		 // Sleep for a bit to let the event percolate through...
		Thread.Sleep(500);
    }
コード例 #9
0
ファイル: TestComponentControl.cs プロジェクト: nhannd/Xian
        /// <summary>
        /// Constructor
        /// </summary>
        public TestComponentControl(TestComponent component)
            :base(component)
        {
            InitializeComponent();

			if (_syncContext == null)
				_syncContext = SynchronizationContext.Current;

            _component = component;

            _label.DataBindings.Add("Text", _component, "Name");
            _text.DataBindings.Add("Text", _component, "Text", true, DataSourceUpdateMode.OnPropertyChanged);
        }
コード例 #10
0
 public void SetUp()
 {
     _pipeline = new ResolverPipeline();
     _pipeline.AddHandlers(
         new TestComponentHandler("Foo", _expected = new TestComponent())
         );
     _goodCtor = typeof (MultiConstructor).GetConstructor(new[] {typeof (ITestComponent)});
     _badCtor = typeof(MultiConstructor).GetConstructor(new[] { typeof(ITestComponent), typeof(int) });
     _defCtor = typeof (MultiConstructor).GetConstructor(new Type[] {});
     _subject = new ConstructorResolver(_pipeline);
     _request = new ResolverRequest(
         typeof(MultiConstructor),
         null,
         new ResolverArgs(new {Key = "Foo"}));
 }
コード例 #11
0
        public void TestMessageHub( )
        {
            Component hub = new Component( );
            TestComponent handler = new TestComponent( );

            MessageHub.AddDispatchRecipient( hub, typeof( Message0 ), handler, 0 );
            MessageHub.AddDispatchRecipient( hub, typeof( Message1 ), handler, 0 );
            //  No dispatch method takes parameter of type Message2
            MessageHub.AddDispatchRecipient( hub, typeof( Message3 ), handler, 0 );

            TestHubMessage( hub, new Message0( ), MethodId.TestComponent_Handle_Message0 );
            TestHubMessage( hub, new Message1( ), MethodId.TestComponent_Handle_Message1 );
            TestHubMessage( hub, new Message2( ), MethodId.TestComponent_Handle_Message1 );
            TestHubMessage( hub, new Message3( ), MethodId.TestComponent_Handle_Message3 );
        }
コード例 #12
0
        public void CanRegisterMultipleComponentsOnTheSameGameObjectForTargettedDelivery()
        {
            var gameObject = new GameObject();
            var testComponent = new TestComponent();
            var testComponent2 = new TestComponent2();

            gameObject.AddComponent(testComponent);
            gameObject.AddComponent(testComponent2);

            Scene.Current.AddObject(gameObject);

            gameObject.SendMessage(new TestGameMessage(), gameObject);

            Assert.True(testComponent.MessageHandled);
            Assert.True(testComponent2.MessageHandled);
        }
コード例 #13
0
		public void CanBroadcastToNamedGameObject()
		{
			var gameObject = new GameObject {Name = "TestGameObject"};
			var receiver = new TestComponent();
			gameObject.AddComponent(receiver);
			Scene.Current.RegisterObj(gameObject);

			var gameObject2 = new GameObject();
			var receiver2 = new TestComponent();
			gameObject2.AddComponent(receiver2);
			Scene.Current.RegisterObj(gameObject2);

			receiver2.TestBroadcastMessageToNamedGameObject();

			Assert.IsTrue(receiver.MessageHandled);
			Assert.IsFalse(receiver2.MessageHandled);
		}
コード例 #14
0
        public void ReplaceRegisteredComponent()
        {
            var initialComponent = new TestComponent();
            var replacementComponent = new TestComponent();

            Assert.IsNull(ComponentRepository.Instance.Resolve<ITestComponent>());
            Assert.IsNull(ComponentRepository.Instance.Resolve<TestComponent>());

            ComponentRepository.Instance.Register(initialComponent);
            Assert.IsTrue(ReferenceEquals(ComponentRepository.Instance.Resolve<TestComponent>(), initialComponent));
            ComponentRepository.Instance.Register(replacementComponent);
            Assert.IsTrue(ReferenceEquals(ComponentRepository.Instance.Resolve<TestComponent>(), replacementComponent));

            ComponentRepository.Instance.Unregister(replacementComponent);

            Assert.IsNull(ComponentRepository.Instance.Resolve<ITestComponent>());
            Assert.IsNull(ComponentRepository.Instance.Resolve<TestComponent>());
        }
コード例 #15
0
        public void RegisterAndResolveComponent()
        {
            var component = new TestComponent();

            Assert.IsNull(ComponentRepository.Instance.Resolve<ITestComponent>());
            Assert.IsNull(ComponentRepository.Instance.Resolve<TestComponent>());

            ComponentRepository.Instance.Register(component);

            Assert.IsNotNull(ComponentRepository.Instance.Resolve<TestComponent>());
            Assert.IsNotNull(ComponentRepository.Instance.Resolve<ITestComponent>());
            Assert.IsTrue(ReferenceEquals(ComponentRepository.Instance.Resolve<TestComponent>(), component));
            Assert.IsTrue(ReferenceEquals(ComponentRepository.Instance.Resolve<ITestComponent>(), component));

            ComponentRepository.Instance.Unregister(component);

            Assert.IsNull(ComponentRepository.Instance.Resolve<ITestComponent>());
            Assert.IsNull(ComponentRepository.Instance.Resolve<TestComponent>());
        }
コード例 #16
0
    }

    [SetUp]
    public void setUp()
    {
    }

    [Test]
    public void testInitState()
    {
        Console.WriteLine("Checking initial state...");

        TestComponent cmpt = new TestComponent(160, 1, 1);
		cmpt.startComponent();

        Assert.AreEqual("Parent_Parent1FSM_SM.Top1", cmpt.getState(0));
		Assert.AreEqual("Intermediary_Parent1FSM_SM.Top1_Intermediary1", cmpt.getState(1));
		Assert.AreEqual("Child_Parent1FSM_SM.Top1_Intermediary1", cmpt.getState(2));

		// and stop the component
コード例 #17
0
        public void DoesNotNotifyDescendantsIfCascadingParameterValuesAreImmutableAndUnchanged()
        {
            // Arrange
            var renderer  = new TestRenderer();
            var component = new TestComponent(builder =>
            {
                builder.OpenComponent <CascadingValue <string> >(0);
                builder.AddAttribute(1, "Value", "Unchanging value");
                builder.AddAttribute(2, RenderTreeBuilder.ChildContent, new RenderFragment(childBuilder =>
                {
                    childBuilder.OpenComponent <CascadingParameterConsumerComponent <string> >(0);
                    childBuilder.AddAttribute(1, "RegularParameter", "Goodbye");
                    childBuilder.CloseComponent();
                }));
                builder.CloseComponent();
            });

            // Act 1: Initial render
            var componentId = renderer.AssignRootComponentId(component);

            component.TriggerRender();
            var firstBatch      = renderer.Batches.Single();
            var nestedComponent = FindComponent <CascadingParameterConsumerComponent <string> >(firstBatch, out _);

            Assert.Equal(3, firstBatch.DiffsByComponentId.Count); // Root + CascadingValue + nested
            Assert.Equal(1, nestedComponent.NumRenders);

            // Act/Assert: Re-render the CascadingValue; observe nested component wasn't re-rendered
            component.TriggerRender();

            // Assert: We did not re-render CascadingParameterConsumerComponent
            Assert.Equal(2, renderer.Batches.Count);
            var secondBatch = renderer.Batches[1];

            Assert.Equal(2, secondBatch.DiffsByComponentId.Count); // Root + CascadingValue, but not nested one
            Assert.Equal(1, nestedComponent.NumRenders);
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: denisgoriachev/bentities
        static void Main(string[] args)
        {
            // fisrt of all, perform scanning of assemblies for factory
            ECSManagerFactory.ScanAssemblies(AppDomain.CurrentDomain.GetAssemblies());

            // after that, we can create ECS Manager
            ECSManager manager = ECSManagerFactory.CreateECSManager();

            // let's create first entity!
            Entity firstEntity = manager.CreateEntity();

            // now let's get transform component and move entity a little bit
            Transform2DComponent component = firstEntity.GetComponentOrDefault <Transform2DComponent>();

            component.Position += new Vector2(10, 10);

            // attach a new component and change its values
            TestComponent newComponent = firstEntity.AttachComponent <TestComponent>();

            newComponent.Variable1 += 10;

            GameTime testGameTime = new GameTime(TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(100));

            // here is the call of Update()
            // All routine, connected to creation of entities, attaching of components and etc. is performed within Update()
            manager.Update(testGameTime);

            // it is better to call Draw, isn't it?
            manager.Draw(testGameTime);

            // here is the one more call of Update()
            // Now all components are registered and can be processed in Systems
            manager.Update(testGameTime);

            // Now it is time to shutdown ECS manager - lets perform unloading of content
            manager.UnloadContent();
        }
            public async Task IgnoresEndMessageWithContextIfStillAffected(ComponentStatus changeStatus, ComponentStatus existingStatus)
            {
                var child = new TestComponent("child");

                child.Status = changeStatus;
                var root = new AlwaysSameValueTestComponent(
                    ComponentStatus.Degraded,
                    "hi",
                    "",
                    new[] { child },
                    false);

                var affectedComponent = root.GetByNames <IComponent>(root.Name, child.Name);
                var change            = new MessageChangeEvent(
                    DefaultTimestamp + TimeSpan.FromDays(1),
                    affectedComponent.Path,
                    changeStatus,
                    MessageType.End);

                var context = new ExistingStartMessageContext(
                    DefaultTimestamp,
                    root,
                    existingStatus);

                var result = await Processor.ProcessAsync(change, EventEntity, root, context);

                Assert.Equal(context, result);

                Factory
                .Verify(
                    x => x.CreateMessageAsync(
                        It.IsAny <EventEntity>(),
                        It.IsAny <DateTime>(),
                        It.IsAny <MessageType>(),
                        It.IsAny <IComponent>()),
                    Times.Never());
            }
コード例 #20
0
ファイル: ComponentBaseTest.cs プロジェクト: jnm2/AspNetCore
        public void RunsOnParametersSetAsyncWhenRendered()
        {
            // Arrange
            var renderer  = new TestRenderer();
            var component = new TestComponent();

            int onParametersSetAsyncRuns = 0;

            component.RunsBaseOnParametersSetAsync = false;
            component.OnParametersSetAsyncLogic    = c =>
            {
                onParametersSetAsyncRuns++;
                return(Task.CompletedTask);
            };

            // Act
            var componentId = renderer.AssignRootComponentId(component);

            renderer.RenderRootComponent(componentId);

            // Assert
            Assert.Equal(1, onParametersSetAsyncRuns);
            Assert.Single(renderer.Batches);
        }
コード例 #21
0
    public async Task ProducesNewBatch_WhenABatchGetsAcknowledged()
    {
        var serviceProvider = CreateServiceProvider();
        var renderer        = GetRemoteRenderer(serviceProvider);
        var i         = 0;
        var component = new TestComponent(builder =>
        {
            builder.AddContent(0, $"Value {i}");
        });

        // Act
        var componentId = renderer.AssignRootComponentId(component);

        for (i = 0; i < 20; i++)
        {
            component.TriggerRender();
        }
        Assert.Equal(10, renderer._unacknowledgedRenderBatches.Count);

        await renderer.OnRenderCompletedAsync(2, null);

        // Assert
        Assert.Equal(10, renderer._unacknowledgedRenderBatches.Count);
    }
コード例 #22
0
        public void PassesCascadingParametersToNestedComponents()
        {
            // Arrange
            var renderer  = new TestRenderer();
            var component = new TestComponent(builder =>
            {
                builder.OpenComponent <CascadingValue <string> >(0);
                builder.AddAttribute(1, "Value", "Hello");
                builder.AddAttribute(2, "ChildContent", new RenderFragment(childBuilder =>
                {
                    childBuilder.OpenComponent <CascadingParameterConsumerComponent <string> >(0);
                    childBuilder.AddAttribute(1, "RegularParameter", "Goodbye");
                    childBuilder.CloseComponent();
                }));
                builder.CloseComponent();
            });

            // Act/Assert
            var componentId = renderer.AssignRootComponentId(component);

            component.TriggerRender();
            var batch               = renderer.Batches.Single();
            var nestedComponent     = FindComponent <CascadingParameterConsumerComponent <string> >(batch, out var nestedComponentId);
            var nestedComponentDiff = batch.DiffsByComponentId[nestedComponentId].Single();

            // The nested component was rendered with the correct parameters
            Assert.Collection(nestedComponentDiff.Edits,
                              edit =>
            {
                Assert.Equal(RenderTreeEditType.PrependFrame, edit.Type);
                AssertFrame.Text(
                    batch.ReferenceFrames[edit.ReferenceFrameIndex],
                    "CascadingParameter=Hello; RegularParameter=Goodbye");
            });
            Assert.Equal(1, nestedComponent.NumRenders);
        }
コード例 #23
0
    public async Task NoNewBatchesAreCreated_WhenThereAreNoPendingRenderRequestsFromComponents()
    {
        var serviceProvider = CreateServiceProvider();
        var renderer        = GetRemoteRenderer(serviceProvider);
        var component       = new TestComponent(builder =>
        {
            builder.OpenElement(0, "my element");
            builder.AddContent(1, "some text");
            builder.CloseElement();
        });

        // Act
        var componentId = renderer.AssignRootComponentId(component);

        for (var i = 0; i < 10; i++)
        {
            component.TriggerRender();
        }

        await renderer.OnRenderCompletedAsync(2, null);

        // Assert
        Assert.Equal(9, renderer._unacknowledgedRenderBatches.Count);
    }
コード例 #24
0
        public void RunsOnInitAsyncAlsoOnBaseClassWhenRendered()
        {
            // Arrange
            var renderer  = new TestRenderer();
            var component = new TestComponent();

            var onInitAsyncRuns = 0;

            component.RunsBaseOnInitAsync = true;
            component.OnInitAsyncLogic    = c =>
            {
                onInitAsyncRuns++;
                return(Task.CompletedTask);
            };

            // Act
            var componentId = renderer.AssignRootComponentId(component);

            renderer.RenderRootComponent(componentId);

            // Assert
            Assert.Equal(1, onInitAsyncRuns);
            Assert.Single(renderer.Batches);
        }
コード例 #25
0
            public async Task ReturnsExistingMessage()
            {
                var type            = (MessageType)99;
                var status          = (ComponentStatus)100;
                var componentStatus = (ComponentStatus)101;
                var component       = new TestComponent("component")
                {
                    Status = componentStatus
                };

                var existingMessage = new MessageEntity(EventEntity, Time, "existing", (MessageType)98);

                Table
                .Setup(x => x.RetrieveAsync <MessageEntity>(MessageEntity.GetRowKey(EventEntity, Time)))
                .ReturnsAsync(existingMessage)
                .Verifiable();

                await InvokeMethod(
                    EventEntity,
                    Time,
                    type,
                    component,
                    status);

                Table.Verify();

                Table
                .Verify(
                    x => x.InsertAsync(It.IsAny <MessageEntity>()),
                    Times.Never());

                Builder
                .Verify(
                    x => x.Build(It.IsAny <MessageType>(), It.IsAny <IComponent>(), It.IsAny <ComponentStatus>()),
                    Times.Never());
            }
コード例 #26
0
        public void HandlesReentrancy()
        {
            var gameObject = new GameObject();
            var testComponent = new TestComponent();
            var testComponent2 = new ComponentThatCallsSendMessageInsideHandleMessage();

            gameObject.AddComponent(testComponent);
            gameObject.AddComponent(testComponent2);

            Scene.Current.AddObject(gameObject);

            gameObject.SendMessage(new TestGameMessageTwo(), gameObject);

            Assert.True(testComponent.MessageHandled);
            Assert.True(testComponent2.MessageHandled);
        }
コード例 #27
0
 public void SetComponent(IApplicationComponent component)
 {
     _component = (TestComponent)component;
 }
コード例 #28
0
        /// <summary>
        /// Sets the succeedAfterAllAssertionsAreExecuted field on the <see cref="TestComponent"/>.
        /// </summary>
        /// <param name="testGameObject">The test game object.</param>
        private static void SetSucceedOnAssertions(GameObject testGameObject)
        {
            TestComponent testComponent = testGameObject.GetComponent <TestComponent>();

            testComponent.succeedAfterAllAssertionsAreExecuted = true;
        }
コード例 #29
0
 public static TestComponent ScrollIntoViewIfNeeded(this TestComponent component, IWebElement element)
 {
     component.Driver.ScrollIntoViewIfNeeded(element);
     return(component);
 }
コード例 #30
0
        public void DoesNotNotifyDescendantsOfUpdatedCascadingParameterValuesWhenFixed()
        {
            // Arrange
            var providedValue      = "Initial value";
            var shouldIncludeChild = true;
            var renderer           = new TestRenderer();
            var component          = new TestComponent(builder =>
            {
                builder.OpenComponent <CascadingValue <string> >(0);
                builder.AddAttribute(1, "Value", providedValue);
                builder.AddAttribute(2, "IsFixed", true);
                builder.AddAttribute(3, "ChildContent", new RenderFragment(childBuilder =>
                {
                    if (shouldIncludeChild)
                    {
                        childBuilder.OpenComponent <CascadingParameterConsumerComponent <string> >(0);
                        childBuilder.AddAttribute(1, "RegularParameter", "Goodbye");
                        childBuilder.CloseComponent();
                    }
                }));
                builder.CloseComponent();
            });

            // Act 1: Initial render; capture nested component ID
            var componentId = renderer.AssignRootComponentId(component);

            component.TriggerRender();
            var firstBatch      = renderer.Batches.Single();
            var nestedComponent = FindComponent <CascadingParameterConsumerComponent <string> >(firstBatch, out var nestedComponentId);

            Assert.Equal(1, nestedComponent.NumRenders);

            // Assert: Initial value is supplied to descendant
            var nestedComponentDiff = firstBatch.DiffsByComponentId[nestedComponentId].Single();

            Assert.Collection(nestedComponentDiff.Edits, edit =>
            {
                Assert.Equal(RenderTreeEditType.PrependFrame, edit.Type);
                AssertFrame.Text(
                    firstBatch.ReferenceFrames[edit.ReferenceFrameIndex],
                    "CascadingParameter=Initial value; RegularParameter=Goodbye");
            });

            // Act 2: Re-render CascadingValue with new value
            providedValue = "Updated value";
            component.TriggerRender();

            // Assert: We did not re-render the descendant
            Assert.Equal(2, renderer.Batches.Count);
            var secondBatch = renderer.Batches[1];

            Assert.Equal(2, secondBatch.DiffsByComponentId.Count); // Root + CascadingValue, but not nested one
            Assert.Equal(1, nestedComponent.NumSetParametersCalls);
            Assert.Equal(1, nestedComponent.NumRenders);

            // Act 3: Dispose
            shouldIncludeChild = false;
            component.TriggerRender();

            // Assert: Absence of an exception here implies we didn't cause a problem by
            // trying to remove a non-existent subscription
        }
コード例 #31
0
        public void GeneticComponent_ValidateProperty_PropertyInfo_NullOrEmptyPropertyName()
        {
            TestComponent component = new TestComponent();

            Assert.Throws <ArgumentNullException>(() => component.TestValidateProperty(1, (PropertyInfo)null));
        }
 void PrepareObject()
 {
     go        = new GameObject("Object");
     behaviour = go.AddComponent <TestComponent>();
 }
コード例 #33
0
 protected override void Before_all_tests()
 {
     base.Before_all_tests();
     _testComponent = AutoMockContainer.Resolve <TestComponent>();
 }
コード例 #34
0
    public void Test()
    {
        TestComponent tc = (TestComponent)GameObject.Find("ExternalGameObject").GetComponent("TestComponent");

        tc.Test("Hello World!");
    }
コード例 #35
0
 static void Main(string[] args)
 {
     TestComponent test = new TestComponent();
 }
コード例 #36
0
 public void SetComponent(IApplicationComponent component)
 {
     _component = (TestComponent)component;
 }
コード例 #37
0
        public void GeneticComponent_ValidateProperty_Name_NonExistentProperty()
        {
            TestComponent component = new TestComponent();

            Assert.Throws <ArgumentException>(() => component.TestValidateProperty(1, "Nothing"));
        }
コード例 #38
0
 protected AbstractionAdapterTestsBase()
 {
     Implementation = new TestComponent();
     Adapter        = new AbstractionAdapter <TestComponent>(Implementation);
 }
コード例 #39
0
    /// <summary>
    /// this method contains all timer example code. NOTE: timer code
    /// does not have to be located in 'OnGUI'. it can exist anywhere
    /// </summary>
    void OnGUI()
    {
        // make the status text fade back to invisible if made yellow
        m_StatusColor = Color.Lerp(m_StatusColor, new Color(1, 1, 0, 0), Time.deltaTime * 0.5f);

        // draw the header text
        GUI.color = Color.white;
        GUILayout.Space(50);
        GUILayout.BeginHorizontal();
        GUILayout.Space(50);
        GUILayout.Label("SCHEDULING EXAMPLE\n    - Each of these examples will schedule some functionality in one (1)\n      second using different options.\n    - Please study the source code in 'Examples/Scheduling/Scheduling.cs' ...");
        GUILayout.EndHorizontal();

        // create an area for all the example buttons
        GUILayout.BeginArea(new Rect(100, 150, 400, 600));
        GUI.color = Color.white;
        GUILayout.Label("Methods, Arguments, Delegates, Iterations, Intervals & Canceling");

        // --- Example 1 ---
        if (DoButton("A simple method"))
        {
            vp_Timer.In(1.0f, DoMethod);
        }

        // --- Example 2 ---
        if (DoButton("A method with a single argument"))
        {
            vp_Timer.In(1.0f, DoMethodWithSingleArgument, 242);
        }

        // --- Example 3 ---
        if (DoButton("A method with multiple arguments"))
        {
            object[] arg = new object[3];
            arg[0] = "December";
            arg[1] = 31;
            arg[2] = 2012;
            vp_Timer.In(1.0f, DoMethodWithMultipleArguments, arg);

            // TIP: you can also create the object array in-line like this:
            //vp_Timer.In(1.0f, DoMethodWithMultipleArguments, new object[] { "December", 31, 2012 });
        }

        // --- Example 4 ---
        if (DoButton("A delegate"))
        {
            vp_Timer.In(1.0f, delegate()
            {
                SmackCube();
            });
        }

        // --- Example 5 ---
        if (DoButton("A delegate with a single argument"))
        {
            vp_Timer.In(1.0f, delegate(object o)
            {
                int i = (int)o;
                SmackCube();
                SetStatus("A delegate with a single argument ... \"" + i + "\"");
            }, 242);
        }

        // --- Example 6 ---
        if (DoButton("A delegate with multiple arguments"))
        {
            vp_Timer.In(1.0f, delegate(object o)
            {
                object[] argument = (object[])o;                                // 'unpack' object into an array
                string month      = (string)argument[0];                        // convert the first argument to a string
                int day           = (int)argument[1];                           // convert the second argument to an integer
                int year          = (int)argument[2];                           // convert the third argument to an integer

                SmackCube();
                SetStatus("A delegate with multiple arguments ... \"" + month + " " + day + ", " + year + "\"");
            }, new object[] { "December", 31, 2012 });
        }

        // --- Example 7 ---
        if (DoButton("5 iterations of a method"))
        {
            vp_Timer.In(1.0f, SmackCube, 5);
        }

        // --- Example 8 ---
        if (DoButton("5 iterations of a method, with 0.2 sec intervals"))
        {
            vp_Timer.In(1.0f, SmackCube, 5, 0.2f);
        }

        // --- Example 9 ---
        if (DoButton("5 iterations of a delegate, canceled after 3 seconds"))
        {
            vp_Timer.Handle timer = new vp_Timer.Handle();
            vp_Timer.In(0.0f, delegate() { SmackCube(); }, 5, 1,
                        timer);
            vp_Timer.In(3, delegate() { timer.Cancel(); });
        }

        GUILayout.Label("\nMethod & object accessibility:");

        // --- Example 10 ---
        if (DoButton("Running a method from a non-monobehaviour class", false))
        {
            vp_Timer.In(1, delegate()
            {
                NonMonoBehaviour test = new NonMonoBehaviour();
                test.Test();
            });
        }

        // --- Example 11 ---
        if (DoButton("Running a method from a specific external gameobject", false))
        {
            vp_Timer.In(1, delegate()
            {
                TestComponent tc = (TestComponent)GameObject.Find("ExternalGameObject").GetComponent("TestComponent");
                tc.Test("Hello World!");
            });
        }

        // --- Example 12 ---
        if (DoButton("Running a method from the first component of a certain type\nin current transform or any of its children", false))
        {
            vp_Timer.In(1, delegate()
            {
                TestComponent tc = transform.root.GetComponentInChildren <TestComponent>();
                tc.Test("Hello World!");
            });
        }

        // --- Example 13 ---
        if (DoButton("Running a method from the first component of a certain type\nin the whole Hierarchy", false))
        {
            vp_Timer.In(1, delegate()
            {
                TestComponent tc = (TestComponent)FindObjectOfType(typeof(TestComponent));
                tc.Test("Hello World!");
            });
        }

        GUILayout.EndArea();

        GUI.color = m_StatusColor;

        GUILayout.BeginArea(new Rect(Screen.width - 255, 205, 240, 600));
        GUILayout.Label(m_StatusString);
        GUILayout.EndArea();
    }
コード例 #40
0
        public void StopsNotifyingDescendantsIfTheyAreRemoved()
        {
            // Arrange
            var providedValue          = "Initial value";
            var displayNestedComponent = true;
            var renderer  = new TestRenderer();
            var component = new TestComponent(builder =>
            {
                // At the outer level, have an unrelated fixed cascading value to show we can deal with combining both types
                builder.OpenComponent <CascadingValue <int> >(0);
                builder.AddAttribute(1, "Value", 123);
                builder.AddAttribute(2, "IsFixed", true);
                builder.AddAttribute(3, "ChildContent", new RenderFragment(builder2 =>
                {
                    // Then also have a non-fixed cascading value so we can show that unsubscription works
                    builder2.OpenComponent <CascadingValue <string> >(0);
                    builder2.AddAttribute(1, "Value", providedValue);
                    builder2.AddAttribute(2, "ChildContent", new RenderFragment(builder3 =>
                    {
                        if (displayNestedComponent)
                        {
                            builder3.OpenComponent <SecondCascadingParameterConsumerComponent <string, int> >(0);
                            builder3.AddAttribute(1, "RegularParameter", "Goodbye");
                            builder3.CloseComponent();
                        }
                    }));
                    builder2.CloseComponent();
                }));
                builder.CloseComponent();
            });

            // Act 1: Initial render; capture nested component ID
            var componentId = renderer.AssignRootComponentId(component);

            component.TriggerRender();
            var firstBatch      = renderer.Batches.Single();
            var nestedComponent = FindComponent <CascadingParameterConsumerComponent <string> >(firstBatch, out var nestedComponentId);

            Assert.Equal(1, nestedComponent.NumSetParametersCalls);
            Assert.Equal(1, nestedComponent.NumRenders);

            // Act/Assert 2: Re-render the CascadingValue; observe nested component wasn't re-rendered
            providedValue          = "Updated value";
            displayNestedComponent = false; // Remove the nested component
            component.TriggerRender();

            // Assert: We did not render the nested component now it's been removed
            Assert.Equal(2, renderer.Batches.Count);
            var secondBatch = renderer.Batches[1];

            Assert.Equal(1, nestedComponent.NumRenders);
            Assert.Equal(3, secondBatch.DiffsByComponentId.Count); // Root + CascadingValue + CascadingValue, but not nested component

            // We *did* send updated params during the first render where it was removed,
            // because the params are sent before the disposal logic runs. We could avoid
            // this by moving the notifications into the OnAfterRender phase, but then we'd
            // often render descendants twice (once because they are descendants and some
            // direct parameter might have changed, then once because a cascading parameter
            // changed). We can't have it both ways, so optimize for the case when the
            // nested component *hasn't* just been removed.
            Assert.Equal(2, nestedComponent.NumSetParametersCalls);

            // Act 3: However, after disposal, the subscription is removed, so we won't send
            // updated params on subsequent CascadingValue renders.
            providedValue = "Updated value 2";
            component.TriggerRender();
            Assert.Equal(2, nestedComponent.NumSetParametersCalls);
        }
コード例 #41
0
    public void childTransitions()
    {
        Console.WriteLine("Checking transitions using default state...");

        TestComponent cmpt = new TestComponent(160, 1, 1);

        cmpt.startComponent();

        // Send it a message ParentInputMessage1 to transition to Top2_Intermediary1
        sendMessage(new ParentInputMessage1(), cmpt);
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
        Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(1));
        Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(2));

        // Top2_Intemediary1 does not support pim1 message.  Verify that this tickles the default transition
        sendMessage(new ParentInputMessage1(), cmpt);
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
        Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(1));
        Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(2));

        // Lastly, the CIM3 message should transition back to the Top1_Intermediary1 state
        sendMessage(new ChildInputMessage3(), cmpt);
        Assert.AreEqual("Parent_Parent1FSM_SM.Top1", cmpt.getState(0));
        Assert.AreEqual("Intermediary_Parent1FSM_SM.Top1_Intermediary1", cmpt.getState(1));
        Assert.AreEqual("Child_Parent1FSM_SM.Top1_Intermediary1", cmpt.getState(2));

        // Send it a message ParentInputMessage1 to transition to Top2_Intermediary1
        sendMessage(new ParentInputMessage1(), cmpt);
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
        Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(1));
        Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(2));

        // Put it into Top2_Intermediary2
        sendMessage(new IntermediaryInputMessage1(), cmpt);
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
        Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(1));
        Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(2));

        // From Top2_Intermediary2, pim1 and cim3 are not supported.  both following
        // transitions should cause default transition to happen instead.
        sendMessage(new ParentInputMessage1(), cmpt);
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
        Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(1));
        Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(2));

        sendMessage(new ChildInputMessage3(), cmpt);
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
        Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(1));
        Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(2));

        // From Top2_Intermediary2, a default internal transition causes us to stay in the same state
        sendMessage(new ChildInputMessage2(), cmpt);
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
        Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(1));
        Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(2));

        // As of Drew's update Dec 4, a simple default transition returns to the original nested state
        sendMessage(new ChildInputMessage1(), cmpt);
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
        Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(1));
        Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(2));

        // and stop the component
        cmpt.shutdownComponent();
    }
コード例 #42
0
 public static TestComponent ScrollIntoView(this TestComponent component, IWebElement element, bool alignToTop = false)
 {
     component.Driver.ScrollIntoView(element, alignToTop);
     return(component);
 }
コード例 #43
0
        Console.WriteLine("Checking transitions between intermediary states...");

        TestComponent cmpt = new TestComponent(160, 1, 1);
		cmpt.startComponent();

        // Send it a message ParentInputMessage1 to transition to Top2_Intermediary1
        sendMessage( new ParentInputMessage1(), cmpt );
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
		Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(1));
		Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(2));

        // Put it into Top2_Intermediary2
        sendMessage( new IntermediaryInputMessage1(), cmpt );
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
		Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(1));
		Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary2", cmpt.getState(2));

        // Put it back to the initial Top1_Intermediary1 state
        sendMessage( new ParentInputMessage2(), cmpt );
        Assert.AreEqual("Parent_Parent1FSM_SM.Top1", cmpt.getState(0));
		Assert.AreEqual("Intermediary_Parent1FSM_SM.Top1_Intermediary1", cmpt.getState(1));
		Assert.AreEqual("Child_Parent1FSM_SM.Top1_Intermediary1", cmpt.getState(2));

		// and stop the component
		cmpt.shutdownComponent();
    }

    [Test]
    public void childTransitions()
    {
        Console.WriteLine("Checking transitions using default state...");

        TestComponent cmpt = new TestComponent(160, 1, 1);
		cmpt.startComponent();

        // Send it a message ParentInputMessage1 to transition to Top2_Intermediary1
        sendMessage( new ParentInputMessage1(), cmpt );
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
		Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(1));
		Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(2));

        // Top2_Intemediary1 does not support pim1 message.  Verify that this tickles the default transition
        sendMessage( new ParentInputMessage1(), cmpt );
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
		Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(1));
		Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(2));

        // Lastly, the CIM3 message should transition back to the Top1_Intermediary1 state
        sendMessage( new ChildInputMessage3(), cmpt );
        Assert.AreEqual("Parent_Parent1FSM_SM.Top1", cmpt.getState(0));
		Assert.AreEqual("Intermediary_Parent1FSM_SM.Top1_Intermediary1", cmpt.getState(1));
		Assert.AreEqual("Child_Parent1FSM_SM.Top1_Intermediary1", cmpt.getState(2));

        // Send it a message ParentInputMessage1 to transition to Top2_Intermediary1
        sendMessage( new ParentInputMessage1(), cmpt );
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
		Assert.AreEqual("Intermediary_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(1));
		Assert.AreEqual("Child_Parent1FSM_SM.Top2_Intermediary1", cmpt.getState(2));

        // Put it into Top2_Intermediary2
        sendMessage( new IntermediaryInputMessage1(), cmpt );
        Assert.AreEqual("Parent_Parent1FSM_SM.Top2", cmpt.getState(0));
コード例 #44
0
    public async Task ProcessBufferedRenderBatches_WritesRenders()
    {
        // Arrange
        var @event          = new ManualResetEventSlim();
        var serviceProvider = CreateServiceProvider();
        var renderIds       = new List <long>();

        var firstBatchTCS  = new TaskCompletionSource <object>();
        var secondBatchTCS = new TaskCompletionSource <object>();
        var thirdBatchTCS  = new TaskCompletionSource <object>();

        var initialClient = new Mock <IClientProxy>();

        initialClient.Setup(c => c.SendCoreAsync(It.IsAny <string>(), It.IsAny <object[]>(), It.IsAny <CancellationToken>()))
        .Callback((string name, object[] value, CancellationToken token) => renderIds.Add((long)value[0]))
        .Returns(firstBatchTCS.Task);
        var circuitClient = new CircuitClientProxy(initialClient.Object, "connection0");
        var renderer      = GetRemoteRenderer(serviceProvider, circuitClient);
        var component     = new TestComponent(builder =>
        {
            builder.OpenElement(0, "my element");
            builder.AddContent(1, "some text");
            builder.CloseElement();
        });

        var client = new Mock <IClientProxy>();

        client.Setup(c => c.SendCoreAsync(It.IsAny <string>(), It.IsAny <object[]>(), It.IsAny <CancellationToken>()))
        .Callback((string name, object[] value, CancellationToken token) => renderIds.Add((long)value[0]))
        .Returns <string, object[], CancellationToken>((n, v, t) => (long)v[0] == 3 ? secondBatchTCS.Task : thirdBatchTCS.Task);

        var componentId = renderer.AssignRootComponentId(component);

        component.TriggerRender();
        _ = renderer.OnRenderCompletedAsync(2, null);

        @event.Reset();
        firstBatchTCS.SetResult(null);

        // Waiting is required here because the continuations of SetResult will not execute synchronously.
        @event.Wait(Timeout);

        circuitClient.SetDisconnected();
        component.TriggerRender();
        component.TriggerRender();

        // Act
        circuitClient.Transfer(client.Object, "new-connection");
        var task = renderer.ProcessBufferedRenderBatches();

        foreach (var id in renderIds.ToArray())
        {
            _ = renderer.OnRenderCompletedAsync(id, null);
        }

        secondBatchTCS.SetResult(null);
        thirdBatchTCS.SetResult(null);

        // Assert
        Assert.Equal(new long[] { 2, 3, 4 }, renderIds);
        Assert.True(task.Wait(3000), "One or more render batches weren't acknowledged");

        await task;
    }
コード例 #45
0
 public new void SetUp()
 {
     _component = new TestComponent();
 }
コード例 #46
0
 public void SetUp()
 {
     TestComponent.Reset();
     Current.Reset();
 }
コード例 #47
0
ファイル: RpcHandlerTest.cs プロジェクト: SkaillZ/ubernet
 protected bool Equals(TestComponent other)
 {
     return(A == other.A && B == other.B && string.Equals(C, other.C));
 }
コード例 #48
0
 public void TearDown()
 {
     TestComponent.Reset();
 }
コード例 #49
0
 public void Setup()
 {
     _fake = new TestComponent <FakeGate>();
 }