public void SetUp() { _subject = new ResolverPipeline(); _subject.AddHandlers( new TestComponentHandler("Foo", _foo = new TestComponent()), new TestComponentHandler("Bar", _bar = new TestComponent()) ); }
public void SetUp() { _subject = new ResolverPipeline(); _subject.AddHandlers( new LazyHandler(_subject), new TestComponentHandler("Foo", _testable = new TestComponent()) ); }
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 ); }
[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); }
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; }
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); }
public void CanBroadcastMessagesToGameObjects() { var gameObject = new GameObject(); var receiver = new TestComponent(); gameObject.AddComponent(receiver); Scene.Current.RegisterObj(gameObject); receiver.TestBroadcastMessage(); Assert.IsTrue(receiver.MessageHandled); }
// 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); }
/// <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); }
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"})); }
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 ); }
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); }
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); }
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>()); }
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>()); }
} [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
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); }
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()); }
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); }
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); }
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); }
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); }
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); }
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()); }
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); }
public void SetComponent(IApplicationComponent component) { _component = (TestComponent)component; }
/// <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; }
public static TestComponent ScrollIntoViewIfNeeded(this TestComponent component, IWebElement element) { component.Driver.ScrollIntoViewIfNeeded(element); return(component); }
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 }
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>(); }
protected override void Before_all_tests() { base.Before_all_tests(); _testComponent = AutoMockContainer.Resolve <TestComponent>(); }
public void Test() { TestComponent tc = (TestComponent)GameObject.Find("ExternalGameObject").GetComponent("TestComponent"); tc.Test("Hello World!"); }
static void Main(string[] args) { TestComponent test = new TestComponent(); }
public void GeneticComponent_ValidateProperty_Name_NonExistentProperty() { TestComponent component = new TestComponent(); Assert.Throws <ArgumentException>(() => component.TestValidateProperty(1, "Nothing")); }
protected AbstractionAdapterTestsBase() { Implementation = new TestComponent(); Adapter = new AbstractionAdapter <TestComponent>(Implementation); }
/// <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(); }
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); }
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(); }
public static TestComponent ScrollIntoView(this TestComponent component, IWebElement element, bool alignToTop = false) { component.Driver.ScrollIntoView(element, alignToTop); return(component); }
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));
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; }
public new void SetUp() { _component = new TestComponent(); }
public void SetUp() { TestComponent.Reset(); Current.Reset(); }
protected bool Equals(TestComponent other) { return(A == other.A && B == other.B && string.Equals(C, other.C)); }
public void TearDown() { TestComponent.Reset(); }
public void Setup() { _fake = new TestComponent <FakeGate>(); }