Example #1
0
        public void FailPhysicalItemCreationIfSerialNumberIsDuplicate()
        {
            //Arrange
            var location = new Location();

            mockPhysicalItemRepo  = new Mock <IPhysicalItemsRepository>();
            mockInventoryItemRepo = new Mock <IInventoryItemsRepository>();
            mockPhysicalItemRepo.Setup(m => m.IsSerialNumberDuplicate(duplicateSerialNumber)).Returns(true);
            mockPhysicalItemRepo.Setup(m => m.GetLocation(validLocationId)).Returns(location);

            sut = new PhysicalItemsService(mockPhysicalItemRepo.Object, mockInventoryItemRepo.Object);
            PhysicalItem physicalItemWithDuplicateSerialNumber = new PhysicalItem()
            {
                PhysicalItemId  = 1,
                InventoryItemId = 1,
                SerialNumber    = "B152",
                LocationId      = 1,
                Value           = 9.99m,
                Created         = DateTime.Now,
                CreatedBy       = "Lucius"
            };

            //Act
            //var isSerialNumberDuplicate = sut.CreatePhysicalItem(physicalItemWithDuplicateSerialNumber);

            //Assert
            Assert.Throws <Exception>(() => sut.CreatePhysicalItem(physicalItemWithDuplicateSerialNumber));
        }
Example #2
0
        public PhysicalItem CreatePhysicalItem(PhysicalItem pItemData)
        {
            if (IsSerialNumberDuplicate(pItemData.SerialNumber))
            {
                throw new Exception("Please try a different serial number.");
            }

            var returnedInventoryItem = FindInventoryItem(pItemData.InventoryItemId);
            var returnedLocation      = FindLocation(pItemData.LocationId);

            //Set PhysicalItem DTO for Create
            var pItemToCreate = new PhysicalItem();

            pItemToCreate.InventoryItemId = pItemData.InventoryItemId;
            pItemToCreate.SerialNumber    = pItemData.SerialNumber;
            pItemToCreate.LocationId      = pItemData.LocationId;
            pItemToCreate.Value           = pItemData.Value;
            pItemToCreate.Created         = DateTime.Now;
            //Get UserId to auto CreatedBy
            pItemToCreate.CreatedBy = pItemData.CreatedBy;

            var createdPItem = _pir.CreatePhysicalItem(pItemToCreate);

            createdPItem.InventoryItem = returnedInventoryItem;
            createdPItem.Location      = returnedLocation;

            return(createdPItem);
        }
Example #3
0
        public PhysicalItem UpdatePhysicalItem(PhysicalItem pItemData)
        {
            var pItemToUpdate = GetById(pItemData.PhysicalItemId);

            //Test if SerialNumber matches, exists in DB, or completely different
            if (pItemToUpdate.SerialNumber != pItemData.SerialNumber)
            {
                if (IsSerialNumberDuplicate(pItemData.SerialNumber))
                {
                    throw new Exception("Please try a different serial number.");
                }
            }

            var returnedInventoryItem = FindInventoryItem(pItemData.InventoryItemId);
            var returnedLocation      = FindLocation(pItemData.LocationId);

            pItemToUpdate.InventoryItemId = returnedInventoryItem.InventoryItemId;
            pItemToUpdate.InventoryItem   = returnedInventoryItem;
            //Need to define what makes a serial number
            pItemToUpdate.SerialNumber  = pItemData.SerialNumber;
            pItemToUpdate.LocationId    = pItemData.LocationId;
            pItemToUpdate.Location      = returnedLocation;
            pItemToUpdate.Value         = pItemData.Value;
            pItemToUpdate.LastUpdated   = DateTime.Now;
            pItemToUpdate.LastUpdatedBy = pItemData.LastUpdatedBy;

            var updatedPItem = _pir.UpdatePhysicalItem(pItemToUpdate);

            return(updatedPItem);
        }
