public async void AddNotification_Success() { CityRepository repository = new CityRepository(); City city = new City(); //{ // NOTIFICATION_TEXT = "Unit Test notification", // CREATED_DATE = DateTime.Now, // ID_DEPENDENCY = "iIAW2gamws" //}; RepositoryResponse<City> expected = new RepositoryResponse<City> { Success = true, Data = city }; var cities = new List<City> { new City { ID = "GUf2kxo3Yl" } }; RepositoryResponse<List<City>> result = await repository.GetCities(); Assert.IsTrue(result.Success, "Notifications not created"); Assert.IsNotNull(result.Data.Count > 0); Assert.IsNull(result.Error, "Some error ocurred"); }
public async Task<RepositoryResponse<Notification>> AddNotification(Notification notification) { var response = new RepositoryResponse<Notification> { }; try { var Noti = Parse.ParseObject.Create("Notification"); #region Add Dependency Relationship DependencyRepository DependencyContext = new DependencyRepository(); RepositoryResponse<ParseObject> Dependency = await DependencyContext.GetDependencyById(notification.ID_DEPENDENCY); ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Dependency"); IEnumerable<ParseObject> result = await query.FindAsync(); #endregion #region Add City Relationship CityRepository CityContext = new CityRepository(); RepositoryResponse<ParseObject> City = await CityContext.GetCityById(notification.ID_CITY); query = new ParseQuery<ParseObject>("City"); result = await query.FindAsync(); #endregion var relation = Noti.GetRelation<ParseObject>("ID_Dependency"); relation.Add(Dependency.Data); relation = Noti.GetRelation<ParseObject>("ID_City"); relation.Add(City.Data); var message = string.Format("{0} > {1}: {2}", Dependency.Data["Name"].ToString(), City.Data["Name"].ToString(), notification.NOTIFICATION_TEXT); Noti.Add("NotificationText", message); await Noti.SaveAsync(); await Noti.SaveAsync(); var push = new ParsePush(); push.Query = from installation in ParseInstallation.Query where installation.Get<string>("City").Contains(notification.ID_CITY) select installation; push.Alert = message; await push.SendAsync(); notification.ID = Noti.ObjectId; response.Data = notification; response.Success = true; } catch (Exception ex) { response.Success = false; response.Error = ex; } return response; }