public async Task PatchUniformReturnsArgumentNullExceptionWhenModelIsNull() { // Arrange var segmentService = new JobProfileTasksSegmentService(repository, mapper, jobProfileSegmentRefreshService); // Act await Assert.ThrowsAsync <ArgumentNullException>(async() => await segmentService.PatchUniformAsync(null, Guid.NewGuid()).ConfigureAwait(false)).ConfigureAwait(false); }
public async Task PatchUniformReturnsNotFoundWhenDataDoesNotExist() { // Arrange var fakeRepository = A.Fake <ICosmosRepository <JobProfileTasksSegmentModel> >(); A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).Returns((JobProfileTasksSegmentModel)null); var segmentService = new JobProfileTasksSegmentService(fakeRepository, mapper, jobProfileSegmentRefreshService); // Act var result = await segmentService.PatchUniformAsync(GetPatchUniformModel(), jobProfileId).ConfigureAwait(false); // Assert A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); Assert.Equal(HttpStatusCode.NotFound, result); }
public async Task PatchUniformReturnsAlreadyReportedWhenExistingSequenceNumberIsHigher() { // Arrange var existingModel = GetJobProfileTasksSegmentModel(999); var fakeRepository = A.Fake <ICosmosRepository <JobProfileTasksSegmentModel> >(); A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).Returns(existingModel); var segmentService = new JobProfileTasksSegmentService(fakeRepository, mapper, jobProfileSegmentRefreshService); // Act var result = await segmentService.PatchUniformAsync(GetPatchUniformModel(), jobProfileId).ConfigureAwait(false); // Assert A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); Assert.Equal(HttpStatusCode.AlreadyReported, result); }
public async Task PatchUniformReturnsAlreadyReportedWhenMessageActionIsDeletedAndDataDoesNotExist() { // Arrange var existingModel = GetJobProfileTasksSegmentModel(); var patchModel = GetPatchUniformModel(MessageActionType.Deleted, Guid.NewGuid()); var fakeRepository = A.Fake <ICosmosRepository <JobProfileTasksSegmentModel> >(); A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).Returns(existingModel); var segmentService = new JobProfileTasksSegmentService(fakeRepository, mapper, jobProfileSegmentRefreshService); // Act var result = await segmentService.PatchUniformAsync(patchModel, jobProfileId).ConfigureAwait(false); // Assert A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); Assert.Equal(HttpStatusCode.AlreadyReported, result); }
public async Task PatchUniformReturnsSuccessWhenMessageActionIsDeleted() { // Arrange var model = GetPatchUniformModel(MessageActionType.Deleted); var existingModel = GetJobProfileTasksSegmentModel(); var fakeRepository = A.Fake <ICosmosRepository <JobProfileTasksSegmentModel> >(); A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).Returns(existingModel); A.CallTo(() => fakeRepository.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).Returns(HttpStatusCode.OK); var segmentService = new JobProfileTasksSegmentService(fakeRepository, mapper, jobProfileSegmentRefreshService); // Act var result = await segmentService.PatchUniformAsync(model, jobProfileId).ConfigureAwait(false); // Assert A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeRepository.UpsertAsync(A <JobProfileTasksSegmentModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => jobProfileSegmentRefreshService.SendMessageAsync(A <RefreshJobProfileSegmentServiceBusModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => mapper.Map <Uniform>(A <PatchUniformModel> .Ignored)).MustNotHaveHappened(); Assert.Equal(HttpStatusCode.OK, result); }