public async Task <ReportSubscriber> AddSubscriber(Report report, int userId) { if (report == null) { throw new EntityNotFoundException("Report not found"); } if (report.CreatorId == userId || report.AssigneeId == userId) { throw new DuplicateException("This user is already member of that report"); } if (await database.ReportSubscriberRepository.Find(new SqlBuilder().Append("reportId").Equals .Append($"'{report.Id}'") .And.Append("userId").Equals.Append(userId).Build().Query) != null) { throw new DuplicateException("This user is already member of that report"); } var reportSubscriber = ReportSubscriber.Create(report.Id, userId); return(await database.ReportSubscriberRepository.Insert(reportSubscriber, false) ? reportSubscriber : throw new DatabaseException()); }
public void SetUp() { request = new AddReportSubscriberRequest { UserId = UserId }; report = new Report(); reportSubscriber = new ReportSubscriber(); reportSubscriberService = new Mock <IReportSubscriberService>(); reportValidationHub = new Mock <IReportValidationHub>(); reportManager = new Mock <IReportManager>(); httpContextReader = new Mock <IHttpContextReader>(); var notifier = new Mock <INotifier>(); var hubManager = new Mock <IHubManager <NotifierHub> >(); mapper = new Mock <IMapper>(); reportSubscriberService.Setup(rss => rss.AddSubscriber(report, UserId)) .ReturnsAsync(reportSubscriber); reportValidationHub.Setup(rvh => rvh.ValidateAndReturnReport(It.IsAny <string>(), It.IsAny <ReportPermission[]>())) .ReturnsAsync(report); reportManager.Setup(rm => rm.ChangeStatus(It.IsAny <ReportStatusType>(), report)).ReturnsAsync(true); httpContextReader.Setup(htc => htc.CurrentUserId).Returns(UserId); addReportSubscriberCommand = new AddReportSubscriberCommand(reportSubscriberService.Object, reportValidationHub.Object, reportManager.Object, httpContextReader.Object, notifier.Object, hubManager.Object, mapper.Object); }
public async Task IsUserReportMember_UserIsSubscriber_ReturnTrue() { rolesService.Setup(r => r.IsPermitted(UserId, Constants.AllOwnersRoles)) .ReturnsAsync(false); report.ReportSubscribers.Add(ReportSubscriber.Create(It.IsNotNull <string>(), UserId)); var result = await reportValidationService.IsUserReportMember(UserId, report); Assert.That(result, Is.True); }