示例#1
0
        public static void HasValidMemento <T>(T aggregate)
            where T : AggregateRoot
        {
            if (aggregate == null)
            {
                throw new ArgumentNullException("aggregate");
            }

            var memento = aggregate.GetMemento();

            if (memento == null)
            {
                throw new Exception("No memento defined!");
            }

            var sameAggregate = Factory.Create <T>(memento, aggregate.Revision, Enumerable.Empty <object>(), "test");
            var sameMemento   = sameAggregate.GetMemento();

            var expected = Serializer.Serialize(memento);
            var actual   = Serializer.Serialize(sameMemento);

            if (actual != expected)
            {
                throw new Exception("Invalid memento implementation!");
            }
        }
示例#2
0
        protected override void Given()
        {
            var aggregate = AggregateRootFactory.Create <AccountAggregateRoot>();

            aggregate.InitialiseAccount(AggregateId, "account-id");
            aggregate.AddAmount(2.00M);
            Subject.Save(aggregate);
        }
示例#3
0
        protected override void Given()
        {
            ReloadedAccountAggregateRoot = AggregateRootFactory.Create <NonDisposingAccountAggregateRoot>();
            ReloadedAccountAggregateRoot.InitialiseAccount(AggregateId, "account-id");
            ReloadedAccountAggregateRoot.AddAmount(2.00M);

            // intermediate save should cause a concurrency error when we save below
            Subject.Save(ReloadedAccountAggregateRoot);

            ReloadedAccountAggregateRoot.AddAmount(5.00M);
        }
示例#4
0
        public void CanReconstitute()
        {
            // arrange
            var memento = (object)null;
            var events  = new[] { new SomethingHappened() };
            var factory = new AggregateRootFactory();

            // act
            var aggregateRoot = factory.Create <PersistedAggregate>(memento, 0, events, "state");

            aggregateRoot.MakeSomethingHappen();

            // assert
            aggregateRoot.ThingsThatHappened.Should().HaveCount(2);
        }
示例#5
0
 /// <summary>
 /// Factory method to create a post
 /// </summary>
 /// <param name="factory">The factory to be used for AggregateRootCreation</param>
 /// <param name="title"></param>
 /// <param name="textContent"></param>
 /// <returns></returns>
 public static Post CreatePost(
     AggregateRootFactory factory,
     String title,
     String textContent,
     String excerpt,
     String blogName)
 {
     //Slug is created replacing any non number or letter char with a dash
     //accents are removed
     String slug = title.Slugify();
     if (String.IsNullOrEmpty(excerpt))
     {
         //Need to calculate the excerpt of the post, in this version just take some text from the
         //body of the post.
         HtmlDocument doc = new HtmlDocument();
         doc.LoadHtml(textContent);
         excerpt = doc.DocumentNode.InnerText;
         if (excerpt.Length > 200) excerpt = excerpt.Substring(0, 200) + "...";
     }
     var evt = new PostCreated(title, textContent, slug, blogName, excerpt);
     return factory.Create<Post>(evt);
 }
 public static CategoryManager Create(AggregateRootFactory factory, String id)
 {
     return factory.Create<CategoryManager>();
 }