public async Task SaveAsync_DeleteIfDtoIsDeleted() { var repoMock = MocksCreator.RepoRecurrence(); var service = new RecurrenceService(repoMock.Object, Mapper, _specFactoryMock.Object); await service.SaveAsync(new[] { new PlannedRecurrenceDto { Uid = "42", IsDeleted = true } }, null); repoMock.Verify(x => x.DeleteAsync("42")); repoMock.Verify(x => x.AnyAsync(It.IsAny <IPlannedRecurrenceSpecification>())); repoMock.VerifyNoOtherCalls(); }
public async Task SaveAsync_CheckIsUserCanEdit() { var repoMock = MocksCreator.RepoRecurrence(new PlannedRecurrenceEntity { UserId = "other", Uid = "1" }); repoMock.Setup(x => x.AnyAsync(It.IsAny <IPlannedRecurrenceSpecification>())) .Returns(Task.FromResult(true)); var service = new RecurrenceService(repoMock.Object, Mapper, _specFactoryMock.Object); var list = new PlannedRecurrenceDto[] { new() { Uid = "1" } }; var userId = "userid"; await Assert.ThrowsAsync <ServiceException>(() => service.SaveAsync(list, userId)); }
public async Task SaveAsync_CreateNewIfNoSuchUid() { var repoMock = MocksCreator.RepoRecurrence(); var service = new RecurrenceService(repoMock.Object, Mapper, _specFactoryMock.Object); await service.SaveAsync(new[] { new PlannedRecurrenceDto { Uid = "42", Task = "42" } }, "userid1"); repoMock.Verify(x => x.UpsertAsync(It.Is <PlannedRecurrenceEntity>(y => y.Uid == "42" && y.Task == "42" && y.UserId == "userid1"))); repoMock.Verify(x => x.AnyAsync(It.IsAny <IPlannedRecurrenceSpecification>())); repoMock.Verify(x => x.GetByIdAsync("42")); repoMock.VerifyNoOtherCalls(); }