public void Initialize() { _subscribedUsersStoreMock = new Mock <INotificationSubscribedUserRepository>(); _subscribeDataDto = new NotificationSubscribedUserDto() { DeviceIdentifier = "test", UserId = 1 }; _service = new NotificationSubscribedUserService(_subscribedUsersStoreMock.Object); _subscribeData = new NotificationSubscribedUser() { UserId = 1, DeviceIdentifier = "test", CreatedDate = DateTime.Now, CreatorId = 1 }; }
public async Task <bool> UserIsSubscribedAsync(NotificationSubscribedUserDto subscribeModel) { if (subscribeModel == null) { throw new ArgumentException(Resources.NullOrEmptyValue, nameof(subscribeModel)); } if (subscribeModel.UserId < 1) { throw new ArgumentException(Resources.LessThanOrEqualToZeroValue, nameof(subscribeModel.UserId)); } if (string.IsNullOrWhiteSpace(subscribeModel.DeviceIdentifier)) { throw new ArgumentException(Resources.NullOrEmptyValueString, nameof(subscribeModel.DeviceIdentifier)); } var subscribe = await GetSubscribeAsync(subscribeModel); return(subscribe != null); }
public NotificationSubscribedUserDto Subscribe(NotificationSubscribedUserDto subscribeData) { if (subscribeData == null) { throw new ArgumentException(Resources.NullOrEmptyValue, nameof(subscribeData)); } if (subscribeData.UserId < 1) { throw new ArgumentException(Resources.LessThanOrEqualToZeroValue, nameof(subscribeData.UserId)); } if (string.IsNullOrWhiteSpace(subscribeData.DeviceIdentifier)) { throw new ArgumentException(Resources.NullOrEmptyValueString, nameof(subscribeData.DeviceIdentifier)); } var subscribe = GetSubscribe(subscribeData); subscribe = subscribe ?? _repository.Add(Mapper.Map <NotificationSubscribedUser>(subscribeData)); return(Mapper.Map <NotificationSubscribedUserDto>(subscribe)); }
/// <summary> /// Get user subscribe /// </summary> /// <param name="subscribeModel">subscribe model</param> /// <returns>User subscribtion</returns> private async Task <NotificationSubscribedUser> GetSubscribeAsync(NotificationSubscribedUserDto subscribeModel) { return(await _repository.GetAsync(subscribeModel.UserId, subscribeModel.DeviceIdentifier)); }
/// <summary> /// Get user subscribe /// </summary> /// <param name="subscribeModel">subscribe model</param> /// <returns>User subscribtion</returns> private NotificationSubscribedUser GetSubscribe(NotificationSubscribedUserDto subscribeModel) { return(_repository.Get(subscribeModel.UserId, subscribeModel.DeviceIdentifier)); }