Пример #1
0
        private static async Task TestMediatRAsync()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddMediatR(typeof(CreateProductCommand));

            //Type[] validators = new[] { typeof(CreateProductCommandValidator) };
            serviceCollection.AddTransient(typeof(IValidator <CreateProductCommand>), typeof(CreateProductCommandValidator));

            //serviceCollection.AddTransient(typeof(IPipelineBehavior<CreateProductCommand, bool>), typeof(LoggingBehavior<CreateProductCommand, bool>));
            serviceCollection.AddTransient(typeof(IPipelineBehavior <CreateProductCommand, bool>), typeof(ValidatorBehavior <CreateProductCommand, bool>));
            serviceCollection.AddTransient(typeof(IPipelineBehavior <CreateProductCommand, bool>), typeof(LoggingBehavior <CreateProductCommand, bool>));

            var provider = serviceCollection.BuildServiceProvider();

            //IValidator<CreateProductCommand> validator = provider.GetService<IValidator<CreateProductCommand>>();
            //IValidator<CreateProductCommand>[] validators = provider.GetServices<IValidator<CreateProductCommand>>().ToArray();

            var productGroup         = ProductGroup.Create("GE GR");
            var createProductCommand = new CreateProductCommand(productGroup, "GR GE Annemarie");

            IMediator mediator = provider.GetService <IMediator>();

            var result = await mediator.Send(createProductCommand);

            //await Task.FromResult<object>(null);
        }
Пример #2
0
        private static void TestEFProduct()
        {
            using (var context = new CatalogContext())
            {
                context.ProductGroups.Add(ProductGroup.Create("Rosa"));
                context.ProductGroups.Add(ProductGroup.Create("Gerbera"));
                context.ProductGroups.Add(ProductGroup.Create("Tulip"));

                context.SaveChanges();

                var rosa   = context.ProductGroups.Where(pg => pg.Name == "Rosa").SingleOrDefault();
                var rosaId = context.Entry(rosa).Property("ProductGroupId").CurrentValue;

                var tulip = context.ProductGroups.Where(pg => Microsoft.EntityFrameworkCore.EF.Property <int>(pg, "ProductGroupId") == 3).SingleOrDefault();

                var redBerlin = Product.Create(rosa, "R GR Red Berlin", null, "R GR Red Berlin");
                var ajax      = Product.Create(tulip, "TU EN AJAX", null, "TU EN AJAX");
                context.Products.Add(redBerlin);
                context.Products.Add(ajax);

                context.SaveChanges();
            }

            var productGroups = CatalogQueries.GetProductGroups();
        }