Example #4
0
 public void Pick(PhysicalItem item)
 {
     if (Unit.PickUpItem(item))
     {
         Sleeper.Sleep(500);
     }
 }
        public PhysicalItem CreatePhysicalItem(PhysicalItem pItemToCreate)
        {
            _db.PhysicalItems.Add(pItemToCreate);
            _db.SaveChanges();

            return(pItemToCreate);
        }
        public bool DeletePhysicalItem(PhysicalItem pItemToDelete)
        {
            _db.PhysicalItems.Remove(pItemToDelete);
            _db.SaveChanges();

            return(true);
        }
        public PhysicalItem UpdatePhysicalItem(PhysicalItem pItemToUpdate)
        {
            _db.PhysicalItems.Update(pItemToUpdate);
            _db.SaveChanges();

            return(pItemToUpdate);
        }
Example #8
0
        public static decimal RefinedPerSecond(RefineryBlock refinery, PhysicalItem ore, Blueprint blueprint)
        {
            Debug.Assert(Equals(blueprint.Inputs.Single().ItemId, ore.Id));
            var producedPerSecond = 1 / blueprint.BaseProductionTimeInSeconds;

            return(0);
        }
Example #9
0
        public override bool CanPick(PhysicalItem physicalItem, int costThreshold)
        {
            if (Sleeper.Sleeping || Unit.Distance2D(physicalItem) > 400)
            {
                return(false);
            }

            switch (physicalItem.Item.Id)
            {
            case AbilityId.item_gem:
            case AbilityId.item_rapier:
            {
                return(Unit.Inventory.FreeInventorySlots.Any());
            }

            case AbilityId.item_aegis:
            {
                return(false);
            }

            case AbilityId.item_cheese:
            {
                return(Unit.Inventory.FreeInventorySlots.Any() || Unit.Inventory.FreeBackpackSlots.Any());
            }
            }

            return(false);
        }
Example #10
0
        public override bool CanPick(PhysicalItem physicalItem)
        {
            if (!this.ShouldPick(physicalItem))
            {
                return(false);
            }

            switch (physicalItem.Item.Id)
            {
            case AbilityId.item_gem:
            case AbilityId.item_rapier:
            {
                return(this.Unit.BaseInventory.FreeMainSlots.Any());
            }

            case AbilityId.item_aegis:
            {
                return(false);
            }

            case AbilityId.item_refresher_shard:
            case AbilityId.item_ultimate_scepter_2:
            case AbilityId.item_cheese:
            {
                return(this.Unit.BaseInventory.FreeMainSlots.Any() || this.Unit.BaseInventory.FreeBackpackSlots.Any());
            }
            }

            return(false);
        }
Example #11
0
        public void Customer_should_require_a_mail()
        {
            const string name = "broom";

            var physicalItem = new PhysicalItem(name);

            Assert.Equal(name, physicalItem.Name);
        }
Example #12
0
    /// <summary>
    /// Отправить сообщение на сервер, что предмет снят
    /// </summary>
    /// <param name="item">Снимаемый предмет</param>
    public void SendUnequipMessage(PhysicalItem item)
    {
        Dictionary <string, string> keyValues = new Dictionary <string, string>
        {
            { "itemID", item.ItemData.Id.ToString() }
        };

        StartCoroutine(SendMessageToServer("uneqip", keyValues));
    }
Example #13
0
        public virtual bool CanPick(PhysicalItem physicalItem)
        {
            if (!this.ShouldPick(physicalItem))
            {
                return(false);
            }

            if (physicalItem.Item.NeutralTierIndex >= 0)
            {
                if (this.Unit.BaseInventory.FreeBackpackSlots.Any() || this.Unit.BaseInventory.GetItem(ItemSlot.NeutralItemSlot) == null)
                {
                    return(true);
                }
            }

            switch (physicalItem.Item.Id)
            {
            case AbilityId.item_gem:
            case AbilityId.item_rapier:
            case AbilityId.item_aegis:
            case AbilityId.item_refresher_shard:
            {
                if (this.Unit.BaseInventory.FreeMainSlots.Any())
                {
                    return(true);
                }

                if (!this.Unit.BaseInventory.FreeBackpackSlots.Any())
                {
                    return(false);
                }

                var item = this.Unit.BaseInventory.MainItems.OrderBy(x => x.Cost).FirstOrDefault(x => x.CanBeMovedToBackpack());
                if (item == null)
                {
                    return(false);
                }

                item.Move(this.Unit.BaseInventory.FreeBackpackSlots.First());
                return(true);
            }

            case AbilityId.item_cheese:
            case AbilityId.item_ultimate_scepter_2 when this.Unit.HasAghanimsScepter:
            {
                return(this.Unit.BaseInventory.FreeMainSlots.Any() || this.Unit.BaseInventory.FreeBackpackSlots.Any());
            }

            case AbilityId.item_ultimate_scepter_2:
            {
                return(true);
            }
            }

            return(false);
        }
