コード例 #1
0
        public void UserCreateTest()
        {
            using (var lifetime = container.BeginLifetimeScope())
            {
                DefaultCommandBus commandBus = lifetime.Resolve <DefaultCommandBus>();
                IMappingEngine    mapper     = lifetime.Resolve <IMappingEngine>();

                User user = new User()
                {
                    FirstName   = "Test",
                    LastName    = "User",
                    Email       = "*****@*****.**",
                    DateCreated = DateTime.Now,
                    RoleId      = 1,
                    Activated   = true
                };

                UserRegisterCommand command = mapper.Map <UserRegisterCommand>(user);
                command.Password = "******";

                IValidationHandler <UserRegisterCommand> validationHandler = lifetime.Resolve <IValidationHandler <UserRegisterCommand> >();
                IEnumerable <ValidationResult>           validations       = commandBus.Validate(command, validationHandler);
                foreach (var val in validations)
                {
                    Assert.IsNull(val, "Error: User creation did not validate " + val.Message);
                }
                ICommandHandler <UserRegisterCommand> commnadHandler = lifetime.Resolve <ICommandHandler <UserRegisterCommand> >();
                ICommandResult result = commandBus.Submit(command, commnadHandler);
                Assert.IsNotNull(result, "Error: User was not created by CommandBus");
                Assert.IsTrue(result.Success, "Error: User was not created by CommandBus");
            }
        }
コード例 #2
0
ファイル: Expense.cs プロジェクト: zszqwe/FNHMVC
        public void ExpenseCreateTest()
        {
            using (var lifetime = container.BeginLifetimeScope())
            {
                DefaultCommandBus   commandBus         = lifetime.Resolve <DefaultCommandBus>();
                ICategoryRepository categoryRepository = lifetime.Resolve <ICategoryRepository>();
                IMappingEngine      mapper             = lifetime.Resolve <IMappingEngine>();

                Category category = categoryRepository.GetAll().FirstOrDefault();

                Expense expense = new Expense()
                {
                    Amount          = 120,
                    Date            = DateTime.Now,
                    Category        = category,
                    TransactionDesc = "Test transaction."
                };

                CreateOrUpdateExpenseCommand command = mapper.Map <CreateOrUpdateExpenseCommand>(expense);

                ICommandHandler <CreateOrUpdateExpenseCommand> commnadHandler = lifetime.Resolve <ICommandHandler <CreateOrUpdateExpenseCommand> >();
                ICommandResult result = commandBus.Submit(command, commnadHandler);
                Assert.IsNotNull(result, "Error: Tipo Via Was Not Created by CommandBus");
                Assert.IsTrue(result.Success, "Error: Tipo Via Was Not Created by CommandBus");
            }
        }
コード例 #3
0
        public void UserChangePasswordTest()
        {
            using (var lifetime = container.BeginLifetimeScope())
            {
                IUserRepository   userRepository = lifetime.Resolve <IUserRepository>();
                DefaultCommandBus commandBus     = lifetime.Resolve <DefaultCommandBus>();

                User user = userRepository.Get(c => c.Email == "*****@*****.**");
                Assert.IsNotNull(user, "Error: User was not found");

                ChangePasswordCommand command = new ChangePasswordCommand();
                command.UserId      = user.UserId;
                command.OldPassword = "******";
                command.NewPassword = "******";

                IValidationHandler <ChangePasswordCommand> validationHandler = lifetime.Resolve <IValidationHandler <ChangePasswordCommand> >();
                IEnumerable <ValidationResult>             validations       = commandBus.Validate(command, validationHandler);
                foreach (var val in validations)
                {
                    Assert.IsNull(val, "Error: User password change did not validate " + val.Message);
                }
                ICommandHandler <ChangePasswordCommand> commnadHandler = lifetime.Resolve <ICommandHandler <ChangePasswordCommand> >();
                ICommandResult result = commandBus.Submit(command, commnadHandler);
                Assert.IsNotNull(result, "Error: User password change did not work");
                Assert.IsTrue(result.Success, "Error: User password change did not work");
            }
        }
コード例 #4
0
ファイル: Expense.cs プロジェクト: zszqwe/FNHMVC
        public void ExpenseUpdateTest()
        {
            Expense expense = null;

            using (var lifetime = container.BeginLifetimeScope())
            {
                IExpenseRepository expenseRepository = lifetime.Resolve <IExpenseRepository>();
                DefaultCommandBus  commandBus        = lifetime.Resolve <DefaultCommandBus>();
                IMappingEngine     mapper            = lifetime.Resolve <IMappingEngine>();

                expense = expenseRepository.Get(c => c.Amount == 120);
                Assert.IsNotNull(expense, "Error: Expense was not found");
                expense.Amount = 150;
            }

            using (var lifetime = container.BeginLifetimeScope())
            {
                IExpenseRepository expenseRepository = lifetime.Resolve <IExpenseRepository>();
                DefaultCommandBus  commandBus        = lifetime.Resolve <DefaultCommandBus>();
                IMappingEngine     mapper            = lifetime.Resolve <IMappingEngine>();

                CreateOrUpdateExpenseCommand command = mapper.Map <CreateOrUpdateExpenseCommand>(expense);

                ICommandHandler <CreateOrUpdateExpenseCommand> commnadHandler = lifetime.Resolve <ICommandHandler <CreateOrUpdateExpenseCommand> >();
                ICommandResult result = commandBus.Submit(command, commnadHandler);
                Assert.IsNotNull(result, "Error: Expense was not updated");
                Assert.IsTrue(result.Success, "Error: Expense was not updated");
            }
        }
