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 IActionResult Topics(int id)
        {
            var forum = _forumService.GetById(id);

            if (forum != null)
            {
                var topics = forum.Topics;

                var topicListings = topics.Select(topic => ModelBuilders.BuildTopicListing(topic))
                                    .OrderByDescending(topic => topic.LastPostCreated);

                var model = new ForumTopicModel
                {
                    Forum  = ModelBuilders.BuildForumListing(forum),
                    Topics = topicListings
                };

                if (TempData["TopicDeletedMessage"] != null)
                {
                    model.TopicDeletedMessage = TempData["TopicDeletedMessage"] as string;
                }

                return(View(model));
            }

            return(RedirectToAction("Index", "Forum"));
        }
Example #3
0
        public MainViewModel(RazorDocumentManager documentManager, ModelProviders modelProviders, ModelBuilders modelBuilders)
        {
            _documentManager = documentManager;
            _modelBuilders   = modelBuilders;
            _modelProviders  = modelProviders;

            Templates = new ObservableCollection <RazorTemplateViewModel>();

            RegisterCommands();
        }
        public async Task ProcessPathsAsyncIsSuccessfulWhenDataPresent()
        {
            // Arrange
            var validLegacyPathModels = ModelBuilders.ValidLegacyPathModels();

            // Act
            await legacyDataLoadService.ProcessPathsAsync(validLegacyPathModels).ConfigureAwait(false);

            // Assert
            Assert.True(true);
        }
Example #5
0
        public void ValidateModelReturnsSuccessForValidDataModels()
        {
            // Arrange
            const bool expectedResult       = true;
            var        appRegistrationModel = ModelBuilders.ValidAppRegistrationModel(ModelBuilders.PathName);

            // Act
            var result = modelValidationService.ValidateModel(appRegistrationModel);

            // assert
            Assert.Equal(expectedResult, result);
        }
Example #6
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 #7
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);
        }
        public async Task LoadAsyncIsSuccessfulWhenDataPresent()
        {
            // Arrange
            var validLegacyPathModels = ModelBuilders.ValidLegacyPathModels();

            A.CallTo(() => fakeLegacyPathService.GetListAsync()).Returns(validLegacyPathModels);

            // Act
            await legacyDataLoadService.LoadAsync().ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeLegacyPathService.GetListAsync()).MustHaveHappenedOnceExactly();
        }
Example #9
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 #10
0
        public void ValidateModelReturnsFailureForInvalidDataModels()
        {
            // Arrange
            const bool expectedResult       = false;
            var        appRegistrationModel = ModelBuilders.ValidAppRegistrationModel(ModelBuilders.PathName);

            appRegistrationModel.Path = null;

            // Act
            var result = modelValidationService.ValidateModel(appRegistrationModel);

            // assert
            Assert.Equal(expectedResult, result);
        }
Example #11
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 #12
0
        public void MapModelsPairReturnsExceptionForNullLegacyPathModel()
        {
            // Arrange
            var             appRegistrationModel = ModelBuilders.ValidAppRegistrationModel(ModelBuilders.PathName);
            LegacyPathModel?legacyPathModel      = null;

            // 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 'legacyPathModel')", exceptionResult.Message);
        }
Example #13
0
        public IActionResult Index()
        {
            var forums = _forumService.GetAll().Select(forum => ModelBuilders.BuildForumListing(forum));

            var model = new ForumIndexModel
            {
                ForumList = forums
            };

            if (TempData["ForumDeletedMessage"] != null)
            {
                model.ForumDeletedMessage = TempData["ForumDeletedMessage"] as string;
            }

            return(View(model));
        }
Example #14
0
        public IActionResult Results(string searchQuery)
        {
            var topics       = _topicService.GetFilteredTopics(searchQuery);
            var areNoResults = (!string.IsNullOrEmpty(searchQuery) && !topics.Any());

            var topicListings = topics.Select(topic => ModelBuilders.BuildTopicListing(topic));

            var model = new SearchResultModel
            {
                Topics             = topicListings,
                SearchQuery        = searchQuery,
                EmptySearchResults = areNoResults
            };

            return(View(model));
        }
        public async Task UpdateAppRegistrationAsyncAppRegistrationxxxxxxxxxxxxxxx()
        {
            // Arrange
            const HttpStatusCode upsertResult     = HttpStatusCode.OK;
            const bool           validationResult = true;
            var validAppRegistrationModel         = ModelBuilders.ValidAppRegistrationModel(ModelBuilders.PathName);

            A.CallTo(() => fakeModelValidationService.ValidateModel(A <AppRegistrationModel> .Ignored)).Returns(validationResult);
            A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).Returns(upsertResult);

            // Act
            await legacyDataLoadService.UpdateAppRegistrationAsync(validAppRegistrationModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => fakeModelValidationService.ValidateModel(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => fakeDocumentService.UpsertAsync(A <AppRegistrationModel> .Ignored)).MustHaveHappenedOnceExactly();
        }
        public RazorTemplateViewModel(RazorDocument document = null, ModelBuilders modelBuilderFactory = null, ModelProviders modelProviders = null)
        {
            _document             = document ?? new RazorDocument();
            _modelBuilderFactory  = modelBuilderFactory;
            _modelProviderFactory = modelProviders;
            _savedModels          = new Dictionary <Type, string>();

            var modelProviderNames = _modelProviderFactory.Providers.Select(x => (string)new ModelProviderFactoryName(x.Value));

            AvailableModelProviders = new ObservableCollection <string>(modelProviderNames);
            _selectedModelProvider  = new ModelProviderName(_document.ModelProvider);

            Errors           = new ObservableCollection <RazorPadError>();
            Messages         = new ObservableTextWriter();
            TemplateCompiler = new TemplateCompiler();

            AttachToModelProviderEvents(_document.ModelProvider);
        }
Example #17
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 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 #19
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();
        }
Example #21
0
 private static IModelBuilder CreateModelBuilder(string providerName)
 {
     return(ModelBuilders.GetModelBuilder(providerName));
 }