Beispiel #1
0
        //[Ignore("Initial integration test. Run once.")]
        public void SaveChanges()
        {
            using (var db = new DomainDbContext())
            {
                var products = db.Products.ToList();
                var customer = db.Customers.FirstOrDefault();
                if (customer == null)
                {
                    customer = new Customer
                    {
                        FirstName = "Elton",
                        LastName  = "Stoneman"
                    };
                }

                var order = new Order
                {
                    Reference = Guid.NewGuid().ToString(),
                    Customer  = customer
                };
                foreach (var product in products)
                {
                    order.OrderProducts.Add(new OrderProduct()
                    {
                        Product = product
                    });
                }
                db.Orders.Add(order);
                db.Save();
            }
        }
Beispiel #2
0
        private static void CreateDatabase()
        {
            System.IO.File.Delete("TestDatabase.db");

            using (var domainDbContext = new DomainDbContext())
            {
                domainDbContext.Database.EnsureCreated();
            }
        }
Beispiel #3
0
        public static void Init()
        {
            //Create the Entity Frameworkd DBContext
            _domainDbContext = new DomainDbContext();

            //Create the database
            _domainDbContext.Database.EnsureCreated();

            //Create repositories.
            _deliveryRepository        = new DeliveryRepository(_domainDbContext);
            _plannedDeliveryRepository = new PlannedDeliveryRepository(_domainDbContext);
        }
Beispiel #4
0
 public void UpdateOrder()
 {
     using (var db = new DomainDbContext())
     {
         var order = db.Orders.FirstOrDefault();
         if (order != null)
         {
             order.Reference += ".1";
             db.Save();
         }
     }
 }
Beispiel #5
0
 public void UpdateProduct()
 {
     using (var db = new DomainDbContext())
     {
         var product = db.Products.FirstOrDefault();
         if (product != null)
         {
             product.Name += " new";
             db.Save();
         }
     }
 }
Beispiel #6
0
        static void Main(string[] args)
        {
            System.IO.File.Delete("TestDatabase.db");

            var newCustomerId = Guid.NewGuid().ToString();

            using (var domainDbContext = new DomainDbContext())
            {
                domainDbContext.Database.EnsureCreated();
            }

            using (var domainDbContext = new DomainDbContext())
            {
                var repository = new CustomerRepository(domainDbContext);

                var customer = new Customer
                {
                    Id   = newCustomerId,
                    City = "Maldegem"
                };

                customer.AddDeliveryAddress(new DeliveryAddress
                {
                    Id      = Guid.NewGuid().ToString(),
                    Address = new AddressStruct
                    {
                        AddressLine1 = "Kleitkalseide"
                    }
                });

                repository.Add(customer);
            }

            using (var domainDbContext = new DomainDbContext())
            {
                var repository = new CustomerRepository(domainDbContext);
                var customer   = repository.GetById(newCustomerId);

                Console.WriteLine(customer.City);
                foreach (var deliveryAddress in customer.DeliveryAddresses)
                {
                    Console.WriteLine(deliveryAddress.Address.AddressLine1);
                }

                //var deliveryRepository = new DeliveryRepository(domainDbContext);
                //var specification = new DeliveryIsPlannedSpecification();
                //var list = deliveryRepository.List(specification);
            }

            Console.WriteLine("Done");
            Console.ReadKey();
        }
        // POST api/customers
        public HttpResponseMessage Post([FromBody] Customer customer)
        {
            using (var db = new DomainDbContext())
            {
                db.Customers.Add(customer);
                db.Save();
            }
            var response = new HttpResponseMessage(HttpStatusCode.Created);

            // Using the extension method to set Location header
            response.AddLocationHeader(Request, customer.Id);
            return(response);
        }
