public void Assert()
        {
            Exception exception = null;

            try
            {
                if (_entity != null)
                {
                    using (var t = _context.OpenSession(_message))
                    {
                        t.SaveAndPublishEvents(_entity);
                    }
                }

                _context.ClearGeneratedEvents();

                InvokeHandler();
            }
            catch (Exception ex)
            {
                exception = ex.GetBaseException();
            }

            NUnit.Framework.Assert.That(
                (object)exception,
                (IResolveConstraint) new ExceptionTypeConstraint(typeof(TException)),
                "Expected exception was not thrown.",
                null);
        }
Exemplo n.º 2
0
        public void Assert()
        {
            if (_entity != null)
            {
                using (var t = _context.OpenSession(_message))
                {
                    t.SaveAndPublishEvents(_entity);
                }
            }

            _context.ClearGeneratedEvents();

            var expected = _expected(_entity, _message);

            /*
             * Invoke the message on the handler and retrieve the actual
             * events from the repository and eventbus, and compare both with the
             * expected events list passed-in using Inforigami.Regalo.ObjectCompare.
             */
            InvokeHandler();

            var eventsStoredToEventStore = _context.GetGeneratedEvents();

            var comparer = ObjectComparerProvider.Create();

            ObjectComparisonResult result = comparer.AreEqual(expected, eventsStoredToEventStore);

            if (!result.AreEqual)
            {
                var message = $"Actual events did not match expected events. {result.InequalityReason}";

                if (expected.Any() && !eventsStoredToEventStore.Any())
                {
                    message +=
                        "\r\nCheck that your Scenario-based test is using the same IMesasageHandlerContext throughout, in case events are written to one assertions are performed against another.";
                }

                throw new AssertionException(message);
            }
        }