public BaseResponse <UserNotification> AddUserNotification(UserNotification model) { var response = new BaseResponse <UserNotification>(); var errors = Validate <UserNotification>(model, new UserNotificationValidator()); if (errors.Count() > 0) { BaseResponse <UserNotification> errResponse = new BaseResponse <UserNotification>(model, errors); errResponse.IsSuccess = false; return(errResponse); } var userNotification = _userNotificationRepository.FindBy(x => x.UserId == model.UserId && x.DeviceId == model.DeviceId).FirstOrDefault(); if (userNotification != null) { userNotification.ClientId = model.ClientId; response.Value = _userNotificationRepository.Edit(userNotification); return(response); } try { response.Value = _userNotificationRepository.Add(model); } catch (Exception ex) { response.IsSuccess = false; response.Message = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace; } return(response); }
public void Can_Add() { //Arrange var notification = new UserNotification(); _repository.Setup(x => x.Insert(notification)).Returns <UserNotification>(x => x); //Act var userNotification = _sut.Add(notification); //Assert Assert.Same(notification, userNotification); VerifySaved(); }