Example #1
0
    public override BTEvent Clone()
    {
        TestEvent1 newObject = (TestEvent1)base.Clone();

        newObject.participant1   = this.participant1;
        newObject.participant2   = this.participant2;
        newObject.test_a         = this.test_a;
        newObject.participant1_d = this.participant1_d;
        newObject.participant2_d = this.participant2_d;
        return(newObject);
    }
        public void LoadFromHistory_WhenInvoked_MustApplyEvents()
        {
            // Arrange
            var testEvent1 = new TestEvent1();
            var testEvent2 = new TestEvent2();
            var expected   = new IEvent[] { testEvent1, testEvent2 };
            var subject    = new TestAggregate();

            // Act
            subject.LoadFromHistory(expected);

            // Assert
            Assert.That(subject.AppliedEvents, Is.EqualTo(expected));
        }
        public void LoadFromHistory_WhenInvoked_MustNotAddEventsToUnpublishedEventsCollection()
        {
            // Arrange
            var testEvent1 = new TestEvent1();
            var testEvent2 = new TestEvent2();
            var events     = new IEvent[] { testEvent1, testEvent2 };
            var subject    = new TestAggregate();

            // Act
            subject.LoadFromHistory(events);

            // Assert
            Assert.That(subject.GetUncommitedChanges(), Is.Empty);
        }
        public void deal_with_event_member_when_applying()
        {
            var expectedResult = string.Empty;

            var player = new EventPlayer();

            player.Add <TestEvent1>(a => { expectedResult = a.Test; });

            var ev = new TestEvent1()
            {
                Test = "ESSAI"
            };

            player.Apply(ev);

            expectedResult.Should().Be("ESSAI");
        }
        public void CheckNormalUsage()
        {
            // TestEvent1

            var handled = false;
            var id      = Guid.NewGuid().ToString("D");
            var sender  = new object();

            EventHandler <TestEventArgs> handler = (x, args) => { handled = true; Assert.Equal(id, args.Id); Assert.Same(sender, x); };

            TestEvent1.SafeInvoke(nameof(TestEvent1), sender, () => new TestEventArgs()
            {
                Id = id
            }, ArgsUsageKind.Reuse);

            Assert.False(handled);

            TestEvent1 += handler;

            TestEvent1.SafeInvoke(nameof(TestEvent1), sender, () => new TestEventArgs()
            {
                Id = id
            }, ArgsUsageKind.Reuse);

            Assert.True(handled);

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                TestEvent1.SafeInvoke(nameof(TestEvent1), sender, () => new TestEventArgs()
                {
                    Id = id
                }, ArgsUsageKind.Unknown);
            });

            TestEvent1 -= handler;

            handled = false;

            TestEvent1.SafeInvoke(nameof(TestEvent1), sender, () => new TestEventArgs()
            {
                Id = id
            }, ArgsUsageKind.Reuse);

            Assert.False(handled);
        }
Example #6
0
 public void Handle(TestEvent1 @event)
 {
     base.Handle(@event);
 }
Example #7
0
        public Task HandleAsync(TestEvent1 @event)
        {
            base.HandleAsync(@event);

            return(Task.FromException(new TestEventHandlerException($"This is a triggered post-processing exception at { GetType().Name }.{nameof(HandleAsync)}({nameof(TestEvent1)}).")));
        }
Example #8
0
 public void HandleWithException(TestEvent1 @event)
 {
     base.Handle(@event);
     throw new TestEventHandlerException($"This is a triggered post-processing exception at { GetType().Name }.{nameof(Handle)}({nameof(TestEvent1)}).");
 }
Example #9
0
        public override void Handle(TestEvent1 @event)
        {
            base.Handle(@event);

            throw new TestEventHandlerException($"This is a triggered post-processing exception at { GetType().Name }.");
        }
Example #10
0
 public Task Handle(TestEvent1 theEvent)
 {
     return(TaskCompletionSource.Task);
 }
Example #11
0
 public void Handle(TestEvent1 command, ILifetimeScope context)
 {
     ParameterScopeTag = context.Tag;
 }
Example #12
0
 public void TriggerTestEvent1()
 {
     TestEvent1?.Invoke(TransmissionInfo.Empty);
 }
Example #13
0
 protected virtual void OnTestEvent1(TestEventArgs e) => TestEvent1?.Invoke(this, e);
 public void TriggerTestEvent1()
 {
     TestEvent1?.Invoke(this, EventArgs.Empty);
 }
 private void When(TestEvent1 @event)
 {
     appliedEvents.Add(@event);
 }
Example #16
0
        static void Main(string[] args)
        {
            AutofacConfig.Register();
            using (Event.Subscribe((object x) => Task.FromResult(true), false))
            {
                try
                {
                    bool r = (1).RaiseAsync().Result;
                }
                catch
                {
                    Console.WriteLine("Value types cannot be used to raise event");
                }
            }
            Console.WriteLine("\tTest1");
            Console.WriteLine("ExecuteAsync(): TestEventHandler2 is going to be canceled, but TestEventHandler1 and TestEventHandler3 will reply");

            CancellationTokenSource ctc = new CancellationTokenSource(900);

            try
            {
                new TestEvent1().ExecuteAsync(async(string e) =>
                {
                    Console.WriteLine(e);
                    return(true);
                }, ctc.Token).Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("\tTest2");
            Console.WriteLine("WaitAll(): returns replies from TestEventHandler1 and TestEventHandler3");
            ctc = new CancellationTokenSource(900);
            IEnumerable <string> results = null;

            try
            {
                results = new TestEvent1().WaitAll <string>(ctc.Token);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                foreach (var r in results)
                {
                    Console.WriteLine(r);
                }
            }

            Console.WriteLine("\tTest3");
            Console.WriteLine("WaitAsync: casts cancel exception");
            ctc = new CancellationTokenSource(900);
            try
            {
                var res = new TestEvent1().WaitAsync <string>(ctc.Token);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }