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; }
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); }
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); }
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); }
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); }
public new void Add(T item) { int index = Count; base.Add(item); ItemAddedEvent?.Invoke(this, new ListItemsChangedEventArgs <T>(item, index)); }
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); }
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++)); } }
// 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; }
private void Handle(ItemAddedEvent message) { store.Tell(new StoreEvents(message.CommandId, new object[] { message })); }
void ItemAdded(IExplorerItem obj) { ItemAddedEvent?.Invoke(obj); }
public void Publish(ItemAddedEvent itemAddedEvent) { _bus.Publish(itemAddedEvent); }
private void When(ItemAddedEvent @event) { Items.Add(new BasketItem(Id, @event.ItemId, @event.Quantity)); }
private void Handle(ItemAddedEvent message) { Console.WriteLine($"ItemAddedEvent received for {message.CartId}"); Console.WriteLine($"Item: {message.ItemId}"); Console.WriteLine($"Quantity: {message.Quantity}"); }
public Task Handle(ItemAddedEvent notification, CancellationToken cancellationToken) { // Handle Projections or inform the other Bounded Context... return(Task.CompletedTask); }
public void Handle(ItemAddedEvent @event) { hub.Clients.All.globalMessageRecieved(@event); }