Exemple #1
0
        public async Task WhenThereAreEvents_ThenEachEventIsExecutedAgainstAPaymentInOrder()
        {
            var event1 = new MockEvent {
                TimeStamp = new DateTime(2000, 1, 1)
            };
            var event2 = new MockEvent {
                TimeStamp = new DateTime(2000, 1, 2)
            };
            var event3 = new MockEvent {
                TimeStamp = new DateTime(2000, 1, 3)
            };

            _events.Add(event2);
            _events.Add(event1);
            _events.Add(event3);

            var payment = await _paymentService.Get(Guid.Empty);

            event1.Payment.Should().Be(payment);
            event2.Payment.Should().Be(payment);
            event3.Payment.Should().Be(payment);

            event1.Sequence.Should().BeLessThan(event2.Sequence);
            event2.Sequence.Should().BeLessThan(event3.Sequence);
        }
Exemple #2
0
        public void ListTest(IList list)
        {
            Assert.IsNotNull(list as IObservableCollection);

            MockEvent.AddNotifiersCollectionAndProperty(list as IObservableCollection);

            //Index Test
            list.Add(Item1);
            Assert.AreEqual(Item1, list[0]);
            MockEvent.AssertMockNotifiersCollection(2, 1);

            list[0] = Item2;
            Assert.AreEqual(Item2, list[0]);
            MockEvent.AssertMockNotifiersCollection(1, 1);

            //Index of test
            Assert.AreEqual(0, list.IndexOf(Item2));

            //Insert(,)
            list.Insert(0, Item3);
            Assert.AreEqual(Item3, list[0]);
            MockEvent.AssertMockNotifiersCollection(2, 1);


            //RemoveAt()
            list.RemoveAt(0);
            Assert.AreEqual(Item2, list[0]);
            MockEvent.AssertMockNotifiersCollection(2, 1);
        }
        public void TestMethod_RemoveWithIndex()
        {
            var key1 = "a"; //0
            var key2 = "c"; //2
            var key3 = "b"; //1

            var value1 = Fixture.Create <string>();
            var value2 = Fixture.Create <string>();
            var value3 = Fixture.Create <string>();

            ObvDictionary.Add(key1, value1);
            ObvDictionary.Add(key2, value2);
            ObvDictionary.Add(key3, value3);

            Log(ObvDictionary.SortedList.IndexOfKey(key1));
            Log(ObvDictionary.SortedList.IndexOfKey(key2));
            Log(ObvDictionary.SortedList.IndexOfKey(key3));


            ObvDictionary.CollectionChanged += (sender, args) => {
                Assert.That(args.OldItems[0], Is.EqualTo(value2));
                Assert.That(args.OldStartingIndex, Is.EqualTo(2));
                Assert.That(args.NewItems, Is.Null);
                Assert.That(args.NewStartingIndex, Is.EqualTo(-1));
                AssertEvent.Call("collection");
            };

            ObvDictionary.Remove(key2);

            MockEvent.Verify(m => m.Call("collection"), Times.Exactly(1));
        }
Exemple #4
0
        public async Task EventDispatcher_DispatchedAfterSuspend_ThenResume()
        {
            var waitDispatched = new AutoResetEvent(false);
            var executor       = new MockJavaScriptExecutor
            {
                OnCallFunctionReturnFlushedQueue = (p0, p1, p2) =>
                {
                    waitDispatched.Set();
                    return(EmptyResponse);
                },
                OnFlushQueue = () => EmptyResponse,
                OnInvokeCallbackAndReturnFlushedQueue = (_, __) => EmptyResponse
            };

            var context = await CreateContextAsync(executor);

            var dispatcher = new EventDispatcher(context);
            await DispatcherHelpers.RunOnDispatcherAsync(dispatcher.OnResume);

            var testEvent = new MockEvent(42, TimeSpan.Zero, "Foo");

            await DispatcherHelpers.RunOnDispatcherAsync(dispatcher.OnSuspend);

            dispatcher.DispatchEvent(testEvent);

            Assert.IsFalse(waitDispatched.WaitOne(500));

            await DispatcherHelpers.RunOnDispatcherAsync(dispatcher.OnResume);

            Assert.IsTrue(waitDispatched.WaitOne());

            await DispatcherHelpers.CallOnDispatcherAsync(context.DisposeAsync);
        }
