Пример #1
0
 public Order Create(int quantity, string productCode)
 {
     ProductCode = productCode;
     Quantity    = quantity;
     DomainEventRepository.Add(new NewOrderCreatedEvent(productCode, quantity));
     return(this);
 }
Пример #2
0
        /// <inheritdoc />
        public void DispatchEvents()
        {
            var events = DomainEventRepository.FindAll();

            foreach (var domainEventRecord in events)
            {
                var subscriptions = _subscriptionManager.GetHandlersForEvent(domainEventRecord.Type.Name);

                foreach (var subscription in subscriptions)
                {
                    var handler = Singleton.Container.GetInstance(subscription.HandlerType);
                    if (handler == null)
                    {
                        continue;
                    }
                    var eventType    = _subscriptionManager.GetEventTypeByName(domainEventRecord.Type.Name);
                    var concreteType = typeof(IHandler <>).MakeGenericType(eventType);
                    concreteType.GetMethod("Handle").Invoke(handler, new[] { domainEventRecord.Event });
                }

                if (!string.IsNullOrEmpty(domainEventRecord.Message))
                {
                    Console.WriteLine(domainEventRecord.Message);
                }
            }
            DomainEventRepository.ClearEvents();
        }
Пример #3
0
 public Sale Create(string productCode, int pricePerProduct, int quantity, string campaignName)
 {
     ProductCode  = productCode;
     Quantity     = quantity;
     TotalPaid    = pricePerProduct * quantity;
     CampaignName = campaignName;
     DomainEventRepository.Add(new SaleConfirmedEvent(this));
     return(this);
 }
Пример #4
0
        public Campaign UpdatePrice(int priceManipulation)
        {
            if ((PriceManipulationLimit >= CurrentPriceManipulation + priceManipulation))
            {
                CurrentPriceManipulation += priceManipulation;
            }

            DomainEventRepository.Add(new UpdateCampaignCurrentManipulationEvent(this));
            return(this);
        }
Пример #5
0
 public Campaign CreateCampaign(string name, string productCode, int duration, int priceManipulationLimit, int targetSalesCount)
 {
     Duration = duration;
     Name     = name;
     PriceManipulationLimit = priceManipulationLimit;
     ProductCode            = productCode;
     TargetSalesCount       = targetSalesCount;
     Status = Status.Active;
     CurrentPriceManipulation = 0;
     DomainEventRepository.Add(new AddNewCampaignEvent(Name, ProductCode, Duration, PriceManipulationLimit, TargetSalesCount));
     return(this);
 }
        private EventStorePatientEndSchedulingService SetupEventEndService()
        {
            EventDataSeeder dataSeeder = new EventDataSeeder();
            DbContextOptionsBuilder <EventSourcingDbContext> builder = new DbContextOptionsBuilder <EventSourcingDbContext>();;
            DbContextOptions <EventSourcingDbContext>        options;
            EventSourcingDbContext context;

            builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            options = builder.Options;
            context = new EventSourcingDbContext(options);

            dataSeeder.SeedAll(context);

            var eventRepo = new DomainEventRepository <PatientEndSchedulingEvent>(context);

            return(new EventStorePatientEndSchedulingService(eventRepo));
        }
        public void AddCreateCampaignEvent()
        {
            //Arrange
            var mock        = new Mock <IRepository <Campaign> >();
            var saleMock    = new Mock <IRepository <Sale> >();
            var uowMock     = new Mock <IUnitOfWork>();
            var consoleMock = new Mock <IConsoleWriter>();

            mock.Setup(x => x.Add(It.IsAny <Campaign>()))
            .Returns(new Campaign {
                ProductCode = "P1", Name = "C1", Status = Status.Active, Duration = 5
            }).Verifiable();
            var campaignService = new CampaignServices(mock.Object, saleMock.Object, uowMock.Object, consoleMock.Object);

            //Act
            campaignService.CreateCampaign("C1", "P1", 10, 20, 100);
            var events = DomainEventRepository.FindAll();

            //Assert
            Assert.Contains(events, x => x.Type == typeof(AddNewCampaignEvent));
        }
