public async Task Add_user_Notification_success() { //Arrange var model = new NotificationEventModel { Data = new NotificationData { AppointmentDateTime = "23/01/2020", FirstName = "Romio", OrganisationName = "Little Runners", Reason = "Healthy" }, Type = "AppointmentCancelled", UserId = Guid.NewGuid() }; //Act var catalogContext = new NotificationsDbContext(_dbOptions); var accessServ = new NotificationsAccess(catalogContext); var NotificationServ = new NotificationsService(accessServ); var testController = new NotificationsController(NotificationServ); var actionResult = await testController.AddUserNotification(model).ConfigureAwait(false); //Assert Assert.IsType <OkObjectResult>(actionResult); var result = Assert.IsAssignableFrom <NotificationModel>(((OkObjectResult)actionResult).Value); Assert.Contains("Healthy", result.Message); }
public async Task <NotificationModel> AddUserNotification(NotificationEventModel notication) { var template = dbContext.Templates.FirstOrDefault(x => x.EventType == notication.Type); if (template == null) { return(null); } var entity = new NotificationEntity { UserId = notication.UserId, DateAdded = DateTime.Now, EventType = notication.Type }; entity.Message = template.Body; entity.Message = entity.Message.Replace("{Firstname}", notication.Data.FirstName); entity.Message = entity.Message.Replace("{OrganisationName}", notication.Data.OrganisationName); entity.Message = entity.Message.Replace("{AppointmentDateTime}", notication.Data.AppointmentDateTime); entity.Message = entity.Message.Replace("{Reason}", notication.Data.Reason); await dbContext.Notifications.AddAsync(entity).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); return(new NotificationModel() { Id = entity.Id, Message = entity.Message, EventType = entity.EventType, UserId = entity.UserId }); }
public async Task <IActionResult> AddUserNotification([FromBody] NotificationEventModel request) { var result = await _notificationsService.AddUserNotification(request).ConfigureAwait(false); if (result == null || result.Id == null || result.Id == default) { return(NotFound(result)); } return(Ok(result)); }
public async Task Add_Notification_by_userid_and_response_ok_Not_Found() { using (var server = CreateServer()) { var notificationEventModel = new NotificationEventModel(); var content = new StringContent(JsonConvert.SerializeObject(notificationEventModel), Encoding.UTF8, "application/json"); var response = await server.CreateClient() .PostAsync(HttPActionRoute.AddUserNotification(), content); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); } }
public async Task Add_Notification_by_userid_and_response_ok_status_code() { using (var server = CreateServer()) { var notificationEventModel = new NotificationEventModel { Type = EventType.AppointmentCancelled.ToString(), UserId = new Guid(userId), Data = new NotificationData { AppointmentDateTime = "28/01/2020", FirstName = "Test", OrganisationName = "Integration", Reason = "Robustness" } }; var content = new StringContent(JsonConvert.SerializeObject(notificationEventModel), Encoding.UTF8, "application/json"); var response = await server.CreateClient() .PostAsync(HttPActionRoute.AddUserNotification(), content); response.EnsureSuccessStatusCode(); } }
public async Task <NotificationModel> AddUserNotification(NotificationEventModel notification) { var result = await this.notificationsAccess.AddUserNotification(notification).ConfigureAwait(false); return(result); }