Exemple #5
0
        /// <summary>
        /// Tests methods specific to ICollection<>.
        /// </summary>
        /// <param name="collection"></param>
        public void CollectionGenericTest(ICollection <TestItem> collection)
        {
            Assert.IsNotNull(collection as IObservableCollection);

            MockEvent.AddNotifiersCollectionAndProperty(collection as IObservableCollection);
            //Add and count
            collection.Add(Item1);
            Assert.AreEqual(1, collection.Count);
            MockEvent.AssertMockNotifiersCollection(2, 1);

            //Remove Test
            collection.Remove(Item1);
            Assert.AreEqual(0, collection.Count);
            MockEvent.AssertMockNotifiersCollection(2, 1);

            collection.Add(Item1);
            collection.Add(Item2);
            collection.Add(Item3);
            Assert.AreEqual(3, collection.Count);
            MockEvent.AssertMockNotifiersCollection(6, 3);

            collection.Clear();
            Assert.AreEqual(0, collection.Count);
            MockEvent.AssertMockNotifiersCollection(2, 1);

            //Contains Test
            collection.Add(Item1);
            Assert.IsTrue(collection.Contains(Item1));
            Assert.IsFalse(collection.Contains(Item2));

            //Syncroot Test
            Assert.IsFalse(collection.IsReadOnly);

            //IEnumerator/ EnumeratorGeneric test
            collection.Clear();
            collection.Add(Item1);
            collection.Add(Item2);
            collection.Add(Item3);
            Assert.AreEqual(3, collection.Count);

            IEnumerator enumerator = collection.GetEnumerator();

            Assert.IsNotNull(enumerator);
            enumerator.MoveNext();
            Assert.AreEqual(enumerator.Current, Item1);

            IEnumerator <TestItem> enumeratorGeneric = collection.GetEnumerator();

            Assert.IsNotNull(enumeratorGeneric);
            enumeratorGeneric.MoveNext();
            Assert.AreEqual(enumeratorGeneric.Current, Item1);

            //CopyTo test
            var array = new TestItem[3];

            collection.CopyTo(array, 0);
            Assert.AreEqual(array[0], Item1);
            Assert.AreEqual(array[1], Item2);
            Assert.AreEqual(array[2], Item3);
        }
Exemple #6
0
        public async Task EventDispatcher_EventDispatches()
        {
            // TODO: (#288) Check for non-determinism.
            var waitDispatched = new AutoResetEvent(false);
            var executor       = new MockJavaScriptExecutor((p0, p1, p2) =>
            {
                if (p1 == "callFunctionReturnFlushedQueue")
                {
                    waitDispatched.Set();
                }

                return(JArray.Parse("[[],[],[]]"));
            });

            var context = await CreateContextAsync(executor);

            var dispatcher = new EventDispatcher(context);
            await DispatcherHelpers.RunOnDispatcherAsync(dispatcher.OnResume);

            var testEvent = new MockEvent(42, TimeSpan.Zero, "Foo");

            dispatcher.DispatchEvent(testEvent);

            Assert.IsTrue(waitDispatched.WaitOne());

            await DispatcherHelpers.RunOnDispatcherAsync(context.Dispose);
        }
Exemple #7
0
        public void GivenAnEventWhenUsingDefaultConstructorThenDefaultValuesMustBeUsed()
        {
            var now = DateTimeOffset.Now;

            var evt = new MockEvent();

            Assert.NotEqual(default, evt.Id);
 private void AssertMockEventNotifiers(int timesPropertyCalled, int timesCollectionCalled, int timesDictionaryCalled)
 {
     //Sets up event testers
     MockEvent.Verify(m => m.Call("PropertyChanged"), Times.Exactly(timesPropertyCalled));
     MockEvent.Verify(m => m.Call("CollectionChanged"), Times.Exactly(timesCollectionCalled));
     MockEvent.Verify(m => m.Call("DictionaryChanged"), Times.Exactly(timesDictionaryCalled));
 }
Exemple #9
0
        public async Task EventDispatcher_MultipleDispatches()
        {
            await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Initialize);

            var waitDispatched = new AutoResetEvent(false);
            var executor       = new MockJavaScriptExecutor
            {
                OnCallFunctionReturnFlushedQueue = (p0, p1, p2) =>
                {
                    waitDispatched.Set();
                    return(EmptyResponse);
                },
                OnFlushQueue = () => EmptyResponse,
                OnInvokeCallbackAndReturnFlushedQueue = (_, __) => EmptyResponse
            };

            var context = await CreateContextAsync(executor);

            var dispatcher = new EventDispatcher(context);
            await DispatcherHelpers.RunOnDispatcherAsync(dispatcher.OnResume);

            var count = 100;

            for (var i = 0; i < count; ++i)
            {
                var testEvent = new MockEvent(42, "Foo");
                dispatcher.DispatchEvent(testEvent);
                Assert.IsTrue(waitDispatched.WaitOne());
            }

            await DispatcherHelpers.CallOnDispatcherAsync(context.DisposeAsync);

            await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Dispose);
        }
