示例#1
0
        public void RecognizesSingleArgumentType(AnnotationArgumentType argumentType)
        {
            var viewModel = TestViewModel(argumentType);

            Assert.AreEqual(1, viewModel.ApplicableArgumentTypes.Count);
            Assert.AreEqual(argumentType, viewModel.ApplicableArgumentTypes.First());
        }
示例#2
0
 private IReadOnlyList <AnnotationArgumentType> ApplicableTypes(AnnotationArgumentType argumentType)
 {
     return(Enum.GetValues(typeof(AnnotationArgumentType))
            .OfType <AnnotationArgumentType>()
            .Where(t => argumentType.HasFlag(t))
            .ToList());
 }
示例#3
0
        public void ArgumentsLongerThan511CharactersAreIllegal(AnnotationArgumentType argumentType)
        {
            var viewModel = TestViewModel(argumentType, initialArgument: "someText");

            viewModel.ArgumentValue = new string('s', 512);

            Assert.IsTrue(viewModel.HasErrors);
        }
示例#4
0
        public void EmptyArgumentsAreIllegal(AnnotationArgumentType argumentType)
        {
            var viewModel = TestViewModel(argumentType, initialArgument: "someText");

            viewModel.ArgumentValue = string.Empty;

            Assert.IsTrue(viewModel.HasErrors);
        }
示例#5
0
        public void ControlCharactersInArgumentsAreIllegal(AnnotationArgumentType argumentType)
        {
            var viewModel = TestViewModel(argumentType, initialArgument: "someText");

            viewModel.ArgumentValue = "text with \u0000 control character";

            Assert.IsTrue(viewModel.HasErrors);
        }
示例#6
0
        public void NewLinesInArgumentsAreIllegal(AnnotationArgumentType argumentType)
        {
            var viewModel = TestViewModel(argumentType, initialArgument: "someText");

            viewModel.ArgumentValue = $"text with{Environment.NewLine}new line";

            Assert.IsTrue(viewModel.HasErrors);
        }
示例#7
0
        public void SettingValidArgumentClearsErrors(AnnotationArgumentType argumentType, string validArgument)
        {
            var viewModel = TestViewModel(argumentType, initialArgument: "someText", inspectionNames: new [] { "MyInspection" });

            viewModel.ArgumentValue = string.Empty;
            viewModel.ArgumentValue = validArgument;

            Assert.IsFalse(viewModel.HasErrors);
        }
        private Mock <IAnnotationArgumentViewModel> MockArgument(AnnotationArgumentType argumentType, string argumentValue = null, bool hasError = false)
        {
            var mockArgument = new Mock <IAnnotationArgumentViewModel>();

            mockArgument.SetupGet(m => m.HasErrors).Returns(hasError);
            mockArgument.SetupGet(m => m.Model).Returns(new TypedAnnotationArgument(argumentType, argumentValue));

            return(mockArgument);
        }
示例#9
0
        private AnnotationArgumentViewModel TestViewModel(
            AnnotationArgumentType argumentType,
            string initialArgument = null,
            IReadOnlyList <string> inspectionNames = null)
        {
            var model = new TypedAnnotationArgument(argumentType, initialArgument ?? string.Empty);
            var inspectionNameConverter = new InspectionToLocalizedNameConverter();

            return(new AnnotationArgumentViewModel(model, inspectionNames ?? new List <string>(), inspectionNameConverter));
        }
示例#10
0
        public void ChangingTheArgumentTypeSetsDefaultValue(AnnotationArgumentType initialArgumentType, AnnotationArgumentType newArgumentType, string initiallyLegalValue, string defaultValue)
        {
            const AnnotationArgumentType allArgumentTypes = AnnotationArgumentType.Attribute
                                                            | AnnotationArgumentType.Inspection
                                                            | AnnotationArgumentType.Boolean
                                                            | AnnotationArgumentType.Number
                                                            | AnnotationArgumentType.Text;

            var viewModel = TestViewModel(allArgumentTypes, initialArgument: string.Empty, inspectionNames: new[] { "MyInspection", "OtherInspection" });

            viewModel.ArgumentType  = initialArgumentType;
            viewModel.ArgumentValue = initiallyLegalValue;

            viewModel.ArgumentType = newArgumentType;

            Assert.AreEqual(defaultValue, viewModel.ArgumentValue);
        }
示例#11
0
        public IAnnotationArgumentViewModel Create(AnnotationArgumentType argumentType, string argument = null)
        {
            var model = new TypedAnnotationArgument(argumentType, argument ?? string.Empty);

            return(new AnnotationArgumentViewModel(model, _inspectionNames, _inspectionNameConverter));
        }
示例#12
0
        public void EmptyInitialValueLeadsToDefaultValue(AnnotationArgumentType argumentType, string defaultValue)
        {
            var viewModel = TestViewModel(argumentType, initialArgument: string.Empty, inspectionNames: new[] { "MyInspection", "OtherInspection" });

            Assert.AreEqual(defaultValue, viewModel.ArgumentValue);
        }
示例#13
0
        public void InitialValueIsValidated(AnnotationArgumentType argumentType)
        {
            var viewModel = TestViewModel(argumentType, initialArgument: "\u0000");

            Assert.IsTrue(viewModel.HasErrors);
        }
示例#14
0
 public TypedAnnotationArgument(AnnotationArgumentType type, string argument)
 {
     ArgumentType = type;
     Argument     = argument;
 }