public void ItCannotCreateAlreadyCreatedForum()
    {
      // Arrange
      CreateForumCommand c = new CreateForumCommand(new ForumId(), "Hello", "Blah");
      Service.Handle(c);

      // Act + Assert
      AssertThrows<DomainException>(
        () => Service.Handle(c),
        ex => { Assert.AreEqual("Recreated", ex.Name); });
    }
    public void CanCreateAndGetForum()
    {
      // Act
      CreateForumCommand cmd = new CreateForumCommand(new ForumId(), "Forum 1", "Blah blah");
      Service.Handle(cmd);

      Forum f = Repository.Get(cmd.Id).Aggregate;

      // Assert
      Assert.AreEqual(cmd.Id, f.Id);
      Assert.AreEqual(cmd.Title, f.Title);
      Assert.AreEqual(cmd.Description, f.Description);
    }
Пример #3
0
        static void Main(string[] args)
        {
            var serializerTypes =
                typeof(ForumId).Assembly.GetTypes()
                .Where(t => typeof(Identity <>).IsAssignableFrom(t) || typeof(IMessage).IsAssignableFrom(t))
                .Where(t => !t.IsAbstract);

            Assembly[] handlerAssemblies = new Assembly[] { typeof(ForumApplicationService).Assembly };

            IMessageBus bus = Configure.With()
                              .Log4Net()
                              .ObjectContainer(Xyperico.Base.ObjectContainer.Container)
                              .SerializableTypes(serializerTypes)
                              .MessageBus(handlerAssemblies)
                              .WithJsonSubscriptionSerializer()
                              //.WithDataContractSubscriptionSerializer()
                              //.WithProtoBufSubscriptionSerializer()
                              //.WithBsonSubscriptionSerializer()
                              .WithFileSubscriptionStore("C:\\tmp\\Xyperico.Discuss.TestStorage")
                              .WithJsonMessageSerializer()
                              //.WithDataContractMessageSerializer()
                              //.WithProtoBufMessageSerializer()
                              //.WithBsonMessageSerializer()
                              .WithMSMQ(".\\private$\\comsite")
                              .Done()
                              .EventStore()
                              .WithSQLiteEventStore(SQLiteConnectionString, true)
                              //.WithSqlServerEventStore(SqlConnectionString, true)
                              .WithJsonEventSerializer()
                              //.WithDataContractEventSerializer()
                              //.WithProtoBufEventSerializer()
                              //.WithBsonEventSerializer()
                              //.WithJsonDocumentSerializer()
                              //.WithDataContractDocumentSerializer()
                              .WithProtoBufDocumentSerializer()
                              //.WithBsonDocumentSerializer()
                              .WithFileDocumentStore("C:\\tmp\\Xyperico.Discuss.TestStorage")
                              .Done()
                              .Start();

            // Supported serializers: JSON, BSON, DataContract, ProtoBuf

            do
            {
                CreateForumCommand cmd = new CreateForumCommand(new ForumId(), "Test forum", "Blah blah");
                bus.Send(cmd);
            }while (Console.ReadLine() == "");
        }
Пример #4
0
        public void CreateForumAsForumChild()
        {
            var parentCategory = Substitute.For <Domain.Category>("category", 1, "desc");

            parentCategory.Id.Returns("1");

            var parentForum = Substitute.For <Domain.Forum>(parentCategory, "category", 1, "desc");

            parentForum.Id.Returns("1");

            var inputParameter = new Domain.Forum(parentForum, "name", 1, "description");
            var command        = new CreateForumCommand {
                ParentForumId = parentForum.Id, Name = inputParameter.Name, SortOrder = inputParameter.SortOrder, Description = inputParameter.Description
            };
            var dto = Substitute.For <IForumDto>();

            var categoryDatastore = Substitute.For <ICategoryDatastore>();
            var datalayerCategory = Substitute.For <ICategoryDto>();

            datalayerCategory.Id.Returns("1");
            categoryDatastore.ReadById(parentCategory.Id).Returns(datalayerCategory);

            var datalayerForum = Substitute.For <IForumDto>();

            datalayerForum.Id.Returns("1");

            var datastore = Substitute.For <IForumDatastore>();

            datastore.CreateAsForumChild(inputParameter).Returns <IForumDto>(dto);
            var taskDatastore = Substitute.For <ITaskDatastore>();

            CreateForumCommandHandler handler = new CreateForumCommandHandler(categoryDatastore, datastore, taskDatastore);
            GenericValidationCommandHandlerDecorator <CreateForumCommand> val =
                new GenericValidationCommandHandlerDecorator <CreateForumCommand>(
                    handler,
                    new List <IValidator <NForum.CQS.Commands.Forums.CreateForumCommand> > {
                new NForum.CQS.Validators.Forums.CreateForumValidator(TestUtils.GetInt32IdValidator())
            }
                    );

            val.Execute(command);

            datastore.ReceivedWithAnyArgs(1).CreateAsForumChild(inputParameter);
        }
    public void CanUpdateForum()
    {
      // Arrange
      CreateForumCommand cmd = new CreateForumCommand(new ForumId(), "Forum 1", "Blah blah");
      Service.Handle(cmd);

      Forum f2 = Repository.Get(cmd.Id).Aggregate;

      // Act
      UpdateForumCommand cmd2 = new UpdateForumCommand(cmd.Id, "Forum A", "Oh well");
      Service.Handle(cmd2);

      Forum f3 = Repository.Get(cmd.Id).Aggregate;

      // Assert
      Assert.AreEqual(cmd.Id, f3.Id);
      Assert.AreEqual("Forum A", f3.Title);
      Assert.AreEqual("Oh well", f3.Description);
    }
Пример #6
0
    static void Main(string[] args)
    {
      var serializerTypes =
        typeof(ForumId).Assembly.GetTypes()
        .Where(t => typeof(Identity<>).IsAssignableFrom(t) || typeof(IMessage).IsAssignableFrom(t))
        .Where(t => !t.IsAbstract);

      Assembly[] handlerAssemblies = new Assembly[] { typeof(ForumApplicationService).Assembly };

      IMessageBus bus = Configure.With()
        .Log4Net()
        .ObjectContainer(Xyperico.Base.ObjectContainer.Container)
        .SerializableTypes(serializerTypes)
        .MessageBus(handlerAssemblies)
          .WithJsonSubscriptionSerializer()
          //.WithProtoBufSubscriptionSerializer()
          .WithFileSubscriptionStore("C:\\tmp\\Xyperico.Discuss.TestStorage")
          //.WithJsonMessageSerializer()
          .WithProtoBufMessageSerializer()
          .WithMSMQ(".\\private$\\comsite")
          .Done()
        .EventStore()
          .WithSQLiteEventStore(SqlConnectionString, true)
          .WithJsonEventSerializer()
          .WithJsonDocumentSerializer()
          .WithFileDocumentStore("C:\\tmp\\Xyperico.Discuss.TestStorage")
          .Done()
        .Start();

      do
      {
        CreateForumCommand cmd = new CreateForumCommand(new ForumId(), "Test forum", "Blah blah");
        bus.Send(cmd);
      }
      while (Console.ReadLine() == "");
    }
Пример #7
0
        public void Create(CreateForumCommand cmd)
        {
            Condition.Requires(cmd, "cmd").IsNotNull();

            Publish(new ForumCreatedEvent(cmd.Id, cmd.Title, cmd.Description));
        }
Пример #8
0
 public void Handle(CreateForumCommand cmd)
 {
     Console.WriteLine("Received CreateForumCommand");
     Update(cmd, f => f.Create(cmd));
 }