Exemple #10
0
        public async Task EventDispatcher_OnReactInstanceDispose_EventDoesNotDispatch()
        {
            var waitDispatched = new AutoResetEvent(false);
            var executor       = new MockJavaScriptExecutor((p0, p1, p2) =>
            {
                if (p1 == "callFunctionReturnFlushedQueue")
                {
                    waitDispatched.Set();
                }

                return(JArray.Parse("[[],[],[]]"));
            });

            var context = await CreateContextAsync(executor);

            var dispatcher = new EventDispatcher(context);
            await DispatcherHelpers.RunOnDispatcherAsync(dispatcher.OnResume);

            var testEvent = new MockEvent(42, TimeSpan.Zero, "Foo");

            using (BlockJavaScriptThread(context))
            {
                dispatcher.DispatchEvent(testEvent);
                await DispatcherHelpers.RunOnDispatcherAsync(dispatcher.OnReactInstanceDispose);
            }

            Assert.IsFalse(waitDispatched.WaitOne(500));

            await DispatcherHelpers.RunOnDispatcherAsync(context.Dispose);
        }
Exemple #11
0
        public void RegisterTest()
        {
            var container = new IocContainer();
            var store     = new EventStore(container);
            int x         = 1;
            var event1    = new MockEvent <SimpleCommand>((context, command) =>
            {
                x += 1;
                return(true);
            }, (context, command, exception) =>
            {
                x += 2;
            });
            var event2 = new MockEvent <SimpleCommand>((context, command) =>
            {
                x += 3;
                return(true);
            }, (context, command, exception) =>
            {
                x += 4;
            });

            store.Register <SimpleCommand>(event1);
            store.Register <SimpleCommand>(event2);
            Assert.True(store.RaiseExecuting <SimpleCommand>(null, null));
            Assert.Equal(5, x);
            store.RaiseExecuted <SimpleCommand>(null, null, null);
            Assert.Equal(11, x);
        }
        public async Task EventDispatcher_OnReactInstanceDispose_EventDoesNotDispatch()
        {
            var waitDispatched = new AutoResetEvent(false);
            var executor       = new MockJavaScriptExecutor
            {
                OnCallFunctionReturnFlushedQueue = (p0, p1, p2) =>
                {
                    waitDispatched.Set();
                    return(EmptyResponse);
                },
                OnFlushQueue = () => EmptyResponse,
                OnInvokeCallbackAndReturnFlushedQueue = (_, __) => EmptyResponse
            };

            var context = await CreateContextAsync(executor);

            var dispatcher = new EventDispatcher(context);
            await DispatcherHelpers.RunOnDispatcherAsync(dispatcher.OnResume);

            var testEvent = new MockEvent(42, "Foo");

            using (BlockJavaScriptThread(context))
            {
                dispatcher.DispatchEvent(testEvent);
                await DispatcherHelpers.RunOnDispatcherAsync(dispatcher.OnReactInstanceDispose);
            }

            Assert.IsFalse(waitDispatched.WaitOne(500));

            await DispatcherHelpers.CallOnDispatcherAsync(context.DisposeAsync);
        }
        public async Task EventDispatcher_EventDispatches()
        {
            // TODO: (#288) Check for non-determinism.
            var waitDispatched = new AutoResetEvent(false);
            var executor       = new MockJavaScriptExecutor
            {
                OnCallFunctionReturnFlushedQueue = (p0, p1, p2) =>
                {
                    waitDispatched.Set();
                    return(EmptyResponse);
                },
                OnFlushQueue = () => EmptyResponse,
                OnInvokeCallbackAndReturnFlushedQueue = (_, __) => EmptyResponse
            };

            var context = await CreateContextAsync(executor);

            var dispatcher = new EventDispatcher(context);
            await DispatcherHelpers.RunOnDispatcherAsync(dispatcher.OnResume);

            var testEvent = new MockEvent(42, "Foo");

            dispatcher.DispatchEvent(testEvent);

            Assert.IsTrue(waitDispatched.WaitOne());

            await DispatcherHelpers.CallOnDispatcherAsync(context.DisposeAsync);
        }