Пример #8
0
        public void AddNewProductOrderCreatedEvent(Product product, Order order, Campaign campaign)
        {
            //Arrange
            var campaignMock = new Mock <IRepository <Campaign> >();
            var productMock  = new Mock <IRepository <Product> >();
            var orderMock    = new Mock <IRepository <Order> >();
            var uowMock      = new Mock <IUnitOfWork>();

            productMock.Setup(x => x.Get(It.IsAny <Expression <Func <Product, bool> > >()))
            .Returns(product);
            orderMock.Setup(x => x.Get(It.IsAny <Expression <Func <Order, bool> > >()))
            .Returns(order);

            var orderService = new OrderServices(orderMock.Object, productMock.Object, campaignMock.Object, uowMock.Object);

            //Act
            orderService.CreateOrder(product.ProductCode, order.Quantity);
            var events = DomainEventRepository.FindAll();

            //Assert
            Assert.Contains(events, x => x.Type == typeof(NewProductOrderCreatedEvent));
        }
        public void AddCreateCampaignEventShouldNotEmptyMessage()
        {
            //Arrange
            var mock        = new Mock <IRepository <Campaign> >();
            var saleMock    = new Mock <IRepository <Sale> >();
            var uowMock     = new Mock <IUnitOfWork>();
            var consoleMock = new Mock <IConsoleWriter>();

            mock.Setup(x => x.Add(It.IsAny <Campaign>()))
            .Returns(new Campaign {
                ProductCode = "P1", Name = "C1", Status = Status.Active, Duration = 5
            }).Verifiable();
            var campaignService = new CampaignServices(mock.Object, saleMock.Object, uowMock.Object, consoleMock.Object);

            //Act
            campaignService.CreateCampaign("C1", "P1", 10, 20, 100);
            var events      = DomainEventRepository.FindAll();
            var domainEvent = events.FirstOrDefault(x => x.Type == typeof(AddNewCampaignEvent)).Event as AddNewCampaignEvent;

            //Assert
            Assert.False(string.IsNullOrEmpty(domainEvent.Message));
        }
Пример #10
0
        public ProductOrder Create(Product product, Order order, Campaign campaign)
        {
            ProductCode = product.ProductCode;
            Quantity    = order.Quantity;
            if (campaign != null)
            {
                DiscountAmount = product.OriginalPrice * campaign.CurrentPriceManipulation / 100;
            }
            PricePerItem             = product.OriginalPrice;
            PricePerItemWithDiscount = PricePerItem - DiscountAmount;
            TotalAmount             = product.OriginalPrice * order.Quantity;
            TotalAmountWithDiscount = order.Quantity * PricePerItemWithDiscount;
            TotalDiscount           = DiscountAmount * Quantity;
            OriginalStock           = product.Stock;
            StockAfterSale          = product.Stock - order.Quantity;

            OrderedProduct       = product;
            OrderedProduct.Stock = StockAfterSale;

            CampaignName = campaign?.Name;
            DomainEventRepository.Add(new NewProductOrderCreatedEvent(this));
            return(this);
        }
        public MapEventsTests()
        {
            EventDataSeeder dataSeeder = new EventDataSeeder();
            DbContextOptionsBuilder <EventSourcingDbContext> builder = new DbContextOptionsBuilder <EventSourcingDbContext>();;
            DbContextOptions <EventSourcingDbContext>        options;
            EventSourcingDbContext context;

            builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            options = builder.Options;
            context = new EventSourcingDbContext(options);

            dataSeeder.SeedAll(context);

            var buildingEventRepo = new DomainEventRepository <BuildingSelectionEvent>(context);

            buildingEventService = new BuildingSelectionService(buildingEventRepo);
            var floorChangeEventRepo = new DomainEventRepository <FloorChangeEvent>(context);

            floorChangeEventService = new FloorChangeService(floorChangeEventRepo);
            var roomEventRepo = new DomainEventRepository <RoomSelectionEvent>(context);

            roomEventService = new RoomSelectionService(roomEventRepo);
        }
Пример #12
0
 public void Create(string productCode, int price, int stock)
 {
     DiscountedPrice = price;
     DomainEventRepository.Add(new AddNewProductEvent(productCode, price, stock));
 }
Пример #13
0
 public Campaign ChangeStatus(Status status)
 {
     Status = status;
     DomainEventRepository.Add(new CampaignDeactivedEvent(this));
     return(this);
 }