コード例 #1
0
ファイル: Assertions.cs プロジェクト: ddd-cqrs-es/NAuthorize
        public static void AssertThrows(this IWhenStateBuilder builder, Exception expectedException)
        {
            using (var scope = CompositionRoot.Instance.BeginLifetimeScope()) {
                var specification = builder.Throws(expectedException).Build();

                StoreGivens(scope, specification.Givens);

                try {
                    HandleWhen(scope, specification.When);

                    NUnit.Framework.Assert.Fail(
                        "Expected the following exception to be thrown:\n\tType:{0}\n\tMessage:{1}.",
                        specification.Throws.GetType().Name,
                        specification.Throws.Message);
                }
                catch (AssertionException) {
                    throw;
                }
                catch (Exception actualException) {
                    NUnit.Framework.Assert.That(
                        actualException.GetType(),
                        Is.EqualTo(specification.Throws.GetType()),
                        "Expected an exception of type {0} but was of type {1}.",
                        specification.Throws.GetType().Name,
                        actualException.GetType().Name);

                    NUnit.Framework.Assert.That(
                        actualException.Message,
                        Is.EqualTo(specification.Throws.Message),
                        "Expected an exception with a specific message:\n\tExpected Message:{0}\n\tActual Message:{1}",
                        specification.Throws.Message, actualException.Message);
                }
            }
        }
コード例 #2
0
ファイル: Assertions.cs プロジェクト: ddd-cqrs-es/NAuthorize
        public static void AssertNothingHappened(this IWhenStateBuilder builder)
        {
            using (var scope = CompositionRoot.Instance.BeginLifetimeScope()) {
                var specification = builder.Build();

                StoreGivens(scope, specification.Givens);

                HandleWhen(scope, specification.When);

                var unitOfWork = scope.Resolve <UnitOfWork>();
                NUnit.Framework.Assert.That(unitOfWork.GetChanges().SelectMany(aggregate => aggregate.Root.GetChanges()), Is.Empty,
                                            "Expected no events but found the following events:\n\t{0}",
                                            string.Join(",", unitOfWork.GetChanges().SelectMany(aggregate => aggregate.Root.GetChanges()).Select(@event => @event.GetType().Name)));
            }
        }
コード例 #3
0
            public static IThenStateBuilder Then(this IWhenStateBuilder builder, params IEvent[] events)
            {
                if (events == null)
                {
                    throw new ArgumentNullException("events");
                }
                if (events.Length == 0)
                {
                    return(builder.Then(Guid.Empty.ToString(), new object[0]));
                }

                using (var enumerator = events.AsEnumerable().GetEnumerator())
                {
                    enumerator.MoveNext();
                    var continuation = builder.Then(enumerator.Current.Id.ToString(), enumerator.Current);
                    while (enumerator.MoveNext())
                    {
                        continuation = continuation.Then(enumerator.Current.Id.ToString(), enumerator.Current);
                    }
                    return(continuation);
                }
            }