Exemple #14
0
 public void Bind <T>(T method)
 {
     if (method is MockEvent)
     {
         this.mockEvent += method as MockEvent;
         this.BindedEventsCounter++;
     }
 }
        public async Task Event_Timestamp()
        {
            var e = new MockEvent(42, "foo");
            await Task.Delay(5);

            var b = new MockEvent(42, "bar");

            Assert.IsTrue(e.Timestamp < b.Timestamp);
        }
        public void NodeCollectionCreationTest()
        {
            List <IEvent> eventList = new List <IEvent>();
            IEvent        aEvent    = new MockEvent("item1", DateTime.Now, null, "Access");

            eventList.Add(aEvent);
            App.nodeCollection.nodeList = NodeParser.GetNodes(eventList);
            Assert.AreNotEqual(App.nodeCollection.nodeList.Count, 0);
        }
        public void When_GetEvent_is_called_should_return_correct_event()
        {
            var expected = new MockEvent();
            var ea       = new AsyncEventAggregator();

            var e = ea.GetEvent <MockEvent>();

            e.GetType().ShouldBeEquivalentTo(expected.GetType());
        }
        public async Task Can_Subcribes_Event_Default_Publisher()
        {
            var actualValue        = 0;
            var anotherActualValue = 0;
            var domainEvent        = new MockEvent()
            {
                Id = 100
            };

            var mockDomainEventHandler = new Mock <MockEventHandler>();

            mockDomainEventHandler
            .Setup(x => x.Handle(It.IsAny <MockEvent>()))
            .Callback(() =>
            {
                actualValue = 101;
            });

            var mockDomainEventHandler2 = new Mock <MockEventHandler>();

            mockDomainEventHandler2
            .Setup(x => x.Handle(It.IsAny <MockEvent>()))
            .Callback(() =>
            {
                anotherActualValue = 102;
            });

            _mockServiceProvider
            .Setup(x => x.GetService(It.Is <Type>(type => type == typeof(MockEvent))))
            .Returns(domainEvent);

            _mockServiceProvider
            .Setup(x => x.GetService(It.Is <Type>(type => type == typeof(MockEventHandler))))
            .Returns(mockDomainEventHandler.Object);

            _mockServiceProvider
            .Setup(x => x.GetService(It.Is <Type>(type => type == typeof(AnotherMockEventHandler))))
            .Returns(mockDomainEventHandler2.Object);

            _eventBus.AddSubcription <MockEvent, MockEventHandler>();
            _eventBus.AddSubcription <MockEvent, AnotherMockEventHandler>();

            var mockEventBus = new Mock <IEventBus>();

            mockEventBus.Setup(x => x.PublishAsync(It.IsAny <MockEvent>()))
            .Returns(Task.Run(() =>
            {
                _eventBus.PublishAsync(domainEvent);
                Thread.Sleep(2000);
            }));

            await mockEventBus.Object.PublishAsync(domainEvent);

            Assert.AreEqual(101, actualValue);
            Assert.AreEqual(102, anotherActualValue);
        }
        private void Start()
        {
            Observable.FromEvent <int>(
                h => MockEvent += h,
                h => MockEvent -= h)
            .TakeUntilDestroy(this)
            .Subscribe(count => print("Trigger num:" + count));

            MockEvent?.Invoke(1);
            MockEvent?.Invoke(100);
        }
        public void OnEvent_StateNotSet_OnEvent_NotCalled()
        {
            var called    = false;
            var game      = new GameWorld();
            var mockEvent = new MockEvent();
            var state     = game.RegisterState <MockGameWorldState>();

            state.OnMockEventCallback = (@event) => called = true;
            game.OnEvent(mockEvent);

            Assert.That(called, Is.False);
        }
Exemple #21
0
        public void Apply_SetsVersion()
        {
            const int  version   = 69;
            IAggregate aggregate = new TestAggregate();
            var        @event    = new MockEvent {
                Version = version
            };

            aggregate.Apply(@event);

            Assert.Equal(version, aggregate.Version);
        }
        public void SaveGet_ShouldReturnEvent()
        {
            //arrange
            var mockEvent = new MockEvent();

            //act
            _eventStore.Save(mockEvent);
            var result = _eventStore.GetEvent <MockEvent>();

            //assert
            Assert.Equal(mockEvent.MessageId, result.MessageId);
        }
