public static List <Character_Item> GetListOfHeldItems() { List <Character_Item> heldItems = new List <Character_Item>(); Character_Item Vax_Whisper = GetSampleHeldItem(); heldItems.Add(Vax_Whisper); Character_Item Grog_Knuckles = new Character_Item { Character_id = Guid.Parse("96992cfa-9e3b-480f-ab06-46539d3666f6"), Item_id = Guid.Parse("026a7dff-5e85-4e6d-94c6-6613828e5df6") }; heldItems.Add(Grog_Knuckles); Character_Item Vax_Potion = new Character_Item { Character_id = Guid.Parse("e3a0faef-99da-4d15-bff1-b535a42b955c"), Item_id = Guid.Parse("2caa23dc-15e6-4a57-9bb6-62f6d8636ff7"), count = 3 }; heldItems.Add(Vax_Potion); return(heldItems); }
public void ItemsRepository_CharacterObtainsItem_ByRecord_ValidCall() { //Arrange List <Character_Item> heldItems = new List <Character_Item>(); var mockSet = new Mock <DbSet <Character_Item> >() .SetupData(heldItems, o => { return(heldItems.Single(x => x.Item_id.CompareTo(o.First()) == 0)); }); var expected = new Character_Item { Character_id = Guid.Parse("e3a0faef-99da-4d15-bff1-b535a42b955c"), Item_id = Guid.Parse("709135c3-6f89-46cb-80ae-4097b621e3b0"), isEquipped = true, IsAttuned = true }; using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <ItemsContext>() .Setup(X => X.HeldItems).Returns(mockSet.Object); //Act IItemsRepository toTest = mockContext.Create <ItemsRepository>(); toTest.CharacterObtainsItem(expected); var actual = heldItems.First(); //assert actual.Should().BeEquivalentTo(expected); } }
public void CharacterCommons_CharacterObtainsItem_ValidCall() { //Arrange List <Character_Item> heldItems = new List <Character_Item>(); var mockSet = new Mock <DbSet <Character_Item> >() .SetupData(heldItems, o => { return(heldItems.Single(x => x.Character_id.CompareTo(o.First()) == 0)); }); Character_Item expected = new Character_Item { Character_id = CreateTestData.getSampleCharacter().Character_id, Item_id = CreateTestData.GetSampleItem().Item_id, count = 1 }; using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <ItemsContext>() .Setup(x => x.HeldItems).Returns(mockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.Set <Character_Item>()).Returns(mockSet.Object); IUnitOfWork uow = UoW_Factory.getUnitofWork(mockContext); IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow); //act ICharacterCommonFunctions toTest = ProcessorFactory.GetCharacterCommonFunctions(access); toTest.addHeldItemToDb(expected.Character_id, expected.Item_id); //Assert heldItems.Should().ContainEquivalentOf(expected); } }
public static HeldItemRowCM mapHeldItemRecordToHeldItemRowCM(Character_Item m) { ReadModelMapper <Character_Item, HeldItemRowCM> mapper = new ReadModelMapper <Character_Item, HeldItemRowCM>(); HeldItemRowCM cm = new HeldItemRowCM(); mapper.mapDataModelToViewModel(m, cm); return(cm); }
public HeldItemRowCM buildExistingHeldItemRowCM(Guid Character_id, Guid Item_id) { Item foundItem = _userAccess.GetItem(Item_id); HeldItemRowCM cm = CharacterMapper.mapItemToHeldItemRowCM(foundItem); Character_Item foundHeldItem = _userAccess.GetHeldItemRecord(Character_id, Item_id); CharacterMapper.mapHeldItemRecordToHeldItemRowCM(foundHeldItem, cm); return(cm); }
public static Character_Item GetSampleHeldItem() { Character_Item Vax_Whisper = new Character_Item() { Item_id = Guid.Parse("709135c3-6f89-46cb-80ae-4097b621e3b0"), Character_id = Guid.Parse("e3a0faef-99da-4d15-bff1-b535a42b955c") }; return(Vax_Whisper); }
public override void OnRead(RiftClient From) { if (CharacterMgr.Instance.GetCharactersCount(From.Acct.Id, From.Realm.RealmId) >= 6) { Log.Error("CharacterCreate", "Hack From : " + From.GetIp); From.Disconnect(); return; } LobbyCharacterCreateResponse Rp = new LobbyCharacterCreateResponse(); Character Exist = CharacterMgr.CharacterDB.SelectObject <Character>("Name='" + CharacterMgr.CharacterDB.Escape(Name) + "' AND RealmID=" + From.Realm.RealmId); if (Exist != null) { Rp.AddField(0, EPacketFieldType.Unsigned7BitEncoded, (long)6); } else { Rp.AddField(0, EPacketFieldType.Unsigned7BitEncoded, (long)0); PacketOutStream Stream = new PacketOutStream(); PacketProcessor.WritePacket(ref Stream, Custom, false, true, true); CustomData = Stream.ToArray(); string Data = UTF8ByteArrayToString(CustomData); Character Char = new Character(); Char.Name = Name; Char.AccountId = From.Acct.Id; Char.RealmId = From.Realm.RealmId; Char.Race = Field1; Char.Sex = Field2; Char.Class = Field13; Char.HairModelID = HairID; Char.Level = 1; Char.Data = Data; CharacterMgr.Instance.AddObject(Char); Character CharEntry = CharacterMgr.Instance.GetCharacter(CharacterMgr.CharacterDB.Escape(Name)); Character_StartItems[] StartItems = CharacterMgr.Instance.GetStartItems(Field1, Field2, Field13); foreach (Character_StartItems Item in StartItems) { Character_Item It = new Character_Item(); It.ItemID = Item.ItemID; It.Bag = 0; It.Equiped = 1; It.GUID = CharEntry.Id; CharacterMgr.Instance.AddObject(It); } } From.SendSerialized(Rp); }
public void CharacterObtainsItem(Guid Character_id, Guid Item_id) { Character_Item newHeldItem = new Character_Item { Character_id = Character_id, Item_id = Item_id, isEquipped = false, IsAttuned = false, count = 1 }; itemsContext.HeldItems.Add(newHeldItem); }
public void CMBuilder_buildExistingHeldItemCM_ValidCall() { //Arrange List <Item> items = CreateTestData.GetListOfItems(); var itemMockSet = new Mock <DbSet <Item> >() .SetupData(items, o => { return(items.Single(x => x.Item_id.CompareTo(o.First()) == 0)); }); List <Character_Item> heldItems = CreateTestData.GetListOfHeldItems(); var heldItemsMockSet = new Mock <DbSet <Character_Item> >() .SetupData(heldItems, o => { return(heldItems.Single(x => x.Item_id.CompareTo(o.First()) == 0)); }); Item item = CreateTestData.GetSampleItem(); Character_Item heldItem = CreateTestData.GetSampleHeldItem(); HeldItemRowCM expected = CharacterMapper.mapItemToHeldItemRowCM(item); CharacterMapper.mapHeldItemRecordToHeldItemRowCM(heldItem, expected); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <ItemsContext>() .Setup(x => x.Set <Item>()).Returns(itemMockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.Items).Returns(itemMockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.Set <Character_Item>()).Returns(heldItemsMockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.HeldItems).Returns(heldItemsMockSet.Object); IUnitOfWork uow = UoW_Factory.getUnitofWork(mockContext); IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow); //Act ICharacterCMBuilder toTest = ProcessorFactory.GetCharacterCMBuilder(access); var actual = toTest.buildExistingHeldItemRowCM(heldItem.Character_id, heldItem.Item_id); actual.Should().BeEquivalentTo(expected); } }
public void ItemsRepository_GetHeldItemRecordsForCharacter_ValidCall() { //Arrange List <Character_Item> heldItems = CreateTestData.GetListOfHeldItems(); var heldItemsMockSet = new Mock <DbSet <Character_Item> >() .SetupData(heldItems, o => { return(heldItems.Single(x => x.Character_id.CompareTo(o.First()) == 0)); }); List <Character_Item> expected = new List <Character_Item>(); Character_Item Vax_Whisper = CreateTestData.GetSampleHeldItem(); expected.Add(Vax_Whisper); Character_Item Vax_Potion = new Character_Item { Character_id = Guid.Parse("e3a0faef-99da-4d15-bff1-b535a42b955c"), Item_id = Guid.Parse("2caa23dc-15e6-4a57-9bb6-62f6d8636ff7"), count = 3 }; expected.Add(Vax_Potion); Guid Vax_id = Guid.Parse("e3a0faef-99da-4d15-bff1-b535a42b955c"); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <ItemsContext>() .Setup(x => x.HeldItems).Returns(heldItemsMockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.Set <Character_Item>()).Returns(heldItemsMockSet.Object); //Act IItemsRepository toTest = mockContext.Create <ItemsRepository>(); var actual = toTest.GetHeldItemRecordsForCharacter(Vax_id); //Assert actual.Should().BeEquivalentTo(expected); } }
private void SetInventory(IEnumerable <HeldItemRowCM> heldItems, Guid Character_id) { CreateModelMapper <HeldItemRowCM, Character_Item> mapper = new CreateModelMapper <HeldItemRowCM, Character_Item>(); List <Guid> obtainedItems = new List <Guid>(); foreach (HeldItemRowCM heldItem in heldItems) { Guid item_id = heldItem.Item_id; if (_commons.itemExists(item_id) && obtainedItems.Contains(item_id) == false) { Character_Item record = mapper.mapViewModelToDataModel(heldItem); record.Character_id = Character_id; _userAccess.CharacterObtainsItem(record); obtainedItems.Add(item_id); } else { continue; } } }
public void CharacterLosesItem(Guid Character_id, Guid Item_id) { Character_Item foundRecord = itemsContext.HeldItems.Where(x => x.Character_id == Character_id & x.Item_id == Item_id).First(); itemsContext.HeldItems.Remove(foundRecord); }
public void CharacterObtainsItem(Character_Item record) { _worker.Items.CharacterObtainsItem(record); }
public override void OnRead(RiftClient From) { if (CharacterMgr.Instance.GetCharactersCount(From.Acct.Id, From.Realm.RealmId) >= 6) { Log.Error("CharacterCreate", "Hack From : " + From.GetIp); From.Disconnect(); return; } LobbyCharacterCreateResponse Rp = new LobbyCharacterCreateResponse(); Character Exist = CharacterMgr.CharacterDB.SelectObject<Character>("Name='" + CharacterMgr.CharacterDB.Escape(Name) + "' AND RealmID=" + From.Realm.RealmId); if (Exist != null) { Rp.AddField(0, EPacketFieldType.Unsigned7BitEncoded, (long)6); } else { Rp.AddField(0, EPacketFieldType.Unsigned7BitEncoded, (long)0); PacketOutStream Stream = new PacketOutStream(); PacketProcessor.WritePacket(ref Stream, Custom, false, true, true); CustomData = Stream.ToArray(); string Data = UTF8ByteArrayToString(CustomData); Character Char = new Character(); Char.Name = Name; Char.AccountId = From.Acct.Id; Char.RealmId = From.Realm.RealmId; Char.Race = Field1; Char.Sex = Field2; Char.Class = Field13; Char.HairModelID = HairID; Char.Level = 1; Char.Data = Data; CharacterMgr.Instance.AddObject(Char); Character CharEntry = CharacterMgr.Instance.GetCharacter(CharacterMgr.CharacterDB.Escape(Name)); Character_StartItems[] StartItems = CharacterMgr.Instance.GetStartItems(Field1, Field2, Field13); foreach (Character_StartItems Item in StartItems) { Character_Item It = new Character_Item(); It.ItemID = Item.ItemID; It.Bag = 0; It.Equiped = 1; It.GUID = CharEntry.Id; CharacterMgr.Instance.AddObject(It); } } From.SendSerialized(Rp); }
public void CMBuilder_buildHeldItemRowCMsForCharacter_ValidCall() { List <Item> items = CreateTestData.GetListOfItems(); var itemMockSet = new Mock <DbSet <Item> >() .SetupData(items, o => { return(items.Single(x => x.Item_id.CompareTo(o.First()) == 0)); }); List <Character_Item> heldItems = CreateTestData.GetListOfHeldItems(); var heldItemsMockSet = new Mock <DbSet <Character_Item> >() .SetupData(heldItems, o => { return(heldItems.Single(x => x.Item_id.CompareTo(o.First()) == 0)); }); List <HeldItemRowCM> expected = new List <HeldItemRowCM>(); Item Whisper = CreateTestData.GetSampleItem(); Character_Item VaxHoldsWhisper = CreateTestData.GetSampleHeldItem(); HeldItemRowCM Vax_Whisper = CharacterMapper.mapItemToHeldItemRowCM(Whisper); CharacterMapper.mapHeldItemRecordToHeldItemRowCM(VaxHoldsWhisper, Vax_Whisper); Vax_Whisper.Index = 0; expected.Add(Vax_Whisper); Item HealingPotion = new Item { Item_id = Guid.Parse("2caa23dc-15e6-4a57-9bb6-62f6d8636ff7"), Name = "Healing potion", Description = "Upon consumption of the whole potion, the imbiber heals for 2d4+2 health.", isEquippable = false, isConsumable = true, requiresAttunement = false, Value = 50 }; Character_Item VaxHoldsPotions = new Character_Item { Character_id = Guid.Parse("e3a0faef-99da-4d15-bff1-b535a42b955c"), Item_id = Guid.Parse("2caa23dc-15e6-4a57-9bb6-62f6d8636ff7"), count = 3 }; HeldItemRowCM Vax_Potions = CharacterMapper.mapItemToHeldItemRowCM(HealingPotion); CharacterMapper.mapHeldItemRecordToHeldItemRowCM(VaxHoldsPotions, Vax_Potions); Vax_Potions.Index = 1; expected.Add(Vax_Potions); Guid Vax_id = Guid.Parse("e3a0faef-99da-4d15-bff1-b535a42b955c"); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <ItemsContext>() .Setup(x => x.Set <Item>()).Returns(itemMockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.Items).Returns(itemMockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.Set <Character_Item>()).Returns(heldItemsMockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.HeldItems).Returns(heldItemsMockSet.Object); IUnitOfWork uow = UoW_Factory.getUnitofWork(mockContext); IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow); //Act ICharacterCMBuilder toTest = ProcessorFactory.GetCharacterCMBuilder(access); var actual = toTest.buildItemRowCMsForCharacter(Vax_id); actual.Should().BeEquivalentTo(expected); } }
public static void mapHeldItemRecordToHeldItemRowCM(Character_Item m, HeldItemRowCM cm) { ReadModelMapper <Character_Item, HeldItemRowCM> mapper = new ReadModelMapper <Character_Item, HeldItemRowCM>(); mapper.mapDataModelToViewModel(m, cm); }
public void CharacterObtainsItem(Character_Item record) { itemsContext.HeldItems.Add(record); }