Example #1
0
        public async Task RegionsCosmosDbTriggerWhenExecutedThrowsException()
        {
            A.CallTo(() => legacyDataLoadService.UpdateRegionAsync(A <LegacyRegionModel> .Ignored)).ThrowsAsync(new HttpRequestException());

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

            // Act
            // Assert
            await Assert.ThrowsAsync <HttpRequestException>(() => function.Run(new List <Document> {
                ModelBuilders.ValidLegacyRegionModel(ModelBuilders.PathName, Enums.PageRegion.Head)
            })).ConfigureAwait(false);
        }
Example #2
0
        public async Task RegionsCosmosDbTriggerWhenExecutedUpdatesRegion()
        {
            // Arrange
            var function = new RegionsCosmosDbTrigger(logger, legacyDataLoadService);

            // Act
            await function.Run(new List <Document> {
                ModelBuilders.ValidLegacyRegionModel(ModelBuilders.PathName, Enums.PageRegion.Head)
            }).ConfigureAwait(false);

            // Assert
            A.CallTo(() => legacyDataLoadService.UpdateRegionAsync(A <LegacyRegionModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
Example #3
0
        public void MapRegionModelToAppRegistrationReturnsExceptionForNullAppRegistrationModel()
        {
            // Arrange
            AppRegistrationModel?appRegistrationModel = null;
            var legacyRegionModel = ModelBuilders.ValidLegacyRegionModel(ModelBuilders.PathName, Enums.PageRegion.Head);

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

            // Assert
            A.CallTo(() => fakeMapper.Map <RegionModel>(legacyRegionModel)).MustNotHaveHappened();

            Assert.Equal("Value cannot be null. (Parameter 'appRegistrationModel')", exceptionResult.Message);
        }
Example #4
0
        public void MapRegionModelToAppRegistrationNoExistingRegionsReturnsSuccessForValidDataModelsWithLegacyRegions()
        {
            // Arrange
            var appRegistrationModel = ModelBuilders.ValidAppRegistrationModel(ModelBuilders.PathName);

            var legacyRegionModel = ModelBuilders.ValidLegacyRegionModel(ModelBuilders.PathName, Enums.PageRegion.Head);
            var validRegionModel  = ModelBuilders.ValidRegionModel(Enums.PageRegion.Head);

            A.CallTo(() => fakeMapper.Map <RegionModel>(legacyRegionModel));

            // Act
            modelMappingService.MapRegionModelToAppRegistration(appRegistrationModel, legacyRegionModel);

            // assert
            A.CallTo(() => fakeMapper.Map <RegionModel>(legacyRegionModel)).MustHaveHappenedOnceExactly();

            Assert.NotNull(appRegistrationModel.Regions);
        }
        public async Task UpdateRegionAsyncAppRegistrationNullNoUpdate()
        {
            // Arrange
            const HttpStatusCode upsertResult     = HttpStatusCode.OK;
            const bool           validationResult = true;
            var validLegacyRegionModel            = ModelBuilders.ValidLegacyRegionModel(ModelBuilders.PathName, Enums.PageRegion.Head);

            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.UpdateRegionAsync(validLegacyRegionModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeDocumentService.GetAsync(A <Expression <Func <AppRegistrationModel, bool> > > .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeModelValidationService.ValidateModel(A <AppRegistrationModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).MustNotHaveHappened();
        }