Exemple #23
0
        public void Unbind <T>(T method)
        {
            if (this.BindedEventsCounter == 0)
            {
                return;
            }

            if (method is MockEvent)
            {
                this.mockEvent -= method as MockEvent;
                this.BindedEventsCounter--;
            }
        }
        public void Event_Initialize_Dispose()
        {
            var e = new MockEvent(42, "Test");

            Assert.IsTrue(e.CanCoalesce);
            Assert.IsTrue(e.IsInitialized);

            Assert.AreEqual(42, e.ViewTag);
            Assert.AreEqual(0, e.CoalescingKey);
            Assert.IsTrue(e.CanCoalesce);

            e.Dispose();
            Assert.IsFalse(e.IsInitialized);
        }
        public void Event_Initialize_Dispose()
        {
            var e = new MockEvent(42, TimeSpan.FromSeconds(10), "Test");

            Assert.IsTrue(e.CanCoalesce);
            Assert.IsTrue(e.IsInitialized);

            Assert.AreEqual(42, e.ViewTag);
            Assert.AreEqual(TimeSpan.FromSeconds(10), e.Timestamp);
            Assert.AreEqual(0, e.CoalescingKey);
            Assert.IsTrue(e.CanCoalesce);

            e.Dispose();
            Assert.IsFalse(e.IsInitialized);
        }
Exemple #26
0
        public void Apply_KeepsHighestVersion()
        {
            const int  version   = 420;
            IAggregate aggregate = new TestAggregate();
            var        event1    = new MockEvent {
                Version = version
            };
            var event2 = new MockEvent {
                Version = version - 69
            };

            aggregate.Apply(event1);
            aggregate.Apply(event2);

            Assert.Equal(version, aggregate.Version);
        }
Exemple #27
0
 public void NullEventRaiseTest()
 {
     Debug.WriteLine("MockEvent: " + MockEvent);
     try
     {
         MockEvent.Raise(this, EventArgs.Empty);
         MockEvent.RaiseEmpty(this);
         MockGenericEvent.Raise(this, new PropertyChangedEventArgs("mockPropoerty"));
     }
     catch (Exception e)
     {
         Assert.Fail("Exception was thrown on null event raise: " + e);
     }
     Assert.IsTrue(MockEvent == null);
     Assert.IsTrue(true);
 }
Exemple #28
0
        private MockEvent GivenEvent()
        {
            var givenEvent = new MockEvent()
            {
                Id = Guid.NewGuid()
            };

            dbContext.OutboxEvents.Add(new OutboxEvent()
            {
                CreatedDate = DateTimeOffset.Now,
                EventName   = givenEvent.GetType().AssemblyQualifiedName,
                Payload     = JsonSerializer.Serialize(givenEvent)
            });
            dbContext.SaveChanges();
            return(givenEvent);
        }
        public async Task Saved_events_can_retreived()
        {
            var event1 = new MockEvent {
                Id = Guid.NewGuid(), Version = 1
            };
            var cancellationToken = default(CancellationToken);

            await _inMemoryDb.Save(new List <IEvent> {
                event1
            });

            var retreivedEvents = await _inMemoryDb.Get(event1.Id, 0, cancellationToken);

            Assert.Single(retreivedEvents);
            Assert.Same(event1, retreivedEvents.ToList().ElementAt(0));
        }
Exemple #30
0
        public void TestLoop()
        {
            var timeline    = new Timeline();
            var fixedEvents = new List <MockEvent> {
                new MockEvent("F0"), new MockEvent("F1"), new MockEvent("F2")
            };
            var evenEvent = new MockEvent("even")
            {
                RepeatTurns = 2
            };
            var turn3Event = new MockEvent("turn3")
            {
                RepeatTurns = 3, OnHit = m => m.RepeatTurns = -1
            };

            var sporadicEvents = new List <(MockEvent, int)> {
                (new MockEvent("S0-3"), 3), (new MockEvent("S0-7"), 7), (new MockEvent("S0-5"), 5)
            };

            // Change initial time point;
            for (int i = 0; i < 12; ++i)
            {
                timeline.Run();
            }

            // Add events
            foreach (var l in fixedEvents)
            {
                timeline.Insert(l);
            }
            timeline.Insert(evenEvent);
            timeline.Insert(turn3Event);

            // Check for event hits per type of event.
            for (var i = 0; i < 10; i++)
            {
                foreach (var l in fixedEvents)
                {
                    Assert.AreEqual(i, l.Hits);
                }

                Assert.AreEqual(i / 2, evenEvent.Hits);
                Assert.AreEqual(i < 3 ? 0 : 1, turn3Event.Hits);

                timeline.Run();
            }
        }