Example #14
0
        public void Pick(PhysicalItem item)
        {
            if (this.Unit.BaseUnit.PickUp(item))
            {
                if (item.Item.NeutralTierIndex >= 0 && !this.Unit.IsInvisible)
                {
                    UpdateManager.BeginInvoke(100, () => this.Unit.BaseUnit.Attack(this.Unit.Position, true));
                }

                this.Sleeper.Sleep(0.5f);
            }
        }
Example #15
0
 public OrderTests()
 {
     _domainEventNotifier = Substitute.For <DomainEventNotifier>();
     DomainEventNotifier.CurrentNotifier = _domainEventNotifier;
     _digitalMedia  = new DigitalMedia("despacito.mp3");
     _book          = new Book("Sapiens");
     _customer      = new Customer("*****@*****.**");
     _address       = new Address("79042-656");
     _membership    = new Membership("Premium service");
     _paymentMethod = CreditCard.FetchByHashed("123");
     _physicalItem  = new PhysicalItem("broom");
 }
Example #16
0
        public ActionResult <PhysicalItem> CreatePhysicalItem([FromBody] PhysicalItem pItemData)
        {
            try
            {
                PhysicalItem newItem = _pis.CreatePhysicalItem(pItemData);

                return(Created("api/physicalitems/" + newItem.SerialNumber, newItem));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Example #17
0
        public ActionResult <PhysicalItem> UpdatePhysicalItem(int id, [FromBody] PhysicalItem pItemData)
        {
            try
            {
                pItemData.PhysicalItemId = id;

                return(Ok(_pis.UpdatePhysicalItem(pItemData)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Example #18
0
        /// <summary>
        /// Inserts a game object into the inventory of the player
        /// </summary>
        /// <param name="obj"> gameobject to pass into the inventory </param>
        bool InsertItem(GameObject obj)
        {
            if (!isLocalPlayer)
            {
                return(false);
            }

            PhysicalItem physItem = obj.GetComponent <PhysicalItem>();
            Item         item     = physItem.scriptableObjectReference;

            if (item.isStackable)
            {
                for (int i = 0; i < inventoryList.Count; i++)
                {
                    if (item == inventoryList[i] && stackAmount[i] < item.maxStackable)
                    {
                        stackAmount[i] += physItem.stackedAmount;
                        ui_Inventory.UpdateItemTextAmount(i);

                        if (stackAmount[i] > item.maxStackable)
                        {
                            // if there's more items being picked up then what fits in 1 stack, split it and run add it to a new slot
                            int stackOverflow = stackAmount[i] - item.maxStackable;
                            stackAmount[i]          = item.maxStackable;
                            physItem.stackedAmount -= stackOverflow;
                            ui_Inventory.UpdateItemTextAmount(i);
                        }
                        else
                        {
                            CalculateWeight();
                            return(true);
                        }
                    }
                }
            }
            for (int i = 0; i < inventoryList.Count; i++)
            {
                if (inventoryList[i] == null)
                {
                    // add the item to the inventorylist and amount to the stackamount
                    stackAmount[i]   = physItem.stackedAmount;
                    inventoryList[i] = item;

                    ui_Inventory.UpdateSprites(i, item, true);
                    CalculateWeight();
                    return(true);
                }
            }
            CalculateWeight();
            return(false);
        }
Example #19
0
        private bool IsItemEnabled(MenuAbilityToggler toggler, PhysicalItem item)
        {
            if (item.Item.NeutralTierIndex >= 0 && toggler.IsEnabled("item_seer_stone"))
            {
                return(true);
            }

            if (toggler.IsEnabled(item.Item.Name))
            {
                return(true);
            }

            return(false);
        }
Example #20
0
 /// <summary>
 /// Попробовать поместить предмет в инвентарь (Проверяет свободные ячейки в инвентаре)
 /// </summary>
 /// <param name="item">Перемещаемый предмет</param>
 private void TryAddItemToCells(PhysicalItem item)
 {
     if (item != null && item.ItemData != null && !IsInventoryFull)
     {
         for (int i = 0; i < _inventoryCells.Count; i++)
         {
             if (_inventoryCells[i].Item == null)
             {
                 _inventoryCells[i].Item = item;
                 break;
             }
         }
     }
 }
Example #21
0
    /// <summary>
    /// Попробовать одеть предмет на рюкзак
    /// </summary>
    /// <param name="item"></param>
    public void TryEquipItem(PhysicalItem item)
    {
        bool operationSuccess = false;

        if (item.ItemData != null && !IsInventoryFull)
        {
            switch (item.ItemData.Type)
            {
            case ItemType.MeleeWeapon:
                if (_equippedMeleeWeapon == null)
                {
                    operationSuccess = true;

                    _equippedMeleeWeapon = item;
                    TryAddItemToCells(item);
                    _equippedMeleeWeapon.MoveToInventory(_pointToEquippedMeleeWeapon);
                }
                break;

            case ItemType.SmallItem:
                if (_equippedSmallItem == null)
                {
                    operationSuccess = true;

                    _equippedSmallItem = item;
                    TryAddItemToCells(item);
                    _equippedSmallItem.MoveToInventory(_pointToEquippedSmallItem);
                }
                break;

            case ItemType.SmallRiffle:
                if (_equippedSmallRiffle == null)
                {
                    operationSuccess = true;

                    _equippedSmallRiffle = item;
                    TryAddItemToCells(item);
                    _equippedSmallRiffle.MoveToInventory(_pointToEquippedSmallRiffle);
                }
                break;
            }
        }

        if (operationSuccess)
        {
            LevelManager.Instance.EquipEvent.Invoke(item);
        }
    }
Example #22
0
        private void OnEntityAdded(object sender, PhysicalItem item)
        {
            if (!item.IsValid || !pingedItems.Value.IsEnabled(item.Item.Name))
            {
                return;
            }

            if (EntityManager <Building> .Entities.Any(
                    x => x.Team == myTeam && x.ClassId == ClassId.CDOTA_Unit_Fountain &&
                    x.Position.Distance(item.Position) < 1000))
            {
                return;
            }

            //TODO how to ping physical item =/
        }
        private BatmansInventoryContext GetPopulatedInMemoryDbContext()
        {
            var options = new DbContextOptionsBuilder <BatmansInventoryContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var          context = new BatmansInventoryContext(options);
            PhysicalItem fakePhysicalItemSameLocation1 = new PhysicalItem()
            {
                PhysicalItemId  = 1,
                InventoryItemId = 1,
                SerialNumber    = "A001",
                LocationId      = 1,
                Value           = 9.99m,
                Created         = DateTime.Now,
                CreatedBy       = "Lucius"
            };
            PhysicalItem fakePhysicalItemSameLocation2 = new PhysicalItem()
            {
                PhysicalItemId  = 2,
                InventoryItemId = 1,
                SerialNumber    = "A002",
                LocationId      = 1,
                Value           = 9.99m,
                Created         = DateTime.Now,
                CreatedBy       = "Lucius"
            };
            PhysicalItem fakePhysicalItemDifferentLocation = new PhysicalItem()
            {
                PhysicalItemId  = 3,
                InventoryItemId = 2,
                SerialNumber    = "B001",
                LocationId      = 3,
                Value           = 19.99m,
                Created         = DateTime.Now,
                CreatedBy       = "Lucius"
            };

            context.Add(fakePhysicalItemSameLocation1);
            context.Add(fakePhysicalItemSameLocation2);
            context.Add(fakePhysicalItemDifferentLocation);
            context.SaveChanges();

            return(context);
        }
Example #24
0
        public override bool CanPick(PhysicalItem physicalItem, int costThreshold)
        {
            if (!CanPick() || Unit.Distance2D(physicalItem) > 400)
            {
                return(false);
            }

            switch (physicalItem.Item.Id)
            {
            case AbilityId.item_gem:
            case AbilityId.item_rapier:
            case AbilityId.item_aegis:
            {
                if (Unit.Inventory.FreeInventorySlots.Any())
                {
                    return(true);
                }

                if (!Unit.Inventory.FreeBackpackSlots.Any())
                {
                    return(false);
                }

                var item = Unit.Inventory.Items.OrderBy(x => x.Cost)
                           .FirstOrDefault(x => x.CanBeMovedToBackpack() && x.Cost < costThreshold);

                if (item == null)
                {
                    return(false);
                }

                item.MoveItem(Unit.Inventory.FreeBackpackSlots.First());
                return(true);
            }

            case AbilityId.item_cheese:
            {
                return(Unit.Inventory.FreeInventorySlots.Any() || Unit.Inventory.FreeBackpackSlots.Any());
            }
            }

            return(false);
        }
 // Token: 0x06000392 RID: 914 RVA: 0x0001BEA8 File Offset: 0x0001A0A8
 private static void OnRemoveEntity(EntityEventArgs args)
 {
     try
     {
         PhysicalItem physicalItem = args.Entity as PhysicalItem;
         if (!(physicalItem == null) && !(physicalItem.Item == null))
         {
             Ability9 abilityFast = EntityManager9.GetAbilityFast(physicalItem.Item.Handle);
             if (!(abilityFast == null))
             {
                 abilityFast.IsActive = true;
             }
         }
     }
     catch (Exception exception)
     {
         Logger.Error(exception, null);
     }
 }
Example #26
0
    /// <summary>
    /// Выкинуть предмет из инвентаря
    /// </summary>
    /// <param name="item">Выкидываемый предмет</param>
    private void DropItem(PhysicalItem item)
    {
        bool operationSuccess = false;

        if (_equippedSmallRiffle == item)
        {
            _equippedSmallRiffle = null; item.Unequip(); operationSuccess = true;
        }
        else if (_equippedMeleeWeapon == item)
        {
            _equippedMeleeWeapon = null; item.Unequip(); operationSuccess = true;
        }
        else if (_equippedSmallItem == item)
        {
            _equippedSmallItem = null; item.Unequip(); operationSuccess = true;
        }
        CloseBackPackUI();

        if (operationSuccess)
        {
            LevelManager.Instance.UnequipEvent.Invoke(item);
        }
    }
Example #27
0
        private static void Main(string[] args)
        {
            ConfigureApplication();

            var foolano      = new Customer("*****@*****.**");
            var book         = new Book("Awesome book");
            var broom        = new PhysicalItem("Broom");
            var membership   = new Membership("Premium account");
            var address      = new Address("79042-656");
            var digitalMedia = new DigitalMedia("AwesomeBook.epub");
            var creditCard   = CreditCard.FetchByHashed("43567890-987654367");

            var order = new Order(foolano, address);

            order.AddProduct(book);
            order.AddProduct(broom);
            order.AddProduct(membership);
            order.AddProduct(digitalMedia);
            order.Pay(creditCard);

            Console.WriteLine(order.IsPaid);
            Console.WriteLine(order.Items[0].Product);
            Console.WriteLine(foolano.Memberships.First().Activated);
        }
Example #28
0
 public abstract bool CanPick(PhysicalItem physicalItem, int costThreshold);
Example #29
0
 public override bool CanPick(PhysicalItem physicalItem, int costThreshold)
 {
     return(false);
 }
Example #30
0
 public static decimal RefinedPerSecond(RefineryBlock refinery, PhysicalItem ore, Blueprint blueprint)
 {
     Debug.Assert(Equals(blueprint.Inputs.Single().ItemId, ore.Id));
     var producedPerSecond = 1 / blueprint.BaseProductionTimeInSeconds;
     return 0;
 }
Example #31
0
 public override bool CanPick(PhysicalItem physicalItem)
 {
     return(false);
 }