public static void Create(Action done) { const string section = "PTestPlayerLevels.Create"; Console.WriteLine (section); var level = new PlayerLevel { name = "create level" + rnd, playername = "ben" + rnd, playerid = "0", data = "this is the level data", fields = new Hashtable { {"rnd", rnd} } }; PlayerLevels.Save (level, (l, r) => { l = l ?? new PlayerLevel(); AssertTrue(section + "#1", "Request succeeded", r.success); AssertEquals(section + "#1", "No errorcode", r.errorcode, 0); AssertTrue(section + "#1", "Returned level is not null", l.Keys.Count > 0); AssertTrue(section + "#1", "Returned level has levelid", l.ContainsKey("levelid")); AssertEquals(section + "#1", "Level names match", level.name, l.name); PlayerLevels.Save (level, (l2, r2) => { AssertTrue(section + "#2", "Request succeeded", r2.success); AssertEquals(section + "#2", "Duplicate level errorcode", r2.errorcode, 405); done(); }); }); }
/** * Saves a PlayerLevel * @param level PlayerLevel The level * @param callback Action<PlayerLevel, PResponse> Callback function */ public static void Save(PlayerLevel level, Action<PlayerLevel, PResponse> callback) { SendSaveLoadRequest(SECTION, SAVE, level, callback); }
/** * Saves a PlayerLevel * @param level PlayerLevel The level * @param callback Action<PlayerLevel, PResponse> Callback function */ public static void Save(PlayerLevel level, Action <PlayerLevel, PResponse> callback) { SendSaveLoadRequest(SECTION, SAVE, level, callback); }
public static void Rate(Action done) { const string section = "TestPlayerLevels.Rate"; Console.WriteLine (section); var level = new PlayerLevel { name = "rate " + rnd, playername = "ben" + rnd, playerid = "0", data = "this is the level data", fields = new Hashtable { {"rnd", rnd} } }; PlayerLevels.Save(level, (l, r) => { l = l ?? new PlayerLevel(); AssertTrue(section + "#1", "Request succeeded", r.success); AssertEquals(section + "#1", "No errorcode", r.errorcode, 0); AssertTrue(section + "#1", "Returned level is not null", l.Keys.Count > 0); AssertTrue(section + "#1", "Returned level has levelid", l.ContainsKey("levelid")); // invalid rating PlayerLevels.Rate (l.levelid, 70, r2 => { AssertFalse(section + "#2", "Request failed", r2.success); AssertEquals(section + "#2", "Invalid rating errorcode", r2.errorcode, 401); // valid rating PlayerLevels.Rate (l.levelid, 7, r3 => { AssertTrue(section + "#3", "Request succeeded", r3.success); AssertEquals(section + "#3", "No errrorcode", r3.errorcode, 0); // duplicate rating PlayerLevels.Rate (l.levelid, 6, r4 => { AssertFalse(section + "#4", "Request failed", r4.success); AssertEquals(section + "#4", "Already rated errorcode", r4.errorcode, 402); done(); }); }); }); }); }
public static void Load(Action done) { const string section = "TestPlayerLevels.Load"; Console.WriteLine (section); var level = new PlayerLevel { name = "sample loading level " + rnd, playername = "ben" + rnd, playerid = rnd.ToString(CultureInfo.InvariantCulture), data = "this is the level data", fields = new Hashtable { {"rnd", rnd} } }; PlayerLevels.Save (level, (l, r) => { AssertTrue(section + "#1", "Request succeeded", r.success); AssertEquals(section + "#1", "No errorcode", r.errorcode, 0); AssertTrue(section + "#1", "Name is correct", l.ContainsKey("levelid")); AssertEquals(section + "#1", "Name is correct", level.name, l.name); AssertEquals(section + "#1", "Data is correct", level.data, l.data); PlayerLevels.Load (l.levelid, (l2, r2) => { AssertTrue(section, "Request succeeded", r2.success); AssertEquals(section, "No errorcode", r2.errorcode, 0); AssertEquals(section, "Name is correct", level.name, l2.name); AssertEquals(section, "Data is correct", level.data, l2.data); done(); }); }); }