Beispiel #1
0
        public void Validate(CSharpCompilation compilation, CSharpSyntaxTree tree, SemanticModel model, Assembly assembly)
        {
            var className = "CountryInfo";

            CSharpCommonValidator.ValidateClass(tree, model, className);
            CSharpCommonValidator.ValidateProperties(tree, model, Lesson3CommonValidator.CreateStep8Properties());
        }
        public void Validate(CSharpCompilation compilation, CSharpSyntaxTree tree, SemanticModel model,
                             Assembly assembly)
        {
            var propertiesToValidate = Lesson3CommonValidator.CreateStep4Properties();

            CSharpCommonValidator.ValidateProperties(tree, model, propertiesToValidate);
        }
Beispiel #3
0
        public void Validate(CSharpCompilation compilation, CSharpSyntaxTree tree, SemanticModel model,
                             Assembly assembly)
        {
            var properties = Lesson3CommonValidator.CreateOnlyStep9Properties();

            properties.Add(Lesson3CommonValidator.CreateNewCustomerProperty());
            CSharpCommonValidator.ValidateProperties(tree, model, properties);
        }
        public static void ValidateStep11Properties(CSharpSyntaxTree tree, SemanticModel model, Assembly assembly)
        {
            ValidateStep2Properties(tree, model, assembly);
            var propertiesToValidate = new List <Property>
            {
                new Property("SubscriptionFrom", "System.DateTime", ControlBindName.DivClass),
                new Property("SubscriptionTo", "System.DateTime", ControlBindName.DivClass)
            };

            CSharpCommonValidator.ValidateProperties(tree, model, propertiesToValidate);
        }
        public void Validate(CSharpCompilation compilation, CSharpSyntaxTree tree, SemanticModel model,
                             Assembly assembly)
        {
            var taskdata = "TaskData";

            CSharpCommonValidator.ValidateClass(tree, model, taskdata);

            List <Property> propertiesToValidate = Lesson2CommonValidator.CreateStep5Properties();

            CSharpCommonValidator.ValidateProperties(tree, model, propertiesToValidate);
        }
        public void Validate(CSharpCompilation compilation, CSharpSyntaxTree tree, SemanticModel model, Assembly assembly)
        {
            CSharpCommonValidator.ValidateProperties(tree, model, Lesson3CommonValidator.CreateStep9Properties());

            ValidatorsExtensions.ExecuteSafe(() =>
            {
                var viewModel = (dynamic)assembly.CreateInstance("DotvvmAcademy.Tutorial.ViewModels.Lesson3ViewModel");

                var usa = viewModel?.Countries[0];
                if (usa == null || usa.Name != "USA" || usa.Id != 1)
                {
                    throw new CodeValidationException(string.Format(Lesson3Texts.CountryInfoError, "USA", 1));
                }
                var canada = viewModel?.Countries[1];
                if (canada == null || canada.Name != "Canada" || canada.Id != 2)
                {
                    throw new CodeValidationException(string.Format(Lesson3Texts.CountryInfoError, "Canada", 2));
                }
            });
        }
Beispiel #7
0
        public void Validate(CSharpCompilation compilation, CSharpSyntaxTree tree, SemanticModel model,
                             Assembly assembly)
        {
            CSharpCommonValidator.ValidateProperties(tree, model, Lesson1CommonValidator.CreateStep4Properties());

            var methodName = "Calculate";

            CSharpCommonValidator.ValidateMethod(tree, model, methodName);

            ValidatorsExtensions.ExecuteSafe(() =>
            {
                var viewModel     = (dynamic)assembly.CreateInstance("DotvvmAcademy.Tutorial.ViewModels.Lesson1ViewModel");
                viewModel.Number1 = 15;
                viewModel.Number2 = 30;
                viewModel.Calculate();

                if (viewModel.Result != 45)
                {
                    throw new CodeValidationException(Lesson1Texts.CommandResultError);
                }
            });
        }
        public static void ValidateStep2Properties(CSharpSyntaxTree tree, SemanticModel model, Assembly assembly)
        {
            CSharpCommonValidator.ValidateProperties(tree, model, CreateStep2ControlProperties());

            ValidatorsExtensions.ExecuteSafe(() =>
            {
                var viewModel       = (dynamic)assembly.CreateInstance("DotvvmAcademy.Tutorial.ViewModels.Lesson4ViewModel");
                var modelProperties = (viewModel.GetType().GetProperties() as IEnumerable <PropertyInfo>).ToList();
                foreach (var requiredProperty in CreateStep2RequiredProperties())
                {
                    var viewModelProperty = modelProperties.FirstOrDefault(a => a.Name == requiredProperty.Name);

                    if (viewModelProperty == null)
                    {
                        throw new CodeValidationException(string.Format(ValidationErrorMessages.PropertyNotFound, requiredProperty.Name));
                    }

                    if (!viewModelProperty.IsDefined(typeof(RequiredAttribute)))
                    {
                        throw new CodeValidationException(string.Format(Lesson4Texts.AttributeMissing,
                                                                        requiredProperty.Name, nameof(RequiredAttribute)));
                    }
                }
                var emailPropertyName = CreateStep2EmailAddressProperty().Name;

                var emailProperty = modelProperties.FirstOrDefault(a => a.Name == emailPropertyName);
                if (emailProperty == null)
                {
                    throw new CodeValidationException(string.Format(ValidationErrorMessages.PropertyNotFound, emailPropertyName));
                }
                if (!emailProperty.IsDefined(typeof(EmailAddressAttribute)))
                {
                    throw new CodeValidationException(string.Format(Lesson4Texts.AttributeMissing,
                                                                    emailPropertyName, nameof(EmailAddressAttribute)));
                }
            });
        }