public void TestItemMoveAddQuantityWrongItem() { const ulong TO_ID = 234987915; const int BASE_TO_ID = 1234; const ulong FROM_ID = 34151555; const int BASE_FROM_ID = 5678; const int FROM_QUANTITY = 10; const int TO_QUANTITY = 30; const int MOVE_QUANTITY = FROM_QUANTITY - 1; ItemInstance fromItem = new ItemInstance(FROM_ID); fromItem.quantity = FROM_QUANTITY; fromItem.baseId = BASE_FROM_ID; ItemLocation fromLoc = new ItemLocation(ItemZoneType.AdventureBag, 0, 0); _dummyCharacter.itemLocationVerifier.PutItem(fromLoc, fromItem); ItemInstance toItem = new ItemInstance(TO_ID); toItem.maxStackSize = TO_QUANTITY + MOVE_QUANTITY + 5; toItem.quantity = TO_QUANTITY; toItem.baseId = BASE_TO_ID; ItemLocation toLoc = new ItemLocation(ItemZoneType.AdventureBag, 0, 1); _dummyCharacter.itemLocationVerifier.PutItem(toLoc, toItem); ItemException e = Assert.Throws <ItemException>(() => _itemService.Move(fromLoc, toLoc, MOVE_QUANTITY)); Assert.Equal(ItemExceptionType.BagLocation, e.type); }
public void Run_InvalidFlagValue_ShouldThrowItemException(string flagValue) { //arrange const string expectedError = "Unknown flag value"; Item fakeContextItem = ItemHelper.CreateItem("GAG_GECO ChangeControlled", string.Empty); Item fakeAffectedItem = ItemHelper.CreateItem("GAG_GrammerChangeControlled", "get"); fakeAffectedItem.setProperty("gag_migration_edit_flag", flagValue); IDataAccessLayer fakeDal = Substitute.For <IDataAccessLayer>(); fakeDal.ApplyItem(Arg.Any <Item>()).Returns(fakeAffectedItem); fakeDal.NewItem("GAG_GrammerChangeControlled", "get").Returns(fakeAffectedItem); fakeDal.NewError(Arg.Any <string>()).Returns(ci => { Item error = ItemHelper.CreateItem(string.Empty, string.Empty); error.loadAML(string.Format(CultureInfo.CurrentCulture, ErrorResultTemplate, ci.ArgAt <string>(0))); return(error); }); var testClass = new TestClass(fakeDal); //act //assert ItemException exception = Assert.Throws <ItemException>(() => testClass.Run(fakeContextItem)); string actualError = exception?.ErrorItem?.getErrorString(); Assert.AreEqual(actualError, expectedError); }
public void Run_WhenContextItemHasDifferentFlagValue_ShouldThrowItemException() { //arrange const string expectedError = "The property gag_migration_edit_flag cannot be changed"; Item fakeContextItem = ItemHelper.CreateItem("CAD", string.Empty); fakeContextItem.setProperty("gag_migration_edit_flag", "0"); fakeContextItem.setProperty("config_id", GenerateConfigId()); Item fakeLatestItem = ItemHelper.CreateItem("CAD", string.Empty); fakeLatestItem.setProperty("gag_migration_edit_flag", "1"); fakeLatestItem.setProperty("config_id", GenerateConfigId()); IDataAccessLayer fakeDal = Substitute.For <IDataAccessLayer>(); fakeDal.ApplyItem(Arg.Any <Item>()).Returns(fakeLatestItem); fakeDal.NewItem(Arg.Any <string>(), Arg.Any <string>()).Returns(ItemHelper.CreateItem("CAD", string.Empty)); var testClass = new TestClass(fakeDal); //act //assert ItemException exception = Assert.Throws <ItemException>(() => testClass.Run(fakeContextItem)); string actualError = exception.Message; Assert.AreEqual(actualError, expectedError); }
public void TestItemMoveNoItemAtLocation() { const byte QUANTITY = 2; ItemLocation fromLoc = new ItemLocation(ItemZoneType.AdventureBag, 0, 0); ItemLocation toLoc = new ItemLocation(ItemZoneType.AdventureBag, 0, 1); ItemException e = Assert.Throws <ItemException>(() => _itemService.Move(fromLoc, toLoc, QUANTITY)); Assert.Equal(ItemExceptionType.Generic, e.type); }
public void TestItemRemoveTooMany() { const ulong INSTANCE_ID = 756366; const int QUANTITY_AVAILABLE = 5; const int QUANTITY_TO_REMOVE = QUANTITY_AVAILABLE + 5; ItemInstance itemInstance = new ItemInstance(INSTANCE_ID); itemInstance.quantity = QUANTITY_AVAILABLE; ItemLocation loc = new ItemLocation(ItemZoneType.AdventureBag, 0, 0); _dummyCharacter.itemLocationVerifier.PutItem(loc, itemInstance); ItemException e = Assert.Throws <ItemException>(() => _itemService.Remove(loc, QUANTITY_TO_REMOVE)); Assert.Equal(ItemExceptionType.Amount, e.type); }
public void TestItemMovePlaceInvalidQuantity() { const ulong INSTANCE_ID = 756366; const byte START_QUANTITY = 5; const byte MOVE_QUANTITY = 10; ItemInstance itemInstance = new ItemInstance(INSTANCE_ID); itemInstance.quantity = START_QUANTITY; ItemLocation fromLoc = new ItemLocation(ItemZoneType.AdventureBag, 0, 0); _dummyCharacter.itemLocationVerifier.PutItem(fromLoc, itemInstance); ItemLocation toLoc = new ItemLocation(ItemZoneType.AdventureBag, 0, 1); ItemException e = Assert.Throws <ItemException>(() => _itemService.Move(fromLoc, toLoc, MOVE_QUANTITY)); Assert.Equal(ItemExceptionType.Amount, e.type); }
public void TestItemMoveNonEmptyBagOutOfSlot() { const ulong BAG_ID = 534577777; const ulong ITEM_IN_BAG_ID = 5117; const int QUANTITY = 1; ItemInstance bag = new ItemInstance(BAG_ID); bag.bagSize = 8; ItemLocation bagLoc = new ItemLocation(ItemZoneType.BagSlot, 0, 0); _dummyCharacter.itemLocationVerifier.PutItem(bagLoc, bag); ItemInstance itemInBag = new ItemInstance(ITEM_IN_BAG_ID); ItemLocation itemInBagLoc = new ItemLocation(ItemZoneType.EquippedBags, 0, 0); _dummyCharacter.itemLocationVerifier.PutItem(itemInBagLoc, itemInBag); ItemLocation toLoc = new ItemLocation(ItemZoneType.AdventureBag, 0, 1); ItemException e = Assert.Throws <ItemException>(() => _itemService.Move(bagLoc, toLoc, QUANTITY)); Assert.Equal(ItemExceptionType.BagLocation, e.type); }