/// <summary> /// Deep load all KitInfo children. /// </summary> private void Step_03_DeepLoad_Generated() { using (TransactionManager tm = CreateTransaction()) { int count = -1; mock = CreateMockInstance(tm); mockCollection = DataRepository.KitInfoProvider.GetPaged(tm, 0, 10, out count); DataRepository.KitInfoProvider.DeepLoading += new EntityProviderBaseCore <KitInfo, KitInfoKey> .DeepLoadingEventHandler( delegate(object sender, DeepSessionEventArgs e) { if (e.DeepSession.Count > 3) { e.Cancel = true; } } ); if (mockCollection.Count > 0) { DataRepository.KitInfoProvider.DeepLoad(tm, mockCollection[0]); System.Console.WriteLine("KitInfo instance correctly deep loaded at 1 level."); mockCollection.Add(mock); // DataRepository.KitInfoProvider.DeepSave(tm, mockCollection); } //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
///<summary> /// Update the Typed KitInfo Entity with modified mock values. ///</summary> static public void UpdateMockInstance(TransactionManager tm, KitInfo mock) { KitInfoTest.UpdateMockInstance_Generated(tm, mock); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); }
protected void CopyValues(KitInfo source) { if (source == null) { return; } _base.CopyValues(source); }
/// <summary> /// Check the foreign key dal methods. /// </summary> private void Step_10_FK_Generated() { using (TransactionManager tm = CreateTransaction()) { KitInfo entity = CreateMockInstance(tm); bool result = DataRepository.KitInfoProvider.Insert(tm, entity); Assert.IsTrue(result, "Could Not Test FK, Insert Failed"); } }
/// <summary> /// Test methods exposed by the EntityHelper class. /// </summary> private void Step_20_TestEntityHelper_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); KitInfo entity = mock.Copy() as KitInfo; entity = (KitInfo)mock.Clone(); Assert.IsTrue(KitInfo.ValueEquals(entity, mock), "Clone is not working"); } }
///<summary> /// Returns a Typed KitInfo Entity with mock values. ///</summary> static public KitInfo CreateMockInstance(TransactionManager tm) { // get the default mock instance KitInfo mock = KitInfoTest.CreateMockInstance_Generated(tm); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); // return the modified object return(mock); }
/// <summary> /// Serialize the mock KitInfo entity into a temporary file. /// </summary> private void Step_06_SerializeEntity_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp_KitInfo.xml"); EntityHelper.SerializeXml(mock, fileName); Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock not found"); System.Console.WriteLine("mock correctly serialized to a temporary file."); } }
/// <summary> /// Check the indexes dal methods. /// </summary> private void Step_11_IX_Generated() { using (TransactionManager tm = CreateTransaction()) { KitInfo entity = CreateMockInstance(tm); bool result = DataRepository.KitInfoProvider.Insert(tm, entity); Assert.IsTrue(result, "Could Not Test IX, Insert Failed"); KitInfo t0 = DataRepository.KitInfoProvider.GetByKitIdGoodsId(tm, entity.KitId, entity.GoodsId); } }
private static KitInfo GetDataKitInfo(BasePlayer player, string kitName, DataEntry data = null) { data = data ?? Data.Get(player.UserIDString); var kitInfo = (KitInfo)null; if (!data.kitsInfo.TryGetValue(kitName, out kitInfo)) { kitInfo = new KitInfo(); data.kitsInfo.Add(kitName, kitInfo); } return(kitInfo); }
/// <summary> /// Inserts a mock KitInfo entity into the database. /// </summary> private void Step_01_Insert_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); Assert.IsTrue(DataRepository.KitInfoProvider.Insert(tm, mock), "Insert failed"); System.Console.WriteLine("DataRepository.KitInfoProvider.Insert(mock):"); System.Console.WriteLine(mock); //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
void AddKit(Player player, string[] args) { if (args.Length < 2) { SendMessage(player, InvalidArgs); return; } var kitname = args[0]; var description = args[1]; KitData kit; if (FindKit(kitname, out kit)) { SendMessage(player, AKitAlreadyExists, kitname); return; } kit = new KitData(); var kitinfo = new KitInfo(args); kit.Name = kitname; kit.Description = description; kit.Permission = kitinfo.GetVariable("permission"); kit.Cooldown = Convert.ToInt32(kitinfo.GetVariable("cooldown")); kit.Uses = Convert.ToInt32(kitinfo.GetVariable("uses")); kit.UsesReset = Convert.ToInt32(kitinfo.GetVariable("reset")); kit.Stacks = 0; SendMessage(player, AKitCreated, kitname); if (kitinfo.HasVariable("inventory")) { var inventory = player.CurrentCharacter.Entity.GetContainerOfType(CollectionTypes.Inventory); var itemCount = 0; foreach (var item in inventory.Contents.Where(item => item != null)) { itemCount++; kit.Items.Add(new KitItem(item.Name, item.StackAmount)); kit.Stacks++; } SendMessage(player, AKitCreatedInvFlag, itemCount); } kitsdata.Add(kitname, kit); storedData.KitsData.Add(kit); }
/// <summary> /// Serialize a KitInfo collection into a temporary file. /// </summary> private void Step_08_SerializeCollection_Generated() { using (TransactionManager tm = CreateTransaction()) { string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp_KitInfoCollection.xml"); mock = CreateMockInstance(tm); TList <KitInfo> mockCollection = new TList <KitInfo>(); mockCollection.Add(mock); EntityHelper.SerializeXml(mockCollection, fileName); Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found"); System.Console.WriteLine("TList<KitInfo> correctly serialized to a temporary file."); } }
private string GetUIMessage(BasePlayer player, Kit kit, KitInfo kitInfo) { if (!HasPermission(player, kit.permission)) { if (!kit.showWithoutPermission) { return(null); } return(string.IsNullOrEmpty(kit.messageForNoPermission) ? GetMessage(Message.PermissionUI, player.UserIDString) : kit.messageForNoPermission); } if (kit.uses > 0) { var left = kit.uses - kitInfo.uses; if (left <= 0) { return(!kit.showWithoutUses ? null : GetMessage(Message.UsesLeftUI, "{limit}", 0)); } } if (kit.block > 0 && !kit.blockBypass) { var unblockDate = SaveRestore.SaveCreatedTime.AddSeconds(kit.block); var leftSpan = unblockDate - DateTime.UtcNow; if (leftSpan.TotalSeconds > 0) { return(!kit.showIfWipeBlocked ? null : GetMessage(Message.WipeblockUI, player.UserIDString, "{d}", GetTimeLeft(leftSpan.Days, "d"), "{h}", GetTimeLeft(leftSpan.Hours, "h"), "{m}", GetTimeLeft(leftSpan.Minutes, "m"), "{s}", GetTimeLeft(leftSpan.Seconds, "s"))); } else { kit.blockBypass = true; } } if (kit.cooldown > 0) { var unblockDate = kitInfo.lastUse.AddSeconds(kit.cooldown); var leftSpan = unblockDate - DateTime.UtcNow; if (leftSpan.TotalSeconds > 0) { return(!kit.showIfOnCooldown ? null : GetMessage(Message.CooldownUI, player.UserIDString, "{d}", GetTimeLeft(leftSpan.Days, "d"), "{h}", GetTimeLeft(leftSpan.Hours, "h"), "{m}", GetTimeLeft(leftSpan.Minutes, "m"), "{s}", GetTimeLeft(leftSpan.Seconds, "s"))); } } return(GetMessage(Message.AvailableUI, player.UserIDString)); }
///<summary> /// Returns a Typed KitInfo Entity with mock values. ///</summary> static public KitInfo CreateMockInstance_Generated(TransactionManager tm) { KitInfo mock = new KitInfo(); mock.KitId = TestUtility.Instance.RandomString(7, false);; mock.GoodsId = TestUtility.Instance.RandomString(6, false);; mock.Qty = (decimal)TestUtility.Instance.RandomShort(); // create a temporary collection and add the item to it TList <KitInfo> tempMockCollection = new TList <KitInfo>(); tempMockCollection.Add(mock); tempMockCollection.Remove(mock); return((KitInfo)mock); }
/// <summary> /// Test Find using the Query class /// </summary> private void Step_30_TestFindByQuery_Generated() { using (TransactionManager tm = CreateTransaction()) { //Insert Mock Instance KitInfo mock = CreateMockInstance(tm); bool result = DataRepository.KitInfoProvider.Insert(tm, mock); Assert.IsTrue(result, "Could Not Test FindByQuery, Insert Failed"); KitInfoQuery query = new KitInfoQuery(); query.AppendEquals(KitInfoColumn.KitId, mock.KitId.ToString()); query.AppendEquals(KitInfoColumn.GoodsId, mock.GoodsId.ToString()); if (mock.Qty != null) { query.AppendEquals(KitInfoColumn.Qty, mock.Qty.ToString()); } TList <KitInfo> results = DataRepository.KitInfoProvider.Find(tm, query); Assert.IsTrue(results.Count == 1, "Find is not working correctly. Failed to find the mock instance"); } }
///<summary> /// Update the Typed KitInfo Entity with modified mock values. ///</summary> static public void UpdateMockInstance_Generated(TransactionManager tm, KitInfo mock) { mock.Qty = (decimal)TestUtility.Instance.RandomShort(); }
/// <summary> /// Make any alterations necessary (i.e. for DB check constraints, special test cases, etc.) /// </summary> /// <param name="mock">Object to be modified</param> static private void SetSpecialTestData(KitInfo mock) { //Code your changes to the data object here. }