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.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 CategoryFormModel(Category category) { this.CategoryId = category.CategoryId; this.Name = category.Name; this.Description = category.Description; }