public static void Handle(Rate temp, Socket socket) { bool VoteExist = UsersInfos.VoteExist(temp.MusicRatedMID, Program.MyServer.Clients[socket]); UsersInfos.AddVoteMusic(temp.MusicRatedMID, Program.MyServer.Clients[socket]); if (temp.Type == ElementType.Music) { var m = Indexation.GetMusicByID(temp.MusicRatedMID); if (m != null) { if (VoteExist) { m.Rating--; } else { m.Rating++; Program.MyServer.Clients.TryGetValue(socket, out string uid); Program.MyServer.SendObject(new RequestAnswer(UsersInfos.GetLikedMusics(uid)), socket); } Program.MyServer.SendObject(new RateReport(true, temp.MusicRatedMID, m.Rating), socket); MusicsInfo.SaveMusicInfo(m); } } else { UsersInfos.RatePlaylist(temp.MusicRatedMID, !VoteExist); Program.MyServer.SendObject(new RateReport(true, temp.MusicRatedMID, UsersInfos.GetPlaylist(temp.MusicRatedMID).Rating), socket); } }
public void VoteExistTest() { Authentification.AuthentificationService a = new Authentification.AuthentificationService(); a.SetupAuth(); a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc")); Assert.AreEqual(false, UsersInfos.VoteExist("IncorrectMID", "abc")); Assert.AreEqual(false, UsersInfos.VoteExist("MusicMID", "IncorrectUID")); Assert.AreEqual(false, UsersInfos.VoteExist("MusicMID", "abc")); UsersInfos.AddVoteMusic("MusicMID", "abc"); Assert.AreEqual(false, UsersInfos.VoteExist("IncorrectMID", "abc")); Assert.AreEqual(false, UsersInfos.VoteExist("MusicMID", "IncorrectUID")); Assert.AreEqual(true, UsersInfos.VoteExist("MusicMID", "abc")); }