public async Task UpdateAppRegistrationAsyncReturnsExceptionForNullAppRegistrationModel() { // Arrange AppRegistrationModel?dummyAppRegistrationModel = null; // Act var exceptionResult = await Assert.ThrowsAsync <ArgumentNullException>(async() => await dataLoadService.UpdateAppRegistrationAsync(dummyAppRegistrationModel).ConfigureAwait(false)).ConfigureAwait(false); // assert A.CallTo(() => fakeModelValidationService.ValidateModel(A <AppRegistrationModel> .Ignored)).MustNotHaveHappened(); A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).MustNotHaveHappened(); Assert.Equal("Value cannot be null. (Parameter 'appRegistrationModel')", exceptionResult.Message); }
public async Task UpdateAppRegistrationAsync(AppRegistrationModel appRegistrationModel) { _ = appRegistrationModel ?? throw new ArgumentNullException(nameof(appRegistrationModel)); logger.LogInformation($"Upserting App Registration: {JsonConvert.SerializeObject(appRegistrationModel)}"); if (modelValidationService.ValidateModel(appRegistrationModel)) { var upsertResult = await documentService.UpsertAsync(appRegistrationModel).ConfigureAwait(false); if (upsertResult == HttpStatusCode.OK || upsertResult == HttpStatusCode.Created) { logger.LogInformation($"Upserted app registration: {appRegistrationModel.Path}: Status code: {upsertResult}"); } else { logger.LogError($"Failed to upsert app registration: {appRegistrationModel.Path}: Status code: {upsertResult}"); } } }
public async Task ProcessPathAsyncUpsertIsSuccessful() { // Arrange const HttpStatusCode upsertResult = HttpStatusCode.OK; const bool validationResult = true; var validLegacyPathModel = ModelBuilders.ValidLegacyPathModel(ModelBuilders.PathName); var validLegacyRegionModels = ModelBuilders.ValidLegacyRegionModels(); var validAppRegistrationModels = ModelBuilders.ValidAppRegistrationModels(ModelBuilders.PathName); A.CallTo(() => fakeLegacyRegionService.GetListAsync(A <string> .Ignored)).Returns(validLegacyRegionModels); A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).Returns(validAppRegistrationModels); A.CallTo(() => fakeModelMappingService.MapModels(A <AppRegistrationModel> .Ignored, A <LegacyPathModel> .Ignored, A <List <LegacyRegionModel> > .Ignored)); A.CallTo(() => fakeModelValidationService.ValidateModel(A <AppRegistrationModel> .Ignored)).Returns(validationResult); A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).Returns(upsertResult); // Act await legacyDataLoadService.ProcessPathAsync(validLegacyPathModel).ConfigureAwait(false); // Assert A.CallTo(() => fakeLegacyRegionService.GetListAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeModelMappingService.MapModels(A <AppRegistrationModel> .Ignored, A <LegacyPathModel> .Ignored, A <List <LegacyRegionModel> > .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeModelValidationService.ValidateModel(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly(); }