Example #1
0
        internal static async Task <ModelTypeAndContextModel> ValidateModelAndGetEFMetadata(
            CommonCommandLineModel commandLineModel,
            IEntityFrameworkService entityFrameworkService,
            IModelTypesLocator modelTypesLocator,
            string areaName)
        {
            ModelType model       = ValidationUtil.ValidateType(commandLineModel.ModelClass, "model", modelTypesLocator);
            ModelType dataContext = ValidationUtil.ValidateType(commandLineModel.DataContextClass, "dataContext", modelTypesLocator, throwWhenNotFound: false);

            // Validation successful
            Contract.Assert(model != null, MessageStrings.ValidationSuccessfull_modelUnset);

            var dbContextFullName = dataContext != null ? dataContext.FullName : commandLineModel.DataContextClass;

            var modelMetadata = await entityFrameworkService.GetModelMetadata(
                dbContextFullName,
                model,
                areaName);

            return(new ModelTypeAndContextModel()
            {
                ModelType = model,
                DbContextFullName = dbContextFullName,
                ContextProcessingResult = modelMetadata
            });
        }
Example #2
0
        public async void TestValidateModelAndGetCodeModelMetadata()
        {
            var modelTypes = new List <ModelType>();

            //Arrange
            model = new TestCommandLineModel()
            {
                ModelClass = "InvalidModel"
            };
            modelTypesLocator.Setup(m => m.GetType("InvalidModel")).Returns(() => { return(modelTypes); });

            //Act & Assert
            Exception ex = await Assert.ThrowsAsync <ArgumentException>(
                async() => await ModelMetadataUtilities.ValidateModelAndGetCodeModelMetadata(
                    model,
                    codeModelService.Object,
                    modelTypesLocator.Object));

            Assert.Equal("A type with the name InvalidModel does not exist", ex.Message);

            // Arrange
            var modelType = new ModelType()
            {
                Name      = "InvalidModel",
                FullName  = "InvalidModel",
                Namespace = ""
            };

            modelTypes.Add(modelType);
            var contextProcessingResult = new ContextProcessingResult()
            {
                ContextProcessingStatus = ContextProcessingStatus.ContextAdded,
                ModelMetadata           = null
            };

            codeModelService.Setup(e => e.GetModelMetadata(modelType))
            .Returns(Task.FromResult(contextProcessingResult));

            //Act
            var result = await ModelMetadataUtilities.ValidateModelAndGetCodeModelMetadata(
                model,
                codeModelService.Object,
                modelTypesLocator.Object);

            //Assert
            Assert.Equal(contextProcessingResult.ContextProcessingStatus, result.ContextProcessingResult.ContextProcessingStatus);
            Assert.Equal(modelType, result.ModelType);
        }
Example #3
0
        internal static async Task <ModelTypeAndContextModel> ValidateModelAndGetCodeModelMetadata(
            CommonCommandLineModel commandLineModel,
            IEntityFrameworkService entityFrameworkService,
            IModelTypesLocator modelTypesLocator)
        {
            ModelType model = ValidationUtil.ValidateType(commandLineModel.ModelClass, "model", modelTypesLocator);

            Contract.Assert(model != null, MessageStrings.ValidationSuccessfull_modelUnset);
            var result = await entityFrameworkService.GetModelMetadata(model);

            return(new ModelTypeAndContextModel()
            {
                ModelType = model,
                ContextProcessingResult = result
            });
        }
Example #4
0
        // Todo: This method is duplicated with the ControllerWithContext generator.
        private async Task <ModelTypeAndContextModel> ValidateModelAndGetMetadata(CommonCommandLineModel commandLineModel)
        {
            ModelType model       = ValidationUtil.ValidateType(commandLineModel.ModelClass, "model", _modelTypesLocator);
            ModelType dataContext = ValidationUtil.ValidateType(commandLineModel.DataContextClass, "dataContext", _modelTypesLocator, throwWhenNotFound: false);

            // Validation successful
            Contract.Assert(model != null, "Validation succeded but model type not set");

            var dbContextFullName = dataContext != null ? dataContext.FullName : commandLineModel.DataContextClass;

            var modelMetadata = await _entityFrameworkService.GetModelMetadata(
                dbContextFullName,
                model);

            return(new ModelTypeAndContextModel()
            {
                ModelType = model,
                DbContextFullName = dbContextFullName,
                ContextProcessingResult = modelMetadata
            });
        }
Example #5
0
        // Todo: This method is duplicated with the ControllerWithContext generator.
        private async Task<ModelTypeAndContextModel> ValidateModelAndGetMetadata(CommonCommandLineModel commandLineModel)
        {
            ModelType model = ValidationUtil.ValidateType(commandLineModel.ModelClass, "model", _modelTypesLocator);
            ModelType dataContext = ValidationUtil.ValidateType(commandLineModel.DataContextClass, "dataContext", _modelTypesLocator, throwWhenNotFound: false);

            // Validation successful
            Contract.Assert(model != null, CodeGenerators.Mvc.MessageStrings.ValidationSuccessfull_modelUnset);

            var dbContextFullName = dataContext != null ? dataContext.FullName : commandLineModel.DataContextClass;

            var modelMetadata = await _entityFrameworkService.GetModelMetadata(
                dbContextFullName,
                model);

            return new ModelTypeAndContextModel()
            {
                ModelType = model,
                DbContextFullName = dbContextFullName,
                ContextProcessingResult = modelMetadata
            };
        }