Esempio n. 1
0
        public void ExpectMessages(params Event[] g)
        {
            _thenWasCalled = true;
            _then.AddRange(g);

            IEnumerable<Event> actual;
            var givenEvents = _givenEvents.ToArray();

            if (_dontExecuteOnExpect) return;
            try
            {
                actual = ExecuteCommand(givenEvents, _when);
            }
            catch (DomainError e)
            {
                actual = new Event[] { new ExceptionThrown(e.Name) };
            }

            var results = CompareAssert(_then.ToArray(), actual.ToArray()).ToArray();

            PrintSpecification();
            PrintResults(results);

            if (results.Any(r => r.Failure != null))
                Assert.Fail("Specification failed");
        }
Esempio n. 2
0
        protected static IEnumerable<ExpectResult> CompareAssert(
			Event[] expected,
			Event[] actual)
        {
            var max = Math.Max(expected.Length, actual.Length);

            for (int i = 0; i < max; i++)
            {
                var ex = expected.Skip(i).FirstOrDefault();
                var ac = actual.Skip(i).FirstOrDefault();

                var expectedString = ex == null ? "No event expected" : ex.ToString();
                var actualString = ac == null ? "No event actually" : ac.ToString();

                var result = new ExpectResult { Expectation = expectedString };

                var realDiff = CompareObjects.FindDifferences(ex, ac);
                if (!string.IsNullOrEmpty(realDiff))
                {
                    var stringRepresentationsDiffer = expectedString != actualString;

                    result.Failure = stringRepresentationsDiffer ?
                                     GetAdjusted("Was:  ", actualString) :
                                     GetAdjusted("Diff: ", realDiff);
                }

                yield return result;
            }
        }
Esempio n. 3
0
 protected abstract Event[] ExecuteCommand(Event[] store, Command cmd);
Esempio n. 4
0
 public EventDescriptor(Guid id, Event eventData, int version)
 {
     EventData = eventData;
     Version = version;
     Id = id;
 }