public void AddByCodeOnlyTest() { // code already exists { string name = "The name"; var target = new CategoricalVariable(name) { 2.0 }; ExceptionAssert.Throw( () => { target.Add(2.0); }, expectedType: typeof(InvalidOperationException), expectedMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_CAT_ALREADY_EXISTS_IN_VARIABLE_LIST")); } // target is read only { string name = "The name"; var target = new CategoricalVariable(name); target.SetAsReadOnly(); ExceptionAssert.Throw( () => { target.Add(3.0); }, expectedType: typeof(InvalidOperationException), expectedMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_CAT_VARIABLE_IS_READONLY")); } // Valid input { string name = "The name"; var target = new CategoricalVariable(name); double code; Category category0, category1; code = 1.0; target.Add(code); category0 = new Category(code); code = 2.0; target.Add(code); category1 = new Category(code); CategoricalVariableAssert.IsStateAsExpected( target, name, expectedCategories: new List <Category>(2) { category0, category1 }, expectedReadOnlyFlag: false); } }
public void SetAsReadOnlyTest() { string expectedName = "The name"; var target = new CategoricalVariable(expectedName); target.SetAsReadOnly(); CategoricalVariableAssert.IsStateAsExpected( target, expectedName, expectedCategories: new List <Category>(), expectedReadOnlyFlag: true); }
public void ConstructorTest() { // name is null { ArgumentExceptionAssert.Throw( () => { new CategoricalVariable(null); }, expectedType: typeof(ArgumentNullException), expectedPartialMessage: ArgumentExceptionAssert.NullPartialMessage, expectedParameterName: "name"); } // name is white space { ArgumentExceptionAssert.Throw( () => { new CategoricalVariable(" "); }, expectedType: typeof(ArgumentOutOfRangeException), expectedPartialMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_PAR_STRING_IS_EMPTY_OR_WHITESPACE"), expectedParameterName: "name"); } // name is empty { ArgumentExceptionAssert.Throw( () => { new CategoricalVariable(string.Empty); }, expectedType: typeof(ArgumentOutOfRangeException), expectedPartialMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_PAR_STRING_IS_EMPTY_OR_WHITESPACE"), expectedParameterName: "name"); } // Valid name { string expectedName = "The name"; var target = new CategoricalVariable(expectedName); CategoricalVariableAssert.IsStateAsExpected( target, expectedName, expectedCategories: new List <Category>(), expectedReadOnlyFlag: false); } }
public void AddTest() { // code already exists { string name = "The name"; var target = new CategoricalVariable(name) { 2.0 }; ExceptionAssert.Throw( () => { target.Add(2.0, "second two"); }, expectedType: typeof(InvalidOperationException), expectedMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_CAT_ALREADY_EXISTS_IN_VARIABLE_LIST")); } // label already exists { string name = "The name"; var target = new CategoricalVariable(name) { { 2.0, "two" } }; ExceptionAssert.Throw( () => { target.Add(2.000001, "two"); }, expectedType: typeof(InvalidOperationException), expectedMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_CAT_ALREADY_EXISTS_IN_VARIABLE_LIST")); } // label is null { string name = "The name"; var target = new CategoricalVariable(name); ArgumentExceptionAssert.Throw( () => { target.Add(3.0, null); }, expectedType: typeof(ArgumentNullException), expectedPartialMessage: ArgumentExceptionAssert.NullPartialMessage, expectedParameterName: "label"); } // label is white space { string name = "The name"; var target = new CategoricalVariable(name); ArgumentExceptionAssert.Throw( () => { target.Add(3.0, " "); }, expectedType: typeof(ArgumentOutOfRangeException), expectedPartialMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_PAR_STRING_IS_EMPTY_OR_WHITESPACE"), expectedParameterName: "label"); } // label is empty { string name = "The name"; var target = new CategoricalVariable(name); ArgumentExceptionAssert.Throw( () => { target.Add(3.0, string.Empty); }, expectedType: typeof(ArgumentOutOfRangeException), expectedPartialMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_PAR_STRING_IS_EMPTY_OR_WHITESPACE"), expectedParameterName: "label"); } // target is read only { string name = "The name"; var target = new CategoricalVariable(name); target.SetAsReadOnly(); ExceptionAssert.Throw( () => { target.Add(3.0, "three"); }, expectedType: typeof(InvalidOperationException), expectedMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_CAT_VARIABLE_IS_READONLY")); } // Valid input { string name = "The name"; var target = new CategoricalVariable(name); double code; string label; Category category0, category1; code = 1.0; label = "one"; target.Add(code, label); category0 = new Category(code, label); code = 2.0; label = "two"; target.Add(code, label); category1 = new Category(code, label); CategoricalVariableAssert.IsStateAsExpected( target, name, expectedCategories: new List <Category>(2) { category0, category1 }, expectedReadOnlyFlag: false); } }