Beispiel #8
0
        private static void Test_DeleteCustomer()
        {
            using (var domainDbContext = new DomainDbContext())
            {
                var query = from c in domainDbContext.Customers
                            select c;
                var customerForid = query.FirstOrDefault();

                var repository = new CustomerRepository(domainDbContext);

                var customer = repository.GetById(customerForid.Id);

                repository.Delete(customer);
            }
        }
        // GET api/customers
        public Customer Get(int id)
        {
            Customer customer = null;

            using (var db = new DomainDbContext())
            {
                db.Configuration.LazyLoadingEnabled = false;
                customer = db.Customers.Find(id);
            }
            if (customer == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(customer);
        }
        protected virtual DomainDbContext BootstrapContext(bool deleteData = false, bool initialize = false)
        {
            var dbContext = new DomainDbContext();

            if (deleteData)
            {
                TeardownData(dbContext);
                dbContext.SaveChanges();
            }
            if (initialize)
            {
                dbContext.Database.Initialize(true);
            }

            return(dbContext);
        }
Beispiel #11
0
        public DomainDbContext BuildDataContext(bool withData = true)
        {
            var builder = new DbContextOptionsBuilder <DomainDbContext>();

            builder = builder.UseInMemoryDatabase("TestDb");

            var db = new DomainDbContext(builder.Options);

            db.Database.EnsureCreated();

            if (withData)
            {
                DataSeed seed = new DataSeed(db);
                seed.Seed();
            }

            return(db);
        }
Beispiel #12
0
        private static void Test_UpdateCustomer_UpdateOneAddress_DeleteTheOther()
        {
            using (var domainDbContext = new DomainDbContext())
            {
                var query = from c in domainDbContext.Customers
                            select c;
                var customerForid = query.FirstOrDefault();

                var repository = new CustomerRepository(domainDbContext);

                var customer = repository.GetById(customerForid.Id);


                customer.DeliveryAddresses[0].Address.AddressLine1 = "Changed !!";
                customer.DeliveryAddresses.RemoveAt(1);

                repository.Update(customer);
            }
        }
        public static async Task DispatchDomainEventsAsync(this IMediator mediator, DomainDbContext ctx)
        {
            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.DomainEvents != null && x.Entity.DomainEvents.Any());

            var domainEvents = domainEntities
                               .SelectMany(x => x.Entity.DomainEvents)
                               .ToList();

            domainEntities.ToList()
            .ForEach(entity => entity.Entity.ClearDomainEvents());

            var tasks = domainEvents
                        .Select(async(domainEvent) => {
                await mediator.Publish(domainEvent);
            });

            await Task.WhenAll(tasks);
        }
Beispiel #14
0
        private static void Test_InsertCustomer()
        {
            using (var domainDbContext = new DomainDbContext())
            {
                var customerId = Guid.NewGuid().ToString();
                var customer   = new Customer();
                customer.Id   = customerId;
                customer.Name = "Test";
                customer.Info = "Test";
                customer.AddDeliveryAddress(new DeliveryAddress
                {
                    CustomerId = customerId,
                    Id         = Guid.NewGuid().ToString(),
                    Info       = "Test 1",
                    Address    = new DomainModel.ValueObjects.AddressStruct
                    {
                        AddressLine1 = "a",
                        AddressLine2 = "b",
                        AddressLine3 = "c",
                        City         = "X"
                    }
                });
                customer.AddDeliveryAddress(new DeliveryAddress
                {
                    CustomerId = customerId,
                    Id         = Guid.NewGuid().ToString(),
                    Info       = "Test 2",
                    Address    = new DomainModel.ValueObjects.AddressStruct
                    {
                        AddressLine1 = "d",
                        AddressLine2 = "e",
                        AddressLine3 = "f",
                        City         = "X"
                    }
                });

                var repository = new CustomerRepository(domainDbContext);
                repository.Add(customer);
            }
        }
Beispiel #15
0
 public Repository(DomainDbContext context) => _domainDbContext = context ?? throw new ArgumentException(nameof(context));
Beispiel #16
0
 public PostsController(DomainDbContext context)
 {
     _context = context;
 }
Beispiel #17
0
 public CommentsController(DomainDbContext context)
 {
     _context = context;
 }
Beispiel #18
0
 public DisciplinesController(DomainDbContext context)
 {
     _context = context;
 }
Beispiel #19
0
 public Store(DomainDbContext dbContext)
 {
     DbContext = dbContext;
 }
Beispiel #20
0
 public DomainDbContextTransactionBehavior(DomainDbContext dbContext, ILogger <DomainDbContextTransactionBehavior <TRequest, TResponse> > logger) : base(dbContext, logger)
 {
 }
Beispiel #21
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IDispatcher dispatcher, DomainDbContext domainDbContext)
        {
            // Ensure WeapsyCqrs database is installed.
            domainDbContext.Database.Migrate();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async context =>
            {
                // Create a sample product loading data from domain events.
                var product = await GettingStarted.CreateProduct(dispatcher);

                // Display product title.
                await context.Response.WriteAsync($"Product title: {product.Title}");
            });
        }
Beispiel #22
0
 public PerfilServices(DomainDbContext domainDb)
 {
     _domainDb = domainDb;
 }
Beispiel #23
0
 public ProjectController()
 {
     _context = new DomainDbContext();
 }
Beispiel #24
0
 public CategoriesController(DomainDbContext context)
 {
     _context = context;
 }
 public DomainManager(DomainDbContext context)
 {
     _context = context;
 }
Beispiel #26
0
 public PostServices(DomainDbContext context)
 {
     Context = context;
 }
Beispiel #27
0
 public DeliveryRepository(DomainDbContext domainDbContext) : base(domainDbContext)
 {
 }
Beispiel #28
0
 public void Init()
 {
     _db    = BuildDataContext();
     _store = new ProductStore(_db);
 }
Beispiel #29
0
 public BaseRepository(DomainDbContext domainDbContext)
 {
     _domainDbContext = domainDbContext;
 }
 public CreateCustomerController(DomainDbContext db)
 {
     _db = db;
 }