Esempio n. 1
0
        public void Add(Item item)
        {
            if (item == null)
            {
                return;
            }

            if (item.HasComponent <OwnerComponent>())
            {
                item.RemoveComponent <OwnerComponent>();
            }

            Items.Add(item);

            item.RemoveDroppedComponents();
            item.AddComponent(new OwnerComponent(Entity));

            item.Use(Entity);

            if (Entity is Player && !item.Touched && item.Scourged)
            {
                Run.AddScourge(true);
            }

            var e = new ItemAddedEvent {
                Item = item,
                Who  = Entity
            };

            Send(e);
            item.Touched = true;
        }
Esempio n. 2
0
        public void BasketItem_Should_Be_Added_To_Basket_When_Item_Quantity_Greater_Than_Zero()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            Guid      basketId = Faker.Random.Uuid();
            Guid      itemId   = Faker.Random.Uuid();
            const int quantity = 2;

            var basketCreatedEvent = new BasketCreatedEvent(basketId);
            var itemAddedEvent     = new ItemAddedEvent(basketId, itemId, quantity);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Basket basket = Basket.Create(basketId);

            basket.AddItem(itemId, quantity);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            basket.Items.Count.Should().Be(1);
            basket.ShouldPublishDomainEvents(basketCreatedEvent, itemAddedEvent);
        }
Esempio n. 3
0
        public void Adding_SameItem_With_Different_Quantity_To_Basket_Should_Change_Quantity()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            Guid      basketId   = Faker.Random.Uuid();
            Guid      itemId     = Faker.Random.Uuid();
            const int quantity   = 2;
            const int toQuantity = 4;

            var basketCreatedEvent   = new BasketCreatedEvent(basketId);
            var itemAddedEvent       = new ItemAddedEvent(basketId, itemId, quantity);
            var quantityChangedEvent = new ItemQuantityChangedEvent(basketId, itemId, quantity, toQuantity);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Basket basket = Basket.Create(basketId);

            basket.AddItem(itemId, quantity);
            basket.AddItem(itemId, toQuantity);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            basket.Items.Count.Should().Be(1);
            basket.ShouldPublishDomainEvents(basketCreatedEvent, itemAddedEvent, quantityChangedEvent);
        }
Esempio n. 4
0
        public void Clearing_Items_From_Basket_Should_Clear_All_Items_In_The_Basket()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            Guid      basketId     = Faker.Random.Uuid();
            Guid      itemId       = Faker.Random.Uuid();
            const int fromQuantity = 2;

            var basketCreatedEvent = new BasketCreatedEvent(basketId);
            var itemAddedEvent     = new ItemAddedEvent(basketId, itemId, fromQuantity);
            var basketCleanedEvent = new BasketCleaned(basketId);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Basket basket = Basket.Create(basketId);

            basket.AddItem(itemId, fromQuantity);
            basket.Clear();

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            basket.Items.Count.Should().Be(0);
            basket.ShouldPublishDomainEvents(basketCreatedEvent, itemAddedEvent, basketCleanedEvent);
        }
Esempio n. 5
0
        public void BasketItem_Quantity_Should_Be_Changed_And_Product_Should_Be_Removed_When_Quantity_Is_Zero()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            Guid      basketId     = Faker.Random.Uuid();
            Guid      itemId       = Faker.Random.Uuid();
            const int fromQuantity = 2;
            const int toQuantity   = 0;

            var basketCreatedEvent = new BasketCreatedEvent(basketId);
            var itemAddedEvent     = new ItemAddedEvent(basketId, itemId, fromQuantity);
            var itemRemovedEvent   = new ItemRemovedEvent(basketId, itemId);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Basket basket = Basket.Create(basketId);

            basket.AddItem(itemId, fromQuantity);
            basket.ChangeItemQuantity(itemId, toQuantity);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            basket.Items.Count.Should().Be(0);
            basket.ShouldPublishDomainEvents(basketCreatedEvent, itemAddedEvent, itemRemovedEvent);
        }
Esempio n. 6
0
        public new void Add(T item)
        {
            int index = Count;

            base.Add(item);
            ItemAddedEvent?.Invoke(this, new ListItemsChangedEventArgs <T>(item, index));
        }
Esempio n. 7
0
        public override void Add(T element)
        {
            int index         = Interlocked.Increment(ref _index) - 1;
            int adjustedIndex = index;

            int arrayIndex = GetArrayIndex(index + 1);

            if (arrayIndex > 0)
            {
                adjustedIndex -= Counts[arrayIndex - 1];
            }

            if (_array[arrayIndex] == null)
            {
                int arrayLength = Sizes[arrayIndex];
                Interlocked.CompareExchange(ref _array[arrayIndex], new T[arrayLength], null);
            }

            _array[arrayIndex][adjustedIndex] = element;

            int count      = _count;
            int fuzzyCount = Interlocked.Increment(ref _fuzzyCount);

            if (fuzzyCount == index + 1)
            {
                Interlocked.CompareExchange(ref _count, fuzzyCount, count);
            }
            ItemAddedEvent?.Invoke(element, index);
        }
Esempio n. 8
0
        public new void AddRange(IEnumerable <T> collection)
        {
            int index = Count;

            base.AddRange(collection);
            foreach (T item in collection)
            {
                ItemAddedEvent?.Invoke(this, new ListItemsChangedEventArgs <T>(item, index++));
            }
        }
Esempio n. 9
0
        // Adds an item to the shopping list
        private void Add()
        {
            ItemAddedEvent e = new ItemAddedEvent();

            e.Id   = Guid.NewGuid();
            e.Name = Name;

            _eventAggregator.Publish(e);

            NotificationText = String.Format("{0} was added to the shopping list.", Name);
            Name             = string.Empty;
        }
Esempio n. 10
0
 private void Handle(ItemAddedEvent message)
 {
     store.Tell(new StoreEvents(message.CommandId, new object[] { message }));
 }
Esempio n. 11
0
 void ItemAdded(IExplorerItem obj)
 {
     ItemAddedEvent?.Invoke(obj);
 }
Esempio n. 12
0
 public void Publish(ItemAddedEvent itemAddedEvent)
 {
     _bus.Publish(itemAddedEvent);
 }
Esempio n. 13
0
 private void When(ItemAddedEvent @event)
 {
     Items.Add(new BasketItem(Id, @event.ItemId, @event.Quantity));
 }
Esempio n. 14
0
 private void Handle(ItemAddedEvent message)
 {
     Console.WriteLine($"ItemAddedEvent received for {message.CartId}");
     Console.WriteLine($"Item: {message.ItemId}");
     Console.WriteLine($"Quantity: {message.Quantity}");
 }
Esempio n. 15
0
        public Task Handle(ItemAddedEvent notification, CancellationToken cancellationToken)
        {
            // Handle Projections or inform the other Bounded Context...

            return(Task.CompletedTask);
        }
Esempio n. 16
0
 public void Handle(ItemAddedEvent @event)
 {
     hub.Clients.All.globalMessageRecieved(@event);
 }