public void PatchJobProfileSocNullTest() { //Asserts Func <Task> f = async() => { await CurrentOpportunitiesSegmentService.PatchJobProfileSocAsync(null, testGuid).ConfigureAwait(false); }; f.Should().Throw <ArgumentNullException>(); }
public async Task ApprenticeshipStandardsPatchTest(MessageAction messageAction) { var elementId = Guid.NewGuid(); //Arrange var patchApprenticeshipStandardsModel = new PatchApprenticeshipStandardsModel() { ActionType = messageAction, Id = elementId }; currentOpportunitiesSegmentModel.Data.Apprenticeships = new Apprenticeships() { Standards = new List <Data.Models.ApprenticeshipStandard>(), }; currentOpportunitiesSegmentModel.Data.Apprenticeships.Standards.Add(new Data.Models.ApprenticeshipStandard() { Id = elementId }); A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(HttpStatusCode.OK); //Act var result = await CurrentOpportunitiesSegmentService.PatchApprenticeshipStandardsAsync(patchApprenticeshipStandardsModel, testGuid).ConfigureAwait(false); //Asserts A.CallTo(() => FakeCurrentOpportunitiesSegmentUtilities.GetReturnStatusForNullElementPatchRequest(A <MessageAction> .Ignored)).MustNotHaveHappened(); result.Should().Be(HttpStatusCode.OK); }
public SegmentServiceBaseTests() { FakeRepository = A.Fake <ICosmosRepository <CurrentOpportunitiesSegmentModel> >(); FakeCourseCurrentOpportunitiesRefresh = A.Fake <ICourseCurrentOpportunitiesRefresh>(); FakeAVCurrentOpportunatiesRefresh = A.Fake <IAVCurrentOpportunitiesRefresh>(); FakeLogger = A.Fake <ILogger <CurrentOpportunitiesSegmentService> >(); FakeMapper = A.Fake <IMapper>(); FakeJobProfileSegmentRefreshService = A.Fake <IJobProfileSegmentRefreshService <RefreshJobProfileSegmentServiceBusModel> >(); FakeCurrentOpportunitiesSegmentUtilities = A.Fake <ICurrentOpportunitiesSegmentUtilities>(); CurrentOpportunitiesSegmentService = new CurrentOpportunitiesSegmentService(FakeRepository, FakeCourseCurrentOpportunitiesRefresh, FakeAVCurrentOpportunatiesRefresh, FakeLogger, FakeMapper, FakeJobProfileSegmentRefreshService, FakeCurrentOpportunitiesSegmentUtilities); }
public async Task SegmentServiceGetByNameReturnsNullWhenMissingInRepository() { // arrange CurrentOpportunitiesSegmentModel expectedResult = null; A.CallTo(() => FakeRepository.GetAsync(A <Expression <Func <CurrentOpportunitiesSegmentModel, bool> > > .Ignored)).Returns(expectedResult); // act var result = await CurrentOpportunitiesSegmentService.GetByNameAsync("article-name").ConfigureAwait(false); // assert A.CallTo(() => FakeRepository.GetAsync(A <Expression <Func <CurrentOpportunitiesSegmentModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task SegmentServiceGetAllListReturnsNullWhenMissingRepository() { // arrange IEnumerable <CurrentOpportunitiesSegmentModel> expectedResults = null; A.CallTo(() => FakeRepository.GetAllAsync()).Returns(expectedResults); // act var results = await CurrentOpportunitiesSegmentService.GetAllAsync().ConfigureAwait(false); // assert A.CallTo(() => FakeRepository.GetAllAsync()).MustHaveHappenedOnceExactly(); A.Equals(results, expectedResults); }
public async Task SegmentServiceGetAllListReturnsSuccess() { // arrange var expectedResults = A.CollectionOfFake <CurrentOpportunitiesSegmentModel>(2); A.CallTo(() => FakeRepository.GetAllAsync()).Returns(expectedResults); // act var results = await CurrentOpportunitiesSegmentService.GetAllAsync().ConfigureAwait(false); // assert A.CallTo(() => FakeRepository.GetAllAsync()).MustHaveHappenedOnceExactly(); A.Equals(results, expectedResults); }
public async Task CareerPathSegmentServicePingReturnsFalseWhenMissingRepository() { // arrange var expectedResult = false; A.CallTo(() => FakeRepository.PingAsync()).Returns(expectedResult); // act var result = await CurrentOpportunitiesSegmentService.PingAsync().ConfigureAwait(false); // assert A.CallTo(() => FakeRepository.PingAsync()).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task RefreshJobProfileMessageNotSentWhenCourseAndAVServiceFails() { // arrange var currentOpportunitiesSegmentModel = A.Fake <CurrentOpportunitiesSegmentModel>(); A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(HttpStatusCode.OK); A.CallTo(() => FakeAVCurrentOpportunatiesRefresh.RefreshApprenticeshipVacanciesAsync(currentOpportunitiesSegmentModel.DocumentId)).Throws(new HttpRequestException()); A.CallTo(() => FakeCourseCurrentOpportunitiesRefresh.RefreshCoursesAsync(currentOpportunitiesSegmentModel.DocumentId)).Throws(new HttpRequestException()); // act var result = await CurrentOpportunitiesSegmentService.UpsertAsync(currentOpportunitiesSegmentModel).ConfigureAwait(false); // asserts A.CallTo(() => FakeJobProfileSegmentRefreshService.SendMessageAsync(A <RefreshJobProfileSegmentServiceBusModel> .Ignored)).MustNotHaveHappened(); }
public void GetCurrentHealthStatusAsyncExceptionTestAsync() { //Arrange var repository = A.Fake <ICosmosRepository <CurrentOpportunitiesSegmentModel> >(); var dummyHealthCheckContext = A.Dummy <HealthCheckContext>(); A.CallTo(() => repository.PingAsync()).Throws(new ApplicationException()); var currentOpportunitiesSegmentService = new CurrentOpportunitiesSegmentService(repository, fakeCourseCurrentOpportunitiesRefresh, fakeIAVCurrentOpportunatiesRefresh, fakeLogger, fakeMapper, fakeJobProfileSegmentRefreshService, fakeCurrentOpportunitiesSegmentUtilities); //Act Func <Task> serviceHealthStatus = async() => await currentOpportunitiesSegmentService.CheckHealthAsync(dummyHealthCheckContext).ConfigureAwait(false); //Asserts serviceHealthStatus.Should().Throw <Exception>(); }
public async Task GetCurrentHealthStatusAsyncTestAsync(bool isHealthyResponse, HealthStatus expectedStatus) { // arrange var dummyHealthCheckContext = A.Dummy <HealthCheckContext>(); A.CallTo(() => fakeRepository.PingAsync()).Returns(isHealthyResponse); var currentOpportunitiesSegmentService = new CurrentOpportunitiesSegmentService(fakeRepository, fakeCourseCurrentOpportunitiesRefresh, fakeIAVCurrentOpportunatiesRefresh, fakeLogger, fakeMapper, fakeJobProfileSegmentRefreshService, fakeCurrentOpportunitiesSegmentUtilities); //Act var serviceHealthStatus = await currentOpportunitiesSegmentService.CheckHealthAsync(dummyHealthCheckContext).ConfigureAwait(false); //Asserts serviceHealthStatus.Status.Should().Be(expectedStatus); A.CallTo(() => fakeRepository.PingAsync()).MustHaveHappenedOnceExactly(); }
public async Task CareerPathSegmentServiceDeleteReturnsNullWhenSegmentNotDeleted() { // arrange Guid documentId = Guid.NewGuid(); var expectedResult = false; A.CallTo(() => FakeRepository.DeleteAsync(documentId)).Returns(HttpStatusCode.BadRequest); // act var result = await CurrentOpportunitiesSegmentService.DeleteAsync(documentId).ConfigureAwait(false); // assert A.CallTo(() => FakeRepository.DeleteAsync(documentId)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task SegmentServiceGetByIdReturnsSuccess() { // arrange Guid documentId = Guid.NewGuid(); var expectedResult = A.Fake <CurrentOpportunitiesSegmentModel>(); A.CallTo(() => FakeRepository.GetAsync(A <Expression <Func <CurrentOpportunitiesSegmentModel, bool> > > .Ignored)).Returns(expectedResult); // act var result = await CurrentOpportunitiesSegmentService.GetByIdAsync(documentId).ConfigureAwait(false); // assert A.CallTo(() => FakeRepository.GetAsync(A <Expression <Func <CurrentOpportunitiesSegmentModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task CurrentOpportunitiesSegementServiceCreateReturnsCreatedWhenSegmentCreated() { // arrange var currentOpportunitiesSegmentModel = A.Fake <CurrentOpportunitiesSegmentModel>(); var expectedResult = HttpStatusCode.Created; A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(HttpStatusCode.Created); // act var result = await CurrentOpportunitiesSegmentService.UpsertAsync(currentOpportunitiesSegmentModel).ConfigureAwait(false); // assert A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task JobProfileSocPatchDeleteApprentishipNullTest() { //Arrange var patchJobProfileSocModel = new PatchJobProfileSocModel() { ActionType = MessageAction.Deleted }; A.CallTo(() => FakeCurrentOpportunitiesSegmentUtilities.GetReturnStatusForNullElementPatchRequest(A <MessageAction> .Ignored)).Returns(HttpStatusCode.AlreadyReported); //Act var result = await CurrentOpportunitiesSegmentService.PatchJobProfileSocAsync(patchJobProfileSocModel, testGuid).ConfigureAwait(false); //Asserts result.Should().Be(HttpStatusCode.AlreadyReported); }
public async Task CareerPathSegmentServiceDeleteReturnsFalseWhenMissingRepository() { // arrange Guid documentId = Guid.NewGuid(); var careerPathSegmentModel = A.Fake <CurrentOpportunitiesSegmentModel>(); var expectedResult = false; A.CallTo(() => FakeRepository.DeleteAsync(documentId)).Returns(HttpStatusCode.FailedDependency); // act var result = await CurrentOpportunitiesSegmentService.DeleteAsync(documentId).ConfigureAwait(false); // assert A.CallTo(() => FakeRepository.DeleteAsync(documentId)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task CurrentOpportunitiesSegmentServiceCreateReturnsNullWhenMissingRepository() { // arrange var currentOpportunitiesSegmentModel = A.Fake <CurrentOpportunitiesSegmentModel>(); var expectedResult = A.Dummy <CurrentOpportunitiesSegmentModel>(); A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(HttpStatusCode.FailedDependency); // act var result = await CurrentOpportunitiesSegmentService.UpsertAsync(currentOpportunitiesSegmentModel).ConfigureAwait(false); // assert A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeRepository.GetAsync(A <Expression <Func <CurrentOpportunitiesSegmentModel, bool> > > .Ignored)).MustNotHaveHappened(); A.Equals(result, expectedResult); }
public async Task JobProfileSocPatchApprentishipTest(MessageAction messageAction) { //Arrange var patchJobProfileSocModel = new PatchJobProfileSocModel() { ActionType = messageAction }; currentOpportunitiesSegmentModel.Data.Apprenticeships = new Apprenticeships(); A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(HttpStatusCode.OK); //Act var result = await CurrentOpportunitiesSegmentService.PatchJobProfileSocAsync(patchJobProfileSocModel, testGuid).ConfigureAwait(false); //Asserts A.CallTo(() => FakeCurrentOpportunitiesSegmentUtilities.GetReturnStatusForNullElementPatchRequest(A <MessageAction> .Ignored)).MustNotHaveHappened(); result.Should().Be(HttpStatusCode.OK); }
public async Task JobProfileSocPatchSocReturnsNotFoundForMissingSegment() { //Arrange var doNotPatchResult = new CurrentOpportunitiesSegmentPatchStatus() { OkToPatch = false, ReturnStatusCode = HttpStatusCode.NotFound }; var patchJobProfileSocModel = new PatchJobProfileSocModel() { ActionType = MessageAction.Deleted }; A.CallTo(() => FakeRepository.GetAsync(A <Expression <Func <CurrentOpportunitiesSegmentModel, bool> > > .Ignored)).Returns(null as CurrentOpportunitiesSegmentModel); A.CallTo(() => FakeCurrentOpportunitiesSegmentUtilities.IsSegementOkToPatch(A <CurrentOpportunitiesSegmentModel> .Ignored, A <long> .Ignored)).Returns(doNotPatchResult); //Act var result = await CurrentOpportunitiesSegmentService.PatchJobProfileSocAsync(patchJobProfileSocModel, testGuid).ConfigureAwait(false); //Asserts result.Should().Be(HttpStatusCode.NotFound); }
public async Task CurrentOpportunitiesSegmentServiceUpdateCoursesAndAppreticeshipsWhenUpserted(HttpStatusCode upsertReturnCode, bool shouldRefresh) { // arrange var currentOpportunitiesSegmentModel = A.Fake <CurrentOpportunitiesSegmentModel>(); A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(upsertReturnCode); // act var result = await CurrentOpportunitiesSegmentService.UpsertAsync(currentOpportunitiesSegmentModel).ConfigureAwait(false); // assert A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).MustHaveHappenedOnceExactly(); if (shouldRefresh) { A.CallTo(() => FakeCourseCurrentOpportunitiesRefresh.RefreshCoursesAsync(A <Guid> .Ignored)).MustHaveHappened(); A.CallTo(() => FakeAVCurrentOpportunatiesRefresh.RefreshApprenticeshipVacanciesAsync(A <Guid> .Ignored)).MustHaveHappened(); } else { A.CallTo(() => FakeCourseCurrentOpportunitiesRefresh.RefreshCoursesAsync(A <Guid> .Ignored)).MustNotHaveHappened(); A.CallTo(() => FakeAVCurrentOpportunatiesRefresh.RefreshApprenticeshipVacanciesAsync(A <Guid> .Ignored)).MustNotHaveHappened(); } }
public async Task CurrentOpportunitiesSegmentServiceCreateReturnsArgumentNullExceptionWhenNullIsUsedAsync() { // arrange // act var exceptionResult = await Assert.ThrowsAsync <ArgumentNullException>(async() => await CurrentOpportunitiesSegmentService.UpsertAsync(null).ConfigureAwait(false)).ConfigureAwait(false); // assert Assert.Equal("Value cannot be null. (Parameter 'currentOpportunitiesSegmentModel')", exceptionResult.Message); }