public void RecognizesSingleArgumentType(AnnotationArgumentType argumentType) { var viewModel = TestViewModel(argumentType); Assert.AreEqual(1, viewModel.ApplicableArgumentTypes.Count); Assert.AreEqual(argumentType, viewModel.ApplicableArgumentTypes.First()); }
private IReadOnlyList <AnnotationArgumentType> ApplicableTypes(AnnotationArgumentType argumentType) { return(Enum.GetValues(typeof(AnnotationArgumentType)) .OfType <AnnotationArgumentType>() .Where(t => argumentType.HasFlag(t)) .ToList()); }
public void ArgumentsLongerThan511CharactersAreIllegal(AnnotationArgumentType argumentType) { var viewModel = TestViewModel(argumentType, initialArgument: "someText"); viewModel.ArgumentValue = new string('s', 512); Assert.IsTrue(viewModel.HasErrors); }
public void EmptyArgumentsAreIllegal(AnnotationArgumentType argumentType) { var viewModel = TestViewModel(argumentType, initialArgument: "someText"); viewModel.ArgumentValue = string.Empty; Assert.IsTrue(viewModel.HasErrors); }
public void ControlCharactersInArgumentsAreIllegal(AnnotationArgumentType argumentType) { var viewModel = TestViewModel(argumentType, initialArgument: "someText"); viewModel.ArgumentValue = "text with \u0000 control character"; Assert.IsTrue(viewModel.HasErrors); }
public void NewLinesInArgumentsAreIllegal(AnnotationArgumentType argumentType) { var viewModel = TestViewModel(argumentType, initialArgument: "someText"); viewModel.ArgumentValue = $"text with{Environment.NewLine}new line"; Assert.IsTrue(viewModel.HasErrors); }
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); }
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)); }
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); }
public IAnnotationArgumentViewModel Create(AnnotationArgumentType argumentType, string argument = null) { var model = new TypedAnnotationArgument(argumentType, argument ?? string.Empty); return(new AnnotationArgumentViewModel(model, _inspectionNames, _inspectionNameConverter)); }
public void EmptyInitialValueLeadsToDefaultValue(AnnotationArgumentType argumentType, string defaultValue) { var viewModel = TestViewModel(argumentType, initialArgument: string.Empty, inspectionNames: new[] { "MyInspection", "OtherInspection" }); Assert.AreEqual(defaultValue, viewModel.ArgumentValue); }
public void InitialValueIsValidated(AnnotationArgumentType argumentType) { var viewModel = TestViewModel(argumentType, initialArgument: "\u0000"); Assert.IsTrue(viewModel.HasErrors); }
public TypedAnnotationArgument(AnnotationArgumentType type, string argument) { ArgumentType = type; Argument = argument; }