public void TestCanAddAndCanDeleteItem() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); LazySessionContext.Bind(new Lazy <ISession>(() => session), fac); IRomMessageProcessor p = RomViewContainer.Container.GetInstance <IRomMessageProcessor>(); IItemRepository repository = RomViewContainer.Container.GetInstance <IItemRepository>(); ItemDefinition expected = new ItemDefinition() { RomId = 999999, Name = "TestItem", ItemType = "ItemType", ItemSubType = "ItemSubType", ItemSubSubType = "ItemSubSubType", Value = 999 }; //romItem id = 228216 string source = string.Format("ITEM{0}SAVE{0}{1}", (char)1, expected.ToDelimitedString(2)); string response = p.HandleMessage(source); Assert.IsNull(response); ItemDefinition result = repository.GetByRomId(expected.RomId); Assert.IsNotNull(result); Assert.AreEqual(expected.ToDelimitedString(1), result.ToDelimitedString(1)); tx.Rollback(); }
public void TestCanFetchByName() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); try { IRepository <ItemDefinition> rep = RomViewContainer.Container.GetInstance <IRepository <ItemDefinition> >(); IItemRepository repository = new ItemRepository(rep); ItemDefinition def = new ItemDefinition { RomId = 999999, Name = "Augury Cloth Bootses", ItemType = "Armor", ItemSubType = "Boots", ItemSubSubType = "Cloth", Value = 100 }; string expected = def.ToDelimitedString(1); repository.AddItem(def); ItemDefinition result = repository.Get(def.Name); Assert.AreEqual(expected, result.ToDelimitedString(1)); } finally { tx.Rollback(); session.Close(); } }
private string _handleItemMessage(string[] sections) { string response = null; ItemDefinition def; int romId; switch (sections[1]) { case "SAVE": def = new ItemDefinition(sections[2], 2); ItemDefinition match = _itemRepository.GetByRomId(def.RomId); if (match != null) { match.Name = def.Name; match.ItemType = def.ItemType; match.ItemSubType = def.ItemSubType; match.ItemSubSubType = def.ItemSubSubType; match.Value = def.Value; _itemRepository.UpdateItem(match); } else { _itemRepository.AddItem(def); } break; case "DELETE": romId = Convert.ToInt32(sections[2]); _itemRepository.DeleteItem(romId); break; case "GET": romId = Convert.ToInt32(sections[2]); def = _itemRepository.GetByRomId(romId); if (def != null) { response = def.ToDelimitedString(1); } else { response = ItemDefinition.GetNullDefinitionString(1); } break; case "FIND": switch (sections[2]) { case "NAME": string name = sections[3]; def = _itemRepository.Get(name); if (def != null) { response = def.ToDelimitedString(1); } else { response = ItemDefinition.GetNullDefinitionString(1); } break; } break; } return(response); }