public async Task PatchLocationReturnsArgumentNullExceptionWhenModelIsNull()
        {
            // Arrange
            var segmentService = new JobProfileTasksSegmentService(repository, mapper, jobProfileSegmentRefreshService);

            // Act
            await Assert.ThrowsAsync <ArgumentNullException>(async() => await segmentService.PatchLocationAsync(null, Guid.NewGuid()).ConfigureAwait(false)).ConfigureAwait(false);
        }
        public async Task PatchLocationReturnsNotFoundWhenDataDoesNotExist()
        {
            // 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.PatchLocationAsync(GetPatchLocationModel(), jobProfileId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal(HttpStatusCode.NotFound, result);
        }
        public async Task PatchLocationReturnsAlreadyReportedWhenExistingSequenceNumberIsHigher()
        {
            // 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.PatchLocationAsync(GetPatchLocationModel(), jobProfileId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal(HttpStatusCode.AlreadyReported, result);
        }
        public async Task PatchLocationReturnsAlreadyReportedWhenMessageActionIsDeletedAndDataDoesNotExist()
        {
            // Arrange
            var existingModel = GetJobProfileTasksSegmentModel();
            var patchModel    = GetPatchLocationModel(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.PatchLocationAsync(patchModel, jobProfileId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeRepository.GetAsync(A <Expression <Func <JobProfileTasksSegmentModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal(HttpStatusCode.AlreadyReported, result);
        }
        public async Task PatchLocationReturnsSuccessWhenMessageActionIsDeleted()
        {
            // Arrange
            var model         = GetPatchLocationModel(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.PatchLocationAsync(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 <Location>(A <PatchLocationModel> .Ignored)).MustNotHaveHappened();
            Assert.Equal(HttpStatusCode.OK, result);
        }