public void WhenAutoWiredDomainActionPerformed_ThenRootChangesStateThroughEvent()
        {
            var root = new AutoWiredTestRoot();

            root.Publish(5);

            Assert.Equal(5, root.LatestVersion);
            Assert.True(root.GetEvents().Any());
            Assert.True(root.GetEvents().OfType <TestPublished>().Any(x => x.Version == 5));
        }
        public void WhenSubsequentAutoWiredDomainActionPerformed_ThenRootChangesStateThroughEvent()
        {
            var root = new AutoWiredTestRoot();

            root.Publish(5);

            Assert.True(root.IsPublished);

            root.Unpublish();

            Assert.False(root.IsPublished);
        }
        public void WhenComparingManualVsAutoWired_ThenItIsAsFastAsManual()
        {
            // warmup
            var manual = new ManualWiredTestRoot();
            var auto   = new AutoWiredTestRoot();

            var repeat = 500000;
            var watch  = Stopwatch.StartNew();

            for (int i = 0; i < repeat; i++)
            {
                new ManualWiredTestRoot().Publish(5);
            }

            watch.Stop();

            var averageManual = watch.ElapsedTicks / repeat;

            Console.WriteLine("Average per publish (Manual): {0}", watch.ElapsedTicks / repeat);

            watch = Stopwatch.StartNew();

            for (int i = 0; i < repeat; i++)
            {
                new AutoWiredTestRoot().Publish(5);
            }

            watch.Stop();

            Console.WriteLine("Average per publish (Autowire): {0}", watch.ElapsedTicks / repeat);

            var averageAuto = watch.ElapsedTicks / repeat;

            // We're as fast as manual.
            Assert.True(averageAuto <= averageManual);
        }