コード例 #1
0
        public void Creating_instance_should_succeed_when_type_is_subclass_of_AggregateRoot_and_has_default_ctor()
        {
            var correctType = typeof(AggRootWithDefaultCtor);
            var creator     = new SimpleAggregateRootCreationStrategy();

            creator.CreateAggregateRoot(correctType);
        }
コード例 #2
0
        public AggregateRootTestFixture() : base()
        {
            Guid commitId = Guid.NewGuid();
            Guid sourceId = Guid.NewGuid();

            CreationStrategy = new SimpleAggregateRootCreationStrategy();

            AggregateRoot   = CreationStrategy.CreateAggregateRoot <TAggregateRoot>();
            PublishedEvents = new List <UncommittedEvent>();

            var history = Given();

            if (history != null)
            {
                long sequence = 0;
                var  stream   = Prepare.Events(history).ForSource(AggregateRoot.EventSourceId);
                AggregateRoot.InitializeFromHistory(stream);
            }

            try
            {
                AggregateRoot.EventApplied += (s, e) => PublishedEvents.Add(e.Event);
                When();
            }
            catch (Exception exception)
            {
                CaughtException = exception;
            }
            finally
            {
                Finally();
            }
        }
コード例 #3
0
        [SetUp] // TODO: Testdriven.net debug runner doesn't recognize inhiret attributes. Use native for now.
        public void Setup()
        {
            CreationStrategy = new SimpleAggregateRootCreationStrategy();

            AggregateRoot   = CreationStrategy.CreateAggregateRoot <TAggregateRoot>();
            PublishedEvents = new SourcedEvent[0];

            var history = Given();

            if (history != null)
            {
                AggregateRoot.InitializeFromHistory(history);
            }

            try
            {
                When();
                PublishedEvents = AggregateRoot.GetUncommittedEvents();
            }
            catch (Exception exception)
            {
                CaughtException = exception;
            }
            finally
            {
                Finally();
            }
        }
コード例 #4
0
        public void Creation_result_by_correct_type_should_be_of_specified_type()
        {
            var correctType = typeof(AggRootWithDefaultCtor);
            var creator     = new SimpleAggregateRootCreationStrategy();

            var result = creator.CreateAggregateRoot(correctType);

            result.Should().BeOfType <AggRootWithDefaultCtor>();
        }
コード例 #5
0
        public void Creation_result_by_correct_type_should_not_be_null()
        {
            var correctType = typeof(AggRootWithDefaultCtor);
            var creator     = new SimpleAggregateRootCreationStrategy();

            var result = creator.CreateAggregateRoot(correctType);

            result.Should().NotBeNull();
        }
コード例 #6
0
        public void Creating_non_aggregate_root_type_should_throw()
        {
            var wrongType = typeof(Stream);
            var creator   = new SimpleAggregateRootCreationStrategy();

            Action act = () => creator.CreateAggregateRoot(wrongType);

            act.ShouldThrow <ArgumentException>().And.ParamName.Should().Be("aggregateRootType");
        }
コード例 #7
0
        public void Creating_without_default_ctor_should_throw()
        {
            var wrongType = typeof(AggRootWithoutDefaultCtor);
            var creator   = new SimpleAggregateRootCreationStrategy();

            Action act = () => creator.CreateAggregateRoot(wrongType);

            act.ShouldThrow <AggregateRootCreationException>().And.Message.Should().Contain(wrongType.FullName);
        }