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();
        }
Example #2
0
        public void MapModelsPairIsSuccessful()
        {
            // Arrange
            var appRegistrationModel = ModelBuilders.ValidAppRegistrationModel(ModelBuilders.PathName);
            var legacyPathModel      = ModelBuilders.ValidLegacyPathModel(ModelBuilders.PathName);

            // Act
            modelMappingService.MapModels(appRegistrationModel, legacyPathModel);

            // assert
            A.CallTo(() => fakeMapper.Map(legacyPathModel, appRegistrationModel)).MustHaveHappenedOnceExactly();
        }
Example #3
0
        public async Task PathsCosmosDbTriggerWhenExecutedThrowsException()
        {
            A.CallTo(() => legacyDataLoadService.UpdatePathAsync(A <LegacyPathModel> .Ignored)).ThrowsAsync(new HttpRequestException());

            // Arrange
            var function = new PathsCosmosDbTrigger(logger, legacyDataLoadService);

            // Act
            // Assert
            await Assert.ThrowsAsync <HttpRequestException>(() => function.Run(new List <Document> {
                ModelBuilders.ValidLegacyPathModel(ModelBuilders.PathName)
            })).ConfigureAwait(false);
        }
Example #4
0
        public async Task PathsCosmosDbTriggerWhenExecutedUpdatesPath()
        {
            // Arrange
            var function = new PathsCosmosDbTrigger(logger, legacyDataLoadService);

            // Act
            await function.Run(new List <Document> {
                ModelBuilders.ValidLegacyPathModel(ModelBuilders.PathName)
            }).ConfigureAwait(false);

            // Assert
            A.CallTo(() => legacyDataLoadService.UpdatePathAsync(A <LegacyPathModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
Example #5
0
        public void MapModelsPairReturnsExceptionForNullAppRegistrationModel()
        {
            // Arrange
            AppRegistrationModel?appRegistrationModel = null;
            var legacyPathModel = ModelBuilders.ValidLegacyPathModel(ModelBuilders.PathName);

            // Act
            var exceptionResult = Assert.Throws <ArgumentNullException>(() => modelMappingService.MapModels(appRegistrationModel, legacyPathModel));

            // assert
            A.CallTo(() => fakeMapper.Map(legacyPathModel, appRegistrationModel)).MustNotHaveHappened();

            Assert.Equal("Value cannot be null. (Parameter 'appRegistrationModel')", exceptionResult.Message);
        }
        public async Task UpdatePathAsyncAppRegistrationNullCreatesNew()
        {
            // Arrange
            const HttpStatusCode upsertResult     = HttpStatusCode.OK;
            const bool           validationResult = true;
            var validLegacyPathModel = ModelBuilders.ValidLegacyPathModel(ModelBuilders.PathName);

            A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).Returns <IEnumerable <AppRegistrationModel>?>(null);
            A.CallTo(() => fakeModelValidationService.ValidateModel(A <AppRegistrationModel> .Ignored)).Returns(validationResult);
            A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).Returns(upsertResult);

            // Act
            await legacyDataLoadService.UpdatePathAsync(validLegacyPathModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeModelValidationService.ValidateModel(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
Example #7
0
        public void MapModelsReturnsSuccessForValidDataModelsWithoutLegacyRegions()
        {
            // Arrange
            var appRegistrationModel = ModelBuilders.ValidAppRegistrationModel(ModelBuilders.PathName);
            var legacyPathModel      = ModelBuilders.ValidLegacyPathModel(ModelBuilders.PathName);
            IList <LegacyRegionModel>?legacyRegionModels = null;
            var validRegionModels = ModelBuilders.ValidRegionModels();

            A.CallTo(() => fakeMapper.Map(legacyPathModel, appRegistrationModel));
            A.CallTo(() => fakeMapper.Map <List <RegionModel> >(legacyRegionModels)).Returns(validRegionModels);

            // Act
            modelMappingService.MapModels(appRegistrationModel, legacyPathModel, legacyRegionModels);

            // assert
            A.CallTo(() => fakeMapper.Map(legacyPathModel, appRegistrationModel)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeMapper.Map <List <RegionModel> >(legacyRegionModels)).MustNotHaveHappened();

            Assert.Null(appRegistrationModel.Regions);
        }
        public async Task ProcessPathAsyncFailsValidation()
        {
            // Arrange
            const bool validationResult           = false;
            var        validLegacyPathModel       = ModelBuilders.ValidLegacyPathModel(ModelBuilders.PathName);
            var        invalidLegacyRegionModels  = A.CollectionOfDummy <LegacyRegionModel>(2);
            var        validAppRegistrationModels = ModelBuilders.ValidAppRegistrationModels(ModelBuilders.PathName);

            A.CallTo(() => fakeLegacyRegionService.GetListAsync(A <string> .Ignored)).Returns(invalidLegacyRegionModels);
            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);

            // 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)).MustNotHaveHappened();
        }