public async Task Test1_GetNotificationByIdAsync() { //Arrange string notification_id = "6xyKcZwxg1cXjUkjaggIf8WGWzu11fhFeGGSZsIyQqwPkuMA"; Notification notification; //Act notification = await NotificationsFirestore.GetNotificationByIdAsync(notification_id); //Assert Assert.True(notification.type.Equals("member_request")); }
public async Task Test3_DeleteNotificationAsync() { string user_id = "ryZJ4v8INRes4o2ZxEaNOPDtqgo2"; string team_id = "1fhFeGGSZsIyQqwPkuMA"; //Act //Notification ID = User ID + Team ID --> To create 1-1 mapping, avoid users to request multiple times await NotificationsFirestore.DeleteNotificationAsync(user_id + team_id); var notification = await NotificationsFirestore.GetNotificationByIdAsync(user_id + team_id); //Assert Assert.Null(notification); }
async Task ExecuteLoadNotificationsCommand() { if (IsBusy) { return; } IsBusy = true; try { notificationsList.Clear(); var notifications = await NotificationsFirestore.GetMyNotificationsAsync(); foreach (var notification in notifications) { // Set the visibility of each notification setVisibility(notification); if (notification.isVisible) { // Load team & user notification.team = await TeamsFirestore.GetTeamByIdAsync(notification.team_id); notification.user = await UsersFirestore.GetUserByUIDAsync(notification.user_id); // Create a message setNotificationContent(notification); notificationsList.Add(notification); } } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public async Task Test2_CreateNotificationAsync() { string user_id = "ryZJ4v8INRes4o2ZxEaNOPDtqgo2"; string team_id = "1fhFeGGSZsIyQqwPkuMA"; //Arrange Notification notification = new Notification { team_id = team_id, user_id = user_id, status = "", type = "team_invitation" }; //Act await NotificationsFirestore.CreateNotificationAsync(notification); //Notification ID = User ID + Team ID --> To create 1-1 mapping, avoid users to request multiple times var newNotification = await NotificationsFirestore.GetNotificationByIdAsync(user_id + team_id); //Assert Assert.True(newNotification.type.Equals("team_invitation")); }
async void JoinButtonClicked(object sender, EventArgs args) { switch (userStatus) { case (sbyte)relationshipType.isInside: var answer = await DisplayAlert("Exit", "Do you really want to leave your group ?", "Leave", "Cancel"); if (answer) { //If is already inside Team, then button is for leaving the team await TeamsFirestore.RemoveUserFromTeamAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team); await UsersFirestore.RemoveTeamFromUserAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team); //Remove notifications in database await NotificationsFirestore.DeleteNotificationAsync(UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id); joinTeamButton.Text = "Join Team"; userStatus = (sbyte)relationshipType.isOutside; } break; case (sbyte)relationshipType.isRequesting: //If is requesting, then button is for cancelled await TeamsFirestore.RemoveUserRequestFromTeamAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team); //Remove arised notification await NotificationsFirestore.DeleteNotificationAsync(UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id); await UsersFirestore.RemoveNotificationFromUserAsync(teamDetailsPageViewModel.Team.team_leader , /*Generate ID = User_id + Team_id*/ UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id); joinTeamButton.Text = "Join Team"; userStatus = (sbyte)relationshipType.isOutside; break; case (sbyte)relationshipType.isOutside: //If is outside, then button is for request joining team await TeamsFirestore.AddUserRequestToTeamAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team); // Create a notification Notification notification = new Notification { Id = UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id, team_id = teamDetailsPageViewModel.Team.Id, user_id = UsersFirestore.myProfile.Id, status = "", type = "member_request" }; // Arise a notification to the team leader of that team await UsersFirestore.AddNotificationToUserAsync(teamDetailsPageViewModel.Team.team_leader, notification.Id); //Push notification online await NotificationsFirestore.CreateNotificationAsync(notification); joinTeamButton.Text = "✔️ Requested"; joinTeamButton.BackgroundColor = Color.FromHex("#D3D3D3"); userStatus = (sbyte)relationshipType.isRequesting; break; } }