コード例 #5
0
ファイル: CategoryTest.cs プロジェクト: zszqwe/FNHMVC
        public void CategoryCreateTest()
        {
            using (var lifetime = container.BeginLifetimeScope())
            {
                ICategoryRepository categoryRepository = lifetime.Resolve <ICategoryRepository>();
                DefaultCommandBus   commandBus         = lifetime.Resolve <DefaultCommandBus>();
                IMappingEngine      mapper             = lifetime.Resolve <IMappingEngine>();

                Category category = new Category()
                {
                    Name        = "Test Category",
                    Description = "This is a test category"
                };

                CreateOrUpdateCategoryCommand command = mapper.Map <CreateOrUpdateCategoryCommand>(category);
                IValidationHandler <CreateOrUpdateCategoryCommand> validationHandler = lifetime.Resolve <IValidationHandler <CreateOrUpdateCategoryCommand> >();
                IEnumerable <ValidationResult> validations = commandBus.Validate(command, validationHandler);
                foreach (var val in validations)
                {
                    Assert.IsNull(val, "Error: Category creation did not validate " + val.Message);
                }
                ICommandHandler <CreateOrUpdateCategoryCommand> commnadHandler = lifetime.Resolve <ICommandHandler <CreateOrUpdateCategoryCommand> >();
                ICommandResult result = commandBus.Submit(command, commnadHandler);
                Assert.IsNotNull(result, "Error: Category was not created by commandBus");
                Assert.IsTrue(result.Success, "Error: Category was not created by commandBus");
            }
        }
        public void Be_Able_To_Handle_A_Command()
        {
            // given
            var someSpyCommand = new SomeSpyCommand();
            CommandHandlerMock commandHandlerMock = new CommandHandlerMock();

            _sut = new DefaultCommandBus();
            _sut.Register(someSpyCommand.GetType(), commandHandlerMock);

            // when
            _sut.Dispatch(someSpyCommand);

            // then
            someSpyCommand.ShouldBeCommandTypeMessage();
            commandHandlerMock.ShouldBeCalledOnce();
        }
コード例 #7
0
ファイル: CategoryTest.cs プロジェクト: zszqwe/FNHMVC
        public void CategoryDeleteTest()
        {
            using (var lifetime = container.BeginLifetimeScope())
            {
                ICategoryRepository categoryRepository = lifetime.Resolve <ICategoryRepository>();
                DefaultCommandBus   commandBus         = lifetime.Resolve <DefaultCommandBus>();
                IMappingEngine      mapper             = lifetime.Resolve <IMappingEngine>();

                Category category = categoryRepository.Get(c => c.Name == "Updated Test Category");
                Assert.IsNotNull(category, "Error: Category was now found.");

                DeleteCategoryCommand command = mapper.Map <DeleteCategoryCommand>(category);
                ICommandHandler <DeleteCategoryCommand> commnadHandler = lifetime.Resolve <ICommandHandler <DeleteCategoryCommand> >();
                ICommandResult result = commandBus.Submit(command, commnadHandler);
                Assert.IsNotNull(result, "Error: Category was not deleted by CommandBus");
                Assert.IsTrue(result.Success, "Error: Category was not deleted by CommandBus");
            }
        }
コード例 #8
0
ファイル: CategoryTest.cs プロジェクト: zszqwe/FNHMVC
        public void CategoryUpdateTest()
        {
            Category category;

            using (var lifetime = container.BeginLifetimeScope())
            {
                ICategoryRepository categoryRepository = lifetime.Resolve <ICategoryRepository>();
                DefaultCommandBus   commandBus         = lifetime.Resolve <DefaultCommandBus>();
                IMappingEngine      mapper             = lifetime.Resolve <IMappingEngine>();

                category = categoryRepository.Get(c => c.Name == "Test Category");
                Assert.IsNotNull(category, "Error: Category was now found.");

                category.Name = "Updated Test Category";

                CreateOrUpdateCategoryCommand command = mapper.Map <CreateOrUpdateCategoryCommand>(category);
                IValidationHandler <CreateOrUpdateCategoryCommand> validationHandler = lifetime.Resolve <IValidationHandler <CreateOrUpdateCategoryCommand> >();
                IEnumerable <ValidationResult> validations = commandBus.Validate(command, validationHandler);

                foreach (var val in validations)
                {
                    Assert.IsNull(val, "Error: Category creation did not validate " + val.Message);
                }
            }

            using (var lifetime = container.BeginLifetimeScope())
            {
                DefaultCommandBus commandBus = lifetime.Resolve <DefaultCommandBus>();
                IMappingEngine    mapper     = lifetime.Resolve <IMappingEngine>();

                CreateOrUpdateCategoryCommand command = mapper.Map <CreateOrUpdateCategoryCommand>(category);

                ICommandHandler <CreateOrUpdateCategoryCommand> commnadHandler = lifetime.Resolve <ICommandHandler <CreateOrUpdateCategoryCommand> >();
                ICommandResult result = commandBus.Submit(command, commnadHandler);
                Assert.IsNotNull(result, "Error: Category was not updated by CommandBus");
                Assert.IsTrue(result.Success, "Error: Provincia was not updated by CommandBus");
            }
        }