public void CreateReference_Failing(ArgumentConstructor type, string config, IEnumerable <string> argument, IEnumerable <ArgumentSchema> schema, ErrorCode error, string argumentId, string parameter, string message) { Exception a = CreateConstructor_Failing(type, config, argument, schema); if (a is BaseArgumentException) { BaseArgumentException ex = a as BaseArgumentException; Assert.Equal(error, ex.ErrorCode); if (!string.IsNullOrEmpty(argumentId)) { Assert.Equal(argumentId, ex.ErrorArgumentId); } else { Assert.Null(ex.ErrorArgumentId); } Assert.Equal(parameter, ex.ErrorParameter); if (!string.IsNullOrEmpty(message)) { Assert.Equal(message, ex.ErrorMessage()); } else { Assert.Equal(parameter, ex.ErrorMessage()); } } else { throw new XunitException(); } }
public void CreateArgumentConfigWithWrongSchema_Failing() { ArgumentConfig a = null; BaseArgumentException ex = Assert.Throws <ArgumentException>(() => a = new ArgumentConfig() { Schema = new List <ArgumentSchema>() { new ArgumentSchema() { Argument = new List <string>() { "string", "f4!se" } }, new ArgumentSchema() { Argument = new List <string>() { "good", "b d" } } }, Delimiter = "-:/" }); Assert.Null(a); Assert.Equal(ErrorCode.INVALID, ex.ErrorCode); Assert.Null(ex.ErrorArgumentId); Assert.Equal("Argument", ex.ErrorParameter); Assert.Equal("Config File: Argument contains invalid data!", ex.ErrorMessage()); }
public void CreateArgumentConfigWithEmptySchema_Failing() { ArgumentConfig a = null; BaseArgumentException ex = Assert.Throws <ArgumentException>(() => a = new ArgumentConfig() { Schema = new List <ArgumentSchema>() { new ArgumentSchema() { Argument = null }, new ArgumentSchema() { Argument = new List <string>() } }, Delimiter = "-:/" }); Assert.Null(a); Assert.Equal(ErrorCode.EMPTY, ex.ErrorCode); Assert.Null(ex.ErrorArgumentId); Assert.Equal("Argument", ex.ErrorParameter); Assert.Equal("Config File: Argument contains no data!", ex.ErrorMessage()); }
public void CreateReferenceAndSetIteratorToLast_FailingTest() { StringMarshaler m = new StringMarshaler(); Iterator <string> i = new Iterator <string>(testData); for (int j = 0; j < this.testData.Count; j++) { i.Next(); } Exception ex = Record.Exception(() => m.Set(i)); BaseArgumentException exBase = ex as BaseArgumentException ?? throw new XunitException("Wrong exception type!"); exBase.ErrorArgumentId = this.testArgument; Assert.Equal(ErrorCode.MISSING, exBase.ErrorCode); Assert.Equal(this.testArgument, exBase.ErrorArgumentId); Assert.Equal($"Could not find string parameter for -{this.testArgument}", exBase.ErrorMessage()); }
public void CreateReferenceAndGetRequiredValue_Failing(ArgumentConstructor type, string config, string[] arguments) { Argument arg = CreateConstructor_Passing(type, config, arguments.Skip(2).Take(2), schema.Take(4)); Exception a = Assert.Throws <ArgumentException>(() => arg.GetValue <string>(arguments[0].Substring(1).ToString())); if (a is BaseArgumentException) { BaseArgumentException ex = a as BaseArgumentException; Assert.Equal(ErrorCode.MISSING, ex.ErrorCode); Assert.Equal("string, text, data", ex.ErrorArgumentId); Assert.Null(ex.ErrorParameter); Assert.Equal("Missing parameter: ('string, text, data')", ex.ErrorMessage()); } else { throw new XunitException(); } }
public void CreateReferenceAndSetIteratorWithWrongFormat_FailingTest() { IntegerMarshaler m = new IntegerMarshaler(); Iterator <string> i = new Iterator <string>(testData); for (int j = 0; j < (this.testData.Count - 1); j++) { i.Next(); } Exception ex = Record.Exception(() => m.Set(i)); BaseArgumentException exBase = ex as BaseArgumentException ?? throw new XunitException("Wrong exception type!"); exBase.ErrorArgumentId = this.testArgument; Assert.Equal(ErrorCode.INVALID, exBase.ErrorCode); Assert.Equal(this.testArgument, exBase.ErrorArgumentId); Assert.Equal(this.testData[(this.testData.Count - 1)], exBase.ErrorParameter); Assert.Equal($"Argument -{this.testArgument} expects an integer but was '{this.testData[(this.testData.Count - 1)]}'", exBase.ErrorMessage()); }