diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/FieldObjectDecoratorTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/FieldObjectDecoratorTests.cs deleted file mode 100644 index c9202ecc..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/FieldObjectDecoratorTests.cs +++ /dev/null @@ -1,87 +0,0 @@ -using RarelySimple.AvatarScriptLink.Net.Decorators; -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Tests.Decorators -{ - [TestClass] - public class FieldObjectDecoratorTests - { - #region Constructor - - [TestMethod] - public void TestFieldObjectDecorator_Constructor_NullFieldObject() - { - Assert.ThrowsException(() => new FieldObjectDecorator((FieldObject)null)); - } - - #endregion - - [TestMethod] - public void TestFieldObjectIsNotModified() - { - var expected = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "sample value", - Lock = "0", - Required = "1" - }; - var decorator = new FieldObjectDecorator(expected); - Assert.IsFalse(decorator.IsModified()); - } - - [TestMethod] - public void TestFieldObjectIsModified() - { - var expected = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "sample value", - Lock = "0", - Required = "1" - }; - var decorator = new FieldObjectDecorator(expected) - { - FieldValue = "modified" - }; - Assert.IsTrue(decorator.IsModified()); - } - - [TestMethod] - public void TestFieldObjectReturnsUnmodified() - { - var expected = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "sample value", - Lock = "0", - Required = "1" - }; - var decorator = new FieldObjectDecorator(expected); - var actual = decorator.Return().AsFieldObject(); - Assert.AreEqual(expected, actual); - } - - [TestMethod] - public void TestFieldObjectReturnsModified() - { - var expected = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "sample value", - Lock = "0", - Required = "1" - }; - var decorator = new FieldObjectDecorator(expected) - { - FieldValue = "modified" - }; - var actual = decorator.Return().AsFieldObject(); - Assert.AreNotEqual(expected, actual); - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/FormObjectDecoratorTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/FormObjectDecoratorTests.cs deleted file mode 100644 index 9add3587..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/FormObjectDecoratorTests.cs +++ /dev/null @@ -1,1435 +0,0 @@ -using RarelySimple.AvatarScriptLink.Net.Decorators; -using RarelySimple.AvatarScriptLink.Net.Exceptions; -using RarelySimple.AvatarScriptLink.Objects; -using static RarelySimple.AvatarScriptLink.Objects.RowObject; - -namespace RarelySimple.AvatarScriptLink.Net.Tests.Decorators; - -[TestClass] -public class FormObjectDecoratorTests -{ - #region Constructor - - [TestMethod] - public void TestFormObjectDecorator_Constructor_NullFormObject() - { - Assert.ThrowsException(() => new FormObjectDecorator(null)); - } - - #endregion - - [TestMethod] - public void TestFormObjectDecorator_ReturnsNoRows() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - var actual = decorator.Return().AsFormObject(); - Assert.IsNull(actual.CurrentRow); - } - - #region Builder - - [TestMethod] - public void TestFormObjectDecorator_Builder_Expected() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "1", - Required = "1" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = FormObjectDecorator.Builder(formObject).Build(); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - Assert.IsTrue(decorator.IsFieldEnabled(fieldNumber)); - Assert.IsTrue(decorator.IsFieldLocked(fieldNumber)); - Assert.IsTrue(decorator.IsFieldRequired(fieldNumber)); - } - - [TestMethod] - public void TestFormObjectDecorator_Builder_CurrentRowExpected() - { - var expected = "456||1"; - var rowObject = new RowObject() - { - RowId = expected - }; - var formObject = new FormObject() - { - FormId = "456" - }; - var decorator = FormObjectDecorator.Builder(formObject).CurrentRow(rowObject).Build(); - Assert.IsTrue(decorator.IsRowPresent(expected)); - } - - [TestMethod] - public void TestFormObjectDecorator_Builder_OtherRowExpected() - { - var expected = "456||1"; - var rowObject = new RowObject() - { - RowId = expected - }; - var formObject = new FormObject() - { - FormId = "456", - MultipleIteration = true - }; - var decorator = FormObjectDecorator.Builder(formObject).OtherRow(rowObject).Build(); - Assert.IsTrue(decorator.IsRowPresent(expected)); - } - - [TestMethod] - public void TestFormObjectDecorator_Builder_OtherRowsExpected() - { - var expected = "456||1"; - var rowObject = new RowObject() - { - RowId = expected - }; - List rows = [rowObject]; - var formObject = new FormObject() - { - FormId = "456", - MultipleIteration = true - }; - var decorator = FormObjectDecorator.Builder(formObject).OtherRows(rows).Build(); - Assert.IsTrue(decorator.IsRowPresent(expected)); - } - - #endregion - - #region GetCurrentRowId - - [TestMethod] - public void TestFormObjectDecorator_GetCurrentRowId_Expected() { - var expected = "456||1"; - RowObject rowObject = new() { - RowId = expected - }; - FormObjectDecorator decorator = FormObjectDecorator.Builder().FormId("456").CurrentRow(rowObject).Build(); - Assert.AreEqual(expected, decorator.GetCurrentRowId()); - } - - [TestMethod] - public void TestFormObjectDecorator_GetCurrentRowId_Exception() { - FormObjectDecorator decorator = FormObjectDecorator.Builder().FormId("456").Build(); - Assert.ThrowsException(() => decorator.GetCurrentRowId()); - } - - #endregion - - #region GetFieldValue - - [TestMethod] - public void TestFormObjectDecorator_GetFieldValue_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - } - - #endregion - - #region GetFieldValues - - [TestMethod] - public void TestFormObjectDecorator_GetFieldValues_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.AreEqual(1, decorator.GetFieldValues(fieldNumber).Count); - Assert.AreEqual(expected, decorator.GetFieldValues(fieldNumber)[0]); - } - - [TestMethod] - public void TestFormObjectDecorator_GetFieldValues_MultipleRows_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var expected2 = "initial value 2"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected2, - Lock = "0", - Required = "0" - }; - var rowObject2 = new RowObject() - { - Fields = [fieldObject2], - RowId = "456||2", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2], - }; - var decorator = new FormObjectDecorator(formObject); - Assert.AreEqual(2, decorator.GetFieldValues(fieldNumber).Count); - Assert.AreEqual(expected, decorator.GetFieldValues(fieldNumber)[0]); - Assert.AreEqual(expected2, decorator.GetFieldValues(fieldNumber)[1]); - } - - [TestMethod] - public void TestFormObjectDecorator_GetFieldValues_NotPresent() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.AreEqual(0, decorator.GetFieldValues("457||1").Count); - } - - [TestMethod] - public void TestFormObjectDecorator_GetFieldValues_Empty() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.ThrowsException(() => decorator.GetFieldValues("")); - } - - [TestMethod] - public void TestFormObjectDecorator_GetFieldValues_Null() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.ThrowsException(() => decorator.GetFieldValues(null)); - } - - #endregion - - #region GetMultipleIterationStatus - - [TestMethod] - public void TestFormObjectDecorator_GetMultipleIerationStatus_ReturnsBool() - { - var expected = false; - var formObject = new FormObject() - { - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.AreEqual(expected.GetType(), decorator.GetMultipleIterationStatus().GetType()); - } - - [TestMethod] - public void TestFormObjectDecorator_GetMultipleIerationStatus_ReturnsFalse() - { - var formObject = new FormObject() - { - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsFalse(decorator.GetMultipleIterationStatus()); - } - - [TestMethod] - public void TestFormObjectDecorator_GetMultipleIerationStatus_ReturnsTrue() - { - var formObject = new FormObject() - { - FormId = "456", - MultipleIteration = true - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsTrue(decorator.GetMultipleIterationStatus()); - } - - #endregion - - #region GetParentRowId - - [TestMethod] - public void TestFormObjectDecorator_GetParentRowId_Expected() { - var expected = "456||1"; - RowObject rowObject = new() { - RowId = "456||3", - ParentRowId = expected - }; - FormObjectDecorator decorator = FormObjectDecorator.Builder().FormId("456").CurrentRow(rowObject).Build(); - Assert.AreEqual(expected, decorator.GetParentRowId()); - } - - [TestMethod] - public void TestFormObjectDecorator_GetParentRowId_Exception() { - FormObjectDecorator decorator = FormObjectDecorator.Builder().FormId("456").Build(); - Assert.ThrowsException(() => decorator.GetParentRowId()); - } - - [TestMethod] - public void TestFormObjectDecorator_GetParentRowId_Null() { - RowObject rowObject = new() { - RowId = "456||3" - }; - FormObjectDecorator decorator = FormObjectDecorator.Builder().FormId("456").CurrentRow(rowObject).Build(); - Assert.IsNull(decorator.GetParentRowId()); - } - - #endregion - - #region IsFieldEnabled - - [TestMethod] - public void IsFieldEnabled_FormObject_IsEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsTrue(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_FormObject_IsNotEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsFalse(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_FormObject_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.ThrowsException(() => decorator.IsFieldEnabled("678.90")); - } - - #endregion - - #region IsFieldLocked - - [TestMethod] - public void IsFieldLocked_FormObject_IsLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "1", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsTrue(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_FormObject_IsNotLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsFalse(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_FormObject_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.ThrowsException(() => decorator.IsFieldLocked("678.90")); - } - - #endregion - - #region IsFieldModified - - [TestMethod] - public void IsFieldModified_FormObject_IsFalse() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - FormObjectDecorator decorator = new(formObject); - Assert.IsFalse(decorator.IsFieldModified("123")); - } - - [TestMethod] - public void IsFieldModified_FormObject_IsTrue() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - RowId = "1||1", - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - FormObjectDecorator decorator = new(formObject); - decorator.SetFieldValue("123", "MODIFIED"); - Assert.IsTrue(decorator.IsFieldModified("123")); - } - - [TestMethod] - public void IsFieldModified_FormObject_IsTrue_NullFieldNumber() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - FormObjectDecorator decorator = new(formObject); - Assert.ThrowsException(() => decorator.IsFieldModified(null)); - } - - #endregion - - #region IsFieldPresent - - [TestMethod] - public void TestFormObjectDecorator_FieldIsPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsTrue(decorator.IsFieldPresent("123.45")); - } - - [TestMethod] - public void TestFormObjectDecorator_FieldIsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsFalse(decorator.IsFieldPresent("678.90")); - } - - #endregion - - #region IsFieldRequired - - [TestMethod] - public void IsFieldRequired_FormObject_IsRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "1" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsTrue(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_FormObject_IsNotRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsFalse(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_FormObject_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.ThrowsException(() => decorator.IsFieldRequired("678.90")); - } - - #endregion - - #region IsRowMarkedForDeletion - - [TestMethod] - public void IsRowMarkedForDeletion_FormObject_Expected() { - var rowObject1 = new RowObject() - { - RowId = "456||1" - }; - var rowObject2 = new RowObject() - { - RowId = "456||2", - RowAction = RowActions.Delete - }; - var formObject = new FormObject() - { - CurrentRow = rowObject1, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2] - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsFalse(decorator.IsRowMarkedForDeletion("456||1")); - Assert.IsTrue(decorator.IsRowMarkedForDeletion("456||2")); - } - - [TestMethod] - public void IsRowMarkedForDeletion_FormObject_NoRowId() { - var rowObject1 = new RowObject() - { - RowId = "456||1" - }; - var rowObject2 = new RowObject() - { - RowId = "456||2", - RowAction = RowActions.Delete - }; - var formObject = new FormObject() - { - CurrentRow = rowObject1, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2] - }; - var decorator = new FormObjectDecorator(formObject); - Assert.ThrowsException(() => decorator.IsRowMarkedForDeletion(null)); - } - - #endregion - - #region SetFieldValue - - [TestMethod] - public void TestFormObjectDecorator_SetFieldValue_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "modified value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - decorator.SetFieldValue(fieldNumber, expected); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - } - - [TestMethod] - public void TestFormObjectDecorator_SetFieldValue_ReturnsExpectedRows() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var decorator = new FormObjectDecorator(formObject); - decorator.SetFieldValue("123.45", "modified value"); - var actual = decorator.Return().AsFormObject(); - Assert.IsNotNull(actual.CurrentRow); - Assert.AreEqual(RowActions.Edit, actual.CurrentRow.RowAction); - Assert.AreEqual(1, actual.CurrentRow.Fields.Count); - } - - #endregion - - #region AddRowObject - - [TestMethod] - public void TestFormObjectDecorator_AddRowObject_WithRowObject() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var decorator = new FormObjectDecorator(formObject); - var rowObject = new RowObject(); - decorator.AddRowObject(rowObject); - Assert.IsNotNull(decorator.CurrentRow); - Assert.AreEqual("1||1", decorator.CurrentRow.RowId); - } - - [TestMethod] - public void TestFormObjectDecorator_AddRowObject_WithRowIdAndParentRowId() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var decorator = new FormObjectDecorator(formObject); - decorator.AddRowObject("1||1", "1||1"); - Assert.IsNotNull(decorator.CurrentRow); - Assert.AreEqual("1||1", decorator.CurrentRow.RowId); - Assert.AreEqual("1||1", decorator.CurrentRow.ParentRowId); - } - - [TestMethod] - public void TestFormObjectDecorator_AddRowObject_WithRowIdParentRowIdAndAction() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var decorator = new FormObjectDecorator(formObject); - decorator.AddRowObject("1||1", "1||1", RowActions.Edit); - Assert.IsNotNull(decorator.CurrentRow); - Assert.AreEqual("1||1", decorator.CurrentRow.RowId); - Assert.AreEqual("1||1", decorator.CurrentRow.ParentRowId); - Assert.AreEqual(RowActions.Edit, decorator.CurrentRow.RowAction); - } - - [TestMethod] - public void TestFormObjectDecorator_AddRowObject_MultipleRows() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var decorator = new FormObjectDecorator(formObject); - var rowObject1 = new RowObject(); - decorator.AddRowObject(rowObject1); - Assert.AreEqual("1||1", decorator.CurrentRow.RowId); - - var rowObject2 = new RowObject(); - decorator.AddRowObject(rowObject2); - Assert.AreEqual(1, decorator.OtherRows.Count); - Assert.AreEqual("1||2", decorator.OtherRows[0].RowId); - } - - [TestMethod] - public void TestFormObjectDecorator_AddRowObject_NullRowObject() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var decorator = new FormObjectDecorator(formObject); -#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. - Assert.ThrowsException(() => decorator.AddRowObject((RowObject)null)); -#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. - } - - [TestMethod] - public void TestFormObjectDecorator_AddRowObject_NonMultipleIterationWithExistingRow() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = false, - CurrentRow = new RowObject() { RowId = "1||1" } - }; - var decorator = new FormObjectDecorator(formObject); - var rowObject = new RowObject(); - Assert.ThrowsException(() => decorator.AddRowObject(rowObject)); - } - - [TestMethod] - public void TestFormObjectDecorator_AddRowObject_DuplicateRowId() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true, - CurrentRow = new RowObject() { RowId = "1||1" } - }; - var decorator = new FormObjectDecorator(formObject); - var rowObject = new RowObject() { RowId = "1||1" }; - Assert.ThrowsException(() => decorator.AddRowObject(rowObject)); - } - - [TestMethod] - public void TestFormObjectDecorator_GetNextAvailableRowId() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var decorator = new FormObjectDecorator(formObject); - string rowId = decorator.GetNextAvailableRowId(); - Assert.AreEqual("1||1", rowId); - } - - [TestMethod] - public void TestFormObjectDecorator_GetNextAvailableRowId_WithExistingRows() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true, - CurrentRow = new RowObject() { RowId = "1||1" } - }; - formObject.OtherRows.Add(new RowObject() { RowId = "1||2" }); - var decorator = new FormObjectDecorator(formObject); - string rowId = decorator.GetNextAvailableRowId(); - Assert.AreEqual("1||3", rowId); - } - - #endregion - - #region DeleteRowObject - - [TestMethod] - public void TestFormObjectDecorator_DeleteRowObject_CurrentRow() - { - var rowObject = new RowObject() - { - RowId = "1||1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var decorator = new FormObjectDecorator(formObject); - decorator.DeleteRowObject("1||1"); - Assert.AreEqual(RowActions.Delete, decorator.CurrentRow.RowAction); - } - - [TestMethod] - public void TestFormObjectDecorator_DeleteRowObject_OtherRow() - { - var row1 = new RowObject() { RowId = "1||1" }; - var row2 = new RowObject() { RowId = "1||2" }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = row1, - MultipleIteration = true, - OtherRows = [row2] - }; - var decorator = new FormObjectDecorator(formObject); - decorator.DeleteRowObject("1||2"); - Assert.AreEqual(RowActions.Delete, decorator.OtherRows[0].RowAction); - } - - [TestMethod] - public void TestFormObjectDecorator_DeleteRowObject_NullRowId() - { - var formObject = new FormObject() - { - FormId = "1" - }; - var decorator = new FormObjectDecorator(formObject); - Assert.ThrowsException(() => decorator.DeleteRowObject((string)null)); - } - - [TestMethod] - public void TestFormObjectDecorator_DeleteRowObject_NotFound() - { - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = new RowObject() { RowId = "1||1" } - }; - var decorator = new FormObjectDecorator(formObject); - Assert.ThrowsException(() => decorator.DeleteRowObject("1||2")); - } - - #endregion - - #region Edge Case Tests - Regression & Coverage - - [TestMethod] - public void TestFormObjectDecorator_Constructor_WithNullOtherRowsCollection() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true, - CurrentRow = new RowObject() { RowId = "1||1" }, - OtherRows = null - }; - var decorator = new FormObjectDecorator(formObject); - Assert.IsNotNull(decorator.OtherRows); - Assert.AreEqual(0, decorator.OtherRows.Count); - } - - [TestMethod] - public void TestFormObjectDecorator_GetNextAvailableRowId_WithNullCurrentRowButExistingOtherRows() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - formObject.OtherRows.Add(new RowObject() { RowId = "1||1" }); - formObject.OtherRows.Add(new RowObject() { RowId = "1||2" }); - var decorator = new FormObjectDecorator(formObject); - string rowId = decorator.GetNextAvailableRowId(); - Assert.AreEqual("1||3", rowId); - } - - [TestMethod] - public void TestFormObjectDecorator_GetNextAvailableRowId_WithGapInSequence() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true, - CurrentRow = new RowObject() { RowId = "1||1" } - }; - formObject.OtherRows.Add(new RowObject() { RowId = "1||3" }); - formObject.OtherRows.Add(new RowObject() { RowId = "1||4" }); - var decorator = new FormObjectDecorator(formObject); - string rowId = decorator.GetNextAvailableRowId(); - Assert.AreEqual("1||2", rowId); - } - - [TestMethod] - public void TestFormObjectDecorator_AddRowObject_WithEmptyRowId_IsAutoGenerated() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var decorator = new FormObjectDecorator(formObject); - var rowObject = new RowObject() { RowId = "" }; - decorator.AddRowObject(rowObject); - Assert.IsNotNull(decorator.CurrentRow); - // Empty row IDs are auto-generated - Assert.AreEqual("1||1", decorator.CurrentRow.RowId); - } - - [TestMethod] - public void TestFormObjectDecorator_AddRowObject_WithNullOtherRows_BecomesCurrentRow() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true, - OtherRows = null - }; - var decorator = new FormObjectDecorator(formObject); - var rowObject = new RowObject(); - decorator.AddRowObject(rowObject); - Assert.IsNotNull(decorator.OtherRows); - // When adding first row to form with null OtherRows, it becomes CurrentRow - Assert.AreEqual(0, decorator.OtherRows.Count); - Assert.AreEqual("1||1", decorator.CurrentRow.RowId); - } - - #endregion - - #region DisableAllFieldObjects - - [TestMethod] - public void DisableAllFieldObjects_NullExclusionList_ThrowsException() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var decorator = new FormObjectDecorator(formObject); - Assert.ThrowsException(() => decorator.DisableAllFieldObjects(null)); - } - - [TestMethod] - public void DisableAllFieldObjects_DisablesFieldsInCurrentRow() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var decorator = new FormObjectDecorator(formObject); - decorator.DisableAllFieldObjects(new List()); - Assert.IsFalse(decorator.CurrentRow.Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_DisablesFieldsInOtherRowsWhenMultipleIteration() - { - var fieldObject1 = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = "124", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var currentRow = new RowObject() - { - Fields = [fieldObject1], - RowId = "1" - }; - var otherRow = new RowObject() - { - Fields = [fieldObject2], - RowId = "2", - ParentRowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = currentRow, - MultipleIteration = true, - OtherRows = [otherRow] - }; - var decorator = new FormObjectDecorator(formObject); - decorator.DisableAllFieldObjects(new List()); - Assert.IsFalse(decorator.CurrentRow.Fields[0].Enabled); - Assert.IsFalse(decorator.OtherRows[0].Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_DisablesFieldsInOtherRowsEvenWhenNotMultipleIteration() - { - var fieldObject1 = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = "124", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var currentRow = new RowObject() - { - Fields = [fieldObject1], - RowId = "1" - }; - var otherRow = new RowObject() - { - Fields = [fieldObject2], - RowId = "2", - ParentRowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = currentRow, - MultipleIteration = false, - OtherRows = [otherRow] - }; - var decorator = new FormObjectDecorator(formObject); - decorator.DisableAllFieldObjects(new List()); - Assert.IsFalse(decorator.CurrentRow.Fields[0].Enabled); - Assert.IsFalse(decorator.OtherRows[0].Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_ExcludedFieldsRemainEnabled() - { - var fieldObject1 = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = "124", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject1, fieldObject2], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var decorator = new FormObjectDecorator(formObject); - decorator.DisableAllFieldObjects(new List { "123" }); - Assert.IsTrue(decorator.CurrentRow.Fields[0].Enabled); - Assert.IsFalse(decorator.CurrentRow.Fields[1].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_WithNullCurrentRow() - { - var formObject = new FormObject() - { - FormId = "1" - }; - var decorator = new FormObjectDecorator(formObject); - decorator.DisableAllFieldObjects(new List()); - Assert.IsNull(decorator.CurrentRow); - } - - [TestMethod] - public void DisableAllFieldObjects_SetsRowActionToEdit() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1", - RowAction = "" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var decorator = new FormObjectDecorator(formObject); - decorator.DisableAllFieldObjects(new List()); - Assert.AreEqual(RowActions.Edit, decorator.CurrentRow.RowAction); - } - - [TestMethod] - public void DisableAllFieldObjects_WithoutExclusionList() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var decorator = new FormObjectDecorator(formObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.CurrentRow.Fields[0].Enabled); - Assert.AreEqual(RowActions.Edit, decorator.CurrentRow.RowAction); - } - - #endregion -} \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/OptionObject2015DecoratorTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/OptionObject2015DecoratorTests.cs deleted file mode 100644 index 9806780e..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/OptionObject2015DecoratorTests.cs +++ /dev/null @@ -1,2108 +0,0 @@ -using RarelySimple.AvatarScriptLink.Net.Decorators; -using RarelySimple.AvatarScriptLink.Net.Exceptions; -using RarelySimple.AvatarScriptLink.Objects; -using static RarelySimple.AvatarScriptLink.Objects.RowObject; - -namespace RarelySimple.AvatarScriptLink.Net.Tests.Decorators; - -[TestClass] -public class OptionObject2015DecoratorTests -{ - #region Constructor - - [TestMethod] - public void TestOptionObject2015Decorator_Constructor_NullOptionObject() - { - Assert.ThrowsException(() => new OptionObject2015Decorator(null)); - } - - #endregion - - [TestMethod] - public void TestOptionObject2015Decorator_ReturnsNoForms() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - var actual = decorator.Return().AsOptionObject2015(); - Assert.AreEqual(0, actual.Forms.Count); - } - - #region AddFormObject - - [TestMethod] - public void AddFormObject_Expected() { - var expected = new FormObject() { - FormId = "1" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.AddFormObject(expected); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectDecorator_Expected() { - var expected = FormObjectDecorator.Builder().FormId("1").Build(); - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.AddFormObject(expected); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectById_Expected() { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.AddFormObject("1"); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_Expected() { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.AddFormObject("1", false); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_ArgumentNullException() { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject(null, false)); - } - - [TestMethod] - public void AddFormObject_MICannotBeFirst() { - var expected = new FormObject() { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectDecorator_MICannotBeFirst() { - var expected = FormObjectDecorator.Builder().FormId("1").MultipleIteration().Build(); - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_MICannotBeFirst() { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject("1", true)); - } - - [TestMethod] - public void AddFormObject_DuplicateForms() { - var expected = new FormObject() { - FormId = "1" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.AddFormObject(expected); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectDecorator_DuplicateForms() { - var expected = FormObjectDecorator.Builder().FormId("1").Build(); - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.AddFormObject(expected); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectById_DuplicateForms() { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.AddFormObject("1"); - Assert.ThrowsException(() => decorator.AddFormObject("1")); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_DuplicateForms() { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.AddFormObject("1", false); - Assert.ThrowsException(() => decorator.AddFormObject("1", false)); - } - - #endregion - - #region GetCurrentRowId - - [TestMethod] - public void TestOptionObject2015Decorator_GetCurrentRowId_Expected() { - var expected = "456||1"; - RowObject rowObject = new() { - RowId = expected - }; - FormObject formObject = new() { - FormId = "456", - CurrentRow = rowObject - }; - OptionObject2015 optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObject2015Decorator decorator = new(optionObject); - Assert.AreEqual(expected, decorator.GetCurrentRowId("456")); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetCurrentRowId_Exception() { - FormObject formObject = new() { - FormId = "456" - }; - OptionObject2015 optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObject2015Decorator decorator = new(optionObject); - Assert.ThrowsException(() => decorator.GetCurrentRowId("456")); - } - - #endregion - - #region GetFieldValue - - - [TestMethod] - public void TestOptionObject2015Decorator_GetFieldValue_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetFieldValue_NotPresent() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetFieldValue("678.90")); - } - - #endregion - - #region GetFieldValues - - [TestMethod] - public void TestOptionObject2015Decorator_GetFieldValues_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.AreEqual(1, decorator.GetFieldValues(fieldNumber).Count); - Assert.AreEqual(expected, decorator.GetFieldValues(fieldNumber)[0]); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetFieldValues_MultipleRows_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var expected2 = "initial value 2"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected2, - Lock = "0", - Required = "0" - }; - var rowObject2 = new RowObject() - { - Fields = [fieldObject2], - RowId = "456||2", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2], - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.AreEqual(2, decorator.GetFieldValues(fieldNumber).Count); - Assert.AreEqual(expected, decorator.GetFieldValues(fieldNumber)[0]); - Assert.AreEqual(expected2, decorator.GetFieldValues(fieldNumber)[1]); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetFieldValues_NotPresent() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.AreEqual(0, decorator.GetFieldValues("457||1").Count); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetFieldValues_Empty() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetFieldValues("")); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetFieldValues_Null() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetFieldValues(null)); - } - - #endregion - - #region GetMultipleIterationStatus - - [TestMethod] - public void TestOptionObject2015Decorator_GetMultipleIterationStatus_ReturnsBool() - { - var formId = "456"; - var expected = false; - var formObject = new FormObject() - { - FormId = formId - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.AreEqual(expected.GetType(), decorator.GetMultipleIterationStatus(formId).GetType()); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetMultipleIterationStatus_ReturnsFalse() - { - var formId = "456"; - var formObject = new FormObject() - { - FormId = formId - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.GetMultipleIterationStatus(formId)); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetMultipleIterationStatus_ReturnsTrue() - { - var formId = "456"; - var formObject = new FormObject() - { - FormId = formId, - MultipleIteration = true - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsTrue(decorator.GetMultipleIterationStatus(formId)); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetMultipleIterationStatus_ReturnsFormObjectNotFoundException() - { - var formId = "456"; - var formObject = new FormObject() - { - FormId = "123", - MultipleIteration = true - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetMultipleIterationStatus(formId)); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetMultipleIterationStatus_NoForms_ReturnsFormObjectNotFoundException() - { - var formId = "456"; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetMultipleIterationStatus(formId)); - } - - #endregion - - #region GetParentRowId - - [TestMethod] - public void TestOptionObject2015Decorator_GetParentRowId_Expected() { - var expected = "456||1"; - RowObject rowObject = new() { - RowId = "456||3", - ParentRowId = expected - }; - FormObject formObject = new() { - FormId = "456", - CurrentRow = rowObject - }; - OptionObject2015 optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObject2015Decorator decorator = new(optionObject); - Assert.AreEqual(expected, decorator.GetParentRowId("456")); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetParentRowId_Exception() { - FormObject formObject = new() { - FormId = "456" - }; - OptionObject2015 optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObject2015Decorator decorator = new(optionObject); - Assert.ThrowsException(() => decorator.GetParentRowId("456")); - } - - [TestMethod] - public void TestOptionObject2015Decorator_GetParentRowId_Null() { - RowObject rowObject = new() { - RowId = "456||3", - }; - FormObject formObject = new() { - FormId = "456", - CurrentRow = rowObject - }; - OptionObject2015 optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObject2015Decorator decorator = new(optionObject); - Assert.IsNull(decorator.GetParentRowId("456")); - } - - #endregion - - #region IsFieldEnabled - - [TestMethod] - public void IsFieldEnabled_OptionObject2015_FirstForm_IsEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject2015_SecondForm_IsEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject2015_FirstForm_IsNotEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject2015_SecondForm_IsNotEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject2015_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsFieldEnabled("678.90")); - } - - #endregion - - #region IsFieldLocked - - [TestMethod] - public void IsFieldLocked_OptionObject2015_FirstForm_IsLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "1", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject2015_SecondForm_IsLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "1", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject2015_FirstForm_IsNotLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject2015_SecondForm_IsNotLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject2015_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsFieldLocked("678.90")); - } - - #endregion - - #region IsFieldModified - - [TestMethod] - public void IsFieldModified_OptionObject2015_IsFalse() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - RowId = "1||1", - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - OptionObject2015 optionObject = new() { - Forms = [formObject] - }; - OptionObject2015Decorator decorator = new(optionObject); - Assert.IsFalse(decorator.IsFieldModified("123")); - } - - [TestMethod] - public void IsFieldModified_OptionObject2015_IsTrue() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - RowId = "1||1", - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - OptionObject2015 optionObject = new() { - Forms = [formObject] - }; - OptionObject2015Decorator decorator = new(optionObject); - decorator.SetFieldValue("123", "MODIFIED"); - Assert.IsTrue(decorator.IsFieldModified("123")); - } - - [TestMethod] - public void IsFieldModified_OptionObject2015_IsFalse_NullFieldNumber() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - RowId = "1||1", - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - OptionObject2015 optionObject = new() { - Forms = [formObject] - }; - OptionObject2015Decorator decorator = new(optionObject); - Assert.ThrowsException(() => decorator.IsFieldModified(null)); - } - - #endregion - - #region IsFieldPresent - - [TestMethod] - public void TestOptionObject2015Decorator_FieldIsPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldPresent("123.45")); - } - - [TestMethod] - public void TestOptionObject2015Decorator_FieldIsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldPresent("678.90")); - } - - #endregion - - #region IsFieldRequired - - [TestMethod] - public void IsFieldRequired_OptionObject2015_FirstForm_IsRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "1" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject2015_SecondForm_IsRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "1" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject2015_FirstForm_IsNotRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject2015_SecondForm_IsNotRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject2015_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsFieldRequired("678.90")); - } - - #endregion - - #region IsFormPresent - - [TestMethod] - public void IsFormPresent_Expected() - { - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsTrue(decorator.IsFormPresent("123")); - Assert.IsTrue(decorator.IsFormPresent("456")); - Assert.IsFalse(decorator.IsFormPresent("789")); - } - - [TestMethod] - public void IsFormPresent_NoForms_Expected() - { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.IsFormPresent("123")); - } - - [TestMethod] - public void IsFormPresent_Null() - { - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsFormPresent(null)); - } - - #endregion - - #region IsRowMarkedForDeletion - - [TestMethod] - public void IsRowMarkedForDeletion_Expected() - { - var rowObject1 = new RowObject() - { - RowId = "456||1" - }; - var rowObject2 = new RowObject() - { - RowId = "456||2", - RowAction = RowActions.Delete - }; - var formObject = new FormObject() - { - CurrentRow = rowObject1, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2] - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.IsRowMarkedForDeletion("456||1")); - Assert.IsTrue(decorator.IsRowMarkedForDeletion("456||2")); - } - - [TestMethod] - public void IsRowMarkedForDeletion_NullRowId() - { - var rowObject1 = new RowObject() - { - RowId = "456||1" - }; - var rowObject2 = new RowObject() - { - RowId = "456||2", - RowAction = RowActions.Delete - }; - var formObject = new FormObject() - { - CurrentRow = rowObject1, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2] - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsRowMarkedForDeletion(null)); - } - - #endregion - - #region DeleteRowObject - - [TestMethod] - public void TestOptionObject2015Decorator_DeleteRowObject_CurrentRow() - { - var rowObject = new RowObject() - { - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DeleteRowObject("456", "456||1"); - Assert.AreEqual(RowActions.Delete, decorator.Forms[0].CurrentRow.RowAction); - } - - [TestMethod] - public void TestOptionObject2015Decorator_DeleteRowObject_Errors() - { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.DeleteRowObject(null, "1||1")); - Assert.ThrowsException(() => decorator.DeleteRowObject("456", null)); - Assert.ThrowsException(() => decorator.DeleteRowObject("999", "1||1")); - } - - [TestMethod] - public void TestOptionObject2015Decorator_DeleteRowObject_OtherRow() - { - var row1 = new RowObject() { RowId = "456||1" }; - var row2 = new RowObject() { RowId = "456||2" }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = row1, - MultipleIteration = true, - OtherRows = [row2] - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DeleteRowObject("456", "456||2"); - Assert.AreEqual(RowActions.Delete, decorator.Forms[0].OtherRows[0].RowAction); - } - - #endregion - - #region IsRowPresent - - [TestMethod] - public void IsRowPresent_Expected() - { - var rowObject = new RowObject() - { - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsTrue(decorator.IsRowPresent("456||1")); - } - - [TestMethod] - public void IsRowPresent_NoForms_Expected() - { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsFalse(decorator.IsRowPresent("123||1")); - } - - [TestMethod] - public void IsRowPresent_Null() - { - var rowObject = new RowObject() - { - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsRowPresent(null)); - } - - #endregion - - #region SetFieldValue - - [TestMethod] - public void TestOptionObject2015Decorator_SetFieldValue_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "modified value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.SetFieldValue(fieldNumber, expected); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - } - - [TestMethod] - public void TestOptionObject2015Decorator_SetFieldValue_ReturnsExpectedForms() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.SetFieldValue("123.45", "modified value"); - var actual = decorator.Return().AsOptionObject2015(); - Assert.AreEqual(1, actual.Forms.Count); - } - - [TestMethod] - public void TestOptionObject2015Decorator_SetFieldValue_WithFormAndRowIds_ReturnsExpectedForms() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.SetFieldValue("456", "456||1", "123.45", "modified value"); - var actual = decorator.Return().AsOptionObject2015(); - Assert.AreEqual(1, actual.Forms.Count); - } - - #endregion - - #region AddRowObject - - [TestMethod] - public void TestOptionObject2015Decorator_AddRowObject_Success() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - var rowObject = new RowObject(); - decorator.AddRowObject("1", rowObject); - Assert.IsNotNull(decorator.Forms[0].CurrentRow); - Assert.AreEqual("1||1", decorator.Forms[0].CurrentRow.RowId); - } - - [TestMethod] - public void TestOptionObject2015Decorator_AddRowObject_FormNotFound() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - var rowObject = new RowObject(); - Assert.ThrowsException(() => decorator.AddRowObject("99", rowObject)); - } - - [TestMethod] - public void TestOptionObject2015Decorator_AddRowObject_NullRowObject() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.AddRowObject("1", null)); - } - - [TestMethod] - public void TestOptionObject2015Decorator_AddRowObject_WithMultipleRows() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.AddRowObject("1", new RowObject()); - decorator.AddRowObject("1", new RowObject()); - Assert.AreEqual(1, decorator.Forms[0].OtherRows.Count); - Assert.AreEqual("1||2", decorator.Forms[0].OtherRows[0].RowId); - } - - #endregion - - #region Edge Case Tests - Regression & Coverage - - [TestMethod] - public void TestOptionObject2015Decorator_Constructor_WithEmptyFormsCollection() - { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.IsNotNull(decorator.Forms); - Assert.AreEqual(0, decorator.Forms.Count); - } - - #endregion - - #region DisableAllFieldObjects - - [TestMethod] - public void DisableAllFieldObjects_AllFieldsDisabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_WithExcludedFields() - { - var fieldObject1 = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = "124", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject1, fieldObject2], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DisableAllFieldObjects(new List { "123" }); - Assert.IsTrue(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[1].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_NullExcludedFieldsList_ThrowsException() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.DisableAllFieldObjects(null)); - } - - [TestMethod] - public void DisableAllFieldObjects_EmptyForms_ThrowsException() - { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObject2015Decorator(optionObject); - Assert.ThrowsException(() => decorator.DisableAllFieldObjects()); - } - - [TestMethod] - public void DisableAllFieldObjects_NullForms_ThrowsException() - { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.Forms = null; - Assert.ThrowsException(() => decorator.DisableAllFieldObjects()); - } - - [TestMethod] - public void DisableAllFieldObjects_NullForms_WithExclusionList_ThrowsException() - { - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.Forms = null; - Assert.ThrowsException(() => decorator.DisableAllFieldObjects(new List())); - } - - [TestMethod] - public void DisableAllFieldObjects_EmptyExclusionList() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DisableAllFieldObjects(new List()); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_PreservesSessionToken() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - SessionToken = "SESSIONTOKEN123", - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("SESSIONTOKEN123", decorator.SessionToken); - } - - [TestMethod] - public void DisableAllFieldObjects_PreservesNamespaceName() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - NamespaceName = "NAMESPACE", - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("NAMESPACE", decorator.NamespaceName); - } - - [TestMethod] - public void DisableAllFieldObjects_MultipleIterationForm() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var otherRow = new RowObject() - { - Fields = [fieldObject], - RowId = "2", - ParentRowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true, - OtherRows = [otherRow] - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.Forms[0].OtherRows[0].Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_SetsRowActionToEdit() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1", - RowAction = "" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("EDIT", decorator.Forms[0].CurrentRow.RowAction); - } - - [TestMethod] - public void DisableAllFieldObjects_PreservesExistingRowAction() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1", - RowAction = "DELETE" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("DELETE", decorator.Forms[0].CurrentRow.RowAction); - } - - [TestMethod] - public void DisableAllFieldObjects_WithNullCurrentRow() - { - var formObject = new FormObject() - { - FormId = "1" - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsNull(decorator.Forms[0].CurrentRow); - } - - [TestMethod] - public void DisableAllFieldObjects_NonMultipleIterationForm() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var otherRow = new RowObject() - { - Fields = [fieldObject], - RowId = "2", - ParentRowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject, - MultipleIteration = false, - OtherRows = [otherRow] - }; - var optionObject = new OptionObject2015() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2015Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - Assert.IsFalse(decorator.Forms[0].OtherRows[0].Fields[0].Enabled); - } - - #endregion -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/OptionObject2DecoratorTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/OptionObject2DecoratorTests.cs deleted file mode 100644 index d6231509..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/OptionObject2DecoratorTests.cs +++ /dev/null @@ -1,2125 +0,0 @@ -using RarelySimple.AvatarScriptLink.Net.Decorators; -using RarelySimple.AvatarScriptLink.Net.Exceptions; -using RarelySimple.AvatarScriptLink.Objects; -using static RarelySimple.AvatarScriptLink.Objects.RowObject; - -namespace RarelySimple.AvatarScriptLink.Net.Tests.Decorators; - -[TestClass] -public class OptionObject2DecoratorTests -{ - #region Constructor - - [TestMethod] - public void TestOptionObject2Decorator_Constructor_NullOptionObject() - { - Assert.ThrowsException(() => new OptionObject2Decorator(null)); - } - - #endregion - - [TestMethod] - public void TestOptionObject2Decorator_ReturnsNoForms() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - var actual = decorator.Return().AsOptionObject2(); - Assert.AreEqual(0, actual.Forms.Count); - } - - #region AddFormObject - - [TestMethod] - public void AddFormObject_Expected() { - var expected = new FormObject() { - FormId = "1" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.AddFormObject(expected); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectDecorator_Expected() { - var expected = FormObjectDecorator.Builder().FormId("1").Build(); - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.AddFormObject(expected); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectById_Expected() { - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.AddFormObject("1"); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_Expected() { - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.AddFormObject("1", false); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_ArgumentNullException() { - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject(null, false)); - } - - [TestMethod] - public void AddFormObject_MICannotBeFirst() { - var expected = new FormObject() { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectDecorator_MICannotBeFirst() { - var expected = FormObjectDecorator.Builder().FormId("1").MultipleIteration().Build(); - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_MICannotBeFirst() { - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject("1", true)); - } - - [TestMethod] - public void AddFormObject_DuplicateForms() { - var expected = new FormObject() { - FormId = "1" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.AddFormObject(expected); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectDecorator_DuplicateForms() { - var expected = FormObjectDecorator.Builder().FormId("1").Build(); - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.AddFormObject(expected); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectById_DuplicateForms() { - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.AddFormObject("1"); - Assert.ThrowsException(() => decorator.AddFormObject("1")); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_DuplicateForms() { - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.AddFormObject("1", false); - Assert.ThrowsException(() => decorator.AddFormObject("1", false)); - } - - #endregion - - #region GetCurrentRowId - - [TestMethod] - public void TestOptionObject2Decorator_GetCurrentRowId_Expected() { - var expected = "456||1"; - RowObject rowObject = new() { - RowId = expected - }; - FormObject formObject = new() { - FormId = "456", - CurrentRow = rowObject - }; - OptionObject2 optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObject2Decorator decorator = new(optionObject); - Assert.AreEqual(expected, decorator.GetCurrentRowId("456")); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetCurrentRowId_Exception() { - FormObject formObject = new() { - FormId = "456" - }; - OptionObject2 optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObject2Decorator decorator = new(optionObject); - Assert.ThrowsException(() => decorator.GetCurrentRowId("456")); - } - - #endregion - - #region GetFieldValue - - - [TestMethod] - public void TestOptionObject2Decorator_GetFieldValue_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetFieldValue_NotPresent() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetFieldValue("678.90")); - } - - #endregion - - #region GetFieldValues - - [TestMethod] - public void TestOptionObject2Decorator_GetFieldValues_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.AreEqual(1, decorator.GetFieldValues(fieldNumber).Count); - Assert.AreEqual(expected, decorator.GetFieldValues(fieldNumber)[0]); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetFieldValues_MultipleRows_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var expected2 = "initial value 2"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected2, - Lock = "0", - Required = "0" - }; - var rowObject2 = new RowObject() - { - Fields = [fieldObject2], - RowId = "456||2", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2], - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.AreEqual(2, decorator.GetFieldValues(fieldNumber).Count); - Assert.AreEqual(expected, decorator.GetFieldValues(fieldNumber)[0]); - Assert.AreEqual(expected2, decorator.GetFieldValues(fieldNumber)[1]); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetFieldValues_NotPresent() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.AreEqual(0, decorator.GetFieldValues("457||1").Count); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetFieldValues_Empty() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetFieldValues("")); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetFieldValues_Null() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetFieldValues(null)); - } - - #endregion - - #region GetMultipleIterationStatus - - [TestMethod] - public void TestOptionObject2Decorator_GetMultipleIterationStatus_ReturnsBool() - { - var formId = "456"; - var expected = false; - var formObject = new FormObject() - { - FormId = formId - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.AreEqual(expected.GetType(), decorator.GetMultipleIterationStatus(formId).GetType()); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetMultipleIterationStatus_ReturnsFalse() - { - var formId = "456"; - var formObject = new FormObject() - { - FormId = formId - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.GetMultipleIterationStatus(formId)); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetMultipleIterationStatus_ReturnsTrue() - { - var formId = "456"; - var formObject = new FormObject() - { - FormId = formId, - MultipleIteration = true - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsTrue(decorator.GetMultipleIterationStatus(formId)); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetMultipleIterationStatus_ReturnsFormObjectNotFoundException() - { - var formId = "456"; - var formObject = new FormObject() - { - FormId = "123", - MultipleIteration = true - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetMultipleIterationStatus(formId)); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetMultipleIterationStatus_NoForms_ReturnsFormObjectNotFoundException() - { - var formId = "456"; - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetMultipleIterationStatus(formId)); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetMultipleIterationStatus_ReturnsArgumentNullException() - { - var formObject = new FormObject() - { - FormId = "123", - MultipleIteration = true - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.GetMultipleIterationStatus(null)); - } - - #endregion - - #region GetParentRowId - - [TestMethod] - public void TestOptionObject2Decorator_GetParentRowId_Expected() { - var expected = "456||1"; - RowObject rowObject = new() { - RowId = "456||3", - ParentRowId = expected - }; - FormObject formObject = new() { - FormId = "456", - CurrentRow = rowObject - }; - OptionObject2 optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObject2Decorator decorator = new(optionObject); - Assert.AreEqual(expected, decorator.GetParentRowId("456")); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetParentRowId_Exception() { - FormObject formObject = new() { - FormId = "456" - }; - OptionObject2 optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObject2Decorator decorator = new(optionObject); - Assert.ThrowsException(() => decorator.GetParentRowId("456")); - } - - [TestMethod] - public void TestOptionObject2Decorator_GetParentRowId_Null() { - RowObject rowObject = new() { - RowId = "456||3", - }; - FormObject formObject = new() { - FormId = "456", - CurrentRow = rowObject - }; - OptionObject2 optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObject2Decorator decorator = new(optionObject); - Assert.IsNull(decorator.GetParentRowId("456")); - } - - #endregion - - #region IsFieldEnabled - - [TestMethod] - public void IsFieldEnabled_OptionObject2_FirstForm_IsEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject2_SecondForm_IsEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject2_FirstForm_IsNotEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject2_SecondForm_IsNotEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject2_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsFieldEnabled("678.90")); - } - - #endregion - - #region IsFieldLocked - - [TestMethod] - public void IsFieldLocked_OptionObject2_FirstForm_IsLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "1", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject2_SecondForm_IsLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "1", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject2_FirstForm_IsNotLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject2_SecondForm_IsNotLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject2_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsFieldLocked("678.90")); - } - - #endregion - - #region IsFieldModified - - [TestMethod] - public void IsFieldModified_OptionObject2_IsFalse() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - RowId = "1||1", - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - OptionObject2 optionObject = new() { - Forms = [formObject] - }; - OptionObject2Decorator decorator = new(optionObject); - Assert.IsFalse(decorator.IsFieldModified("123")); - } - - [TestMethod] - public void IsFieldModified_OptionObject2_IsTrue() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - RowId = "1||1", - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - OptionObject2 optionObject = new() { - Forms = [formObject] - }; - OptionObject2Decorator decorator = new(optionObject); - decorator.SetFieldValue("123", "MODIFIED"); - Assert.IsTrue(decorator.IsFieldModified("123")); - } - - [TestMethod] - public void IsFieldModified_OptionObject2_IsFalse_NullFieldNumber() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - RowId = "1||1", - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - OptionObject2 optionObject = new() { - Forms = [formObject] - }; - OptionObject2Decorator decorator = new(optionObject); - Assert.ThrowsException(() => decorator.IsFieldModified(null)); - } - - #endregion - - #region IsFieldPresent - - [TestMethod] - public void TestOptionObject2Decorator_FieldIsPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldPresent("123.45")); - } - - [TestMethod] - public void TestOptionObject2Decorator_FieldIsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldPresent("678.90")); - } - - #endregion - - #region IsFieldRequired - - [TestMethod] - public void IsFieldRequired_OptionObject2_FirstForm_IsRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "1" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject2_SecondForm_IsRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "1" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsTrue(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject2_FirstForm_IsNotRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject2_SecondForm_IsNotRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject2_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsFieldRequired("678.90")); - } - - #endregion - - #region IsFormPresent - - [TestMethod] - public void IsFormPresent_Expected() - { - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsTrue(decorator.IsFormPresent("123")); - Assert.IsTrue(decorator.IsFormPresent("456")); - Assert.IsFalse(decorator.IsFormPresent("789")); - } - - [TestMethod] - public void IsFormPresent_NoForms_Expected() - { - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.IsFormPresent("123")); - } - - [TestMethod] - public void IsFormPresent_Null() - { - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsFormPresent(null)); - } - - #endregion - - #region IsRowMarkedForDeletion - - [TestMethod] - public void IsRowMarkedForDeletion_Expected() - { - var rowObject1 = new RowObject() - { - RowId = "456||1" - }; - var rowObject2 = new RowObject() - { - RowId = "456||2", - RowAction = RowActions.Delete - }; - var formObject = new FormObject() - { - CurrentRow = rowObject1, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2] - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.IsRowMarkedForDeletion("456||1")); - Assert.IsTrue(decorator.IsRowMarkedForDeletion("456||2")); - } - - [TestMethod] - public void IsRowMarkedForDeletion_NullRowId() - { - var rowObject1 = new RowObject() - { - RowId = "456||1" - }; - var rowObject2 = new RowObject() - { - RowId = "456||2", - RowAction = RowActions.Delete - }; - var formObject = new FormObject() - { - CurrentRow = rowObject1, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2] - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsRowMarkedForDeletion(null)); - } - - #endregion - - #region DeleteRowObject - - [TestMethod] - public void TestOptionObject2Decorator_DeleteRowObject_CurrentRow() - { - var rowObject = new RowObject() - { - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DeleteRowObject("456", "456||1"); - Assert.AreEqual(RowActions.Delete, decorator.Forms[0].CurrentRow.RowAction); - } - - [TestMethod] - public void TestOptionObject2Decorator_DeleteRowObject_Errors() - { - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.DeleteRowObject(null, "1||1")); - Assert.ThrowsException(() => decorator.DeleteRowObject("456", null)); - Assert.ThrowsException(() => decorator.DeleteRowObject("999", "1||1")); - } - - [TestMethod] - public void TestOptionObject2Decorator_DeleteRowObject_OtherRow() - { - var row1 = new RowObject() { RowId = "456||1" }; - var row2 = new RowObject() { RowId = "456||2" }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = row1, - MultipleIteration = true, - OtherRows = [row2] - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DeleteRowObject("456", "456||2"); - Assert.AreEqual(RowActions.Delete, decorator.Forms[0].OtherRows[0].RowAction); - } - - #endregion - - #region IsRowPresent - - [TestMethod] - public void IsRowPresent_Expected() - { - var rowObject = new RowObject() - { - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsTrue(decorator.IsRowPresent("456||1")); - } - - [TestMethod] - public void IsRowPresent_NoForms_Expected() - { - var optionObject = new OptionObject2() - { - OptionId = "TEST123" - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsFalse(decorator.IsRowPresent("123||1")); - } - - [TestMethod] - public void IsRowPresent_Null() - { - var rowObject = new RowObject() - { - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.IsRowPresent(null)); - } - - #endregion - - #region SetFieldValue - - [TestMethod] - public void TestOptionObject2Decorator_SetFieldValue_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "modified value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.SetFieldValue(fieldNumber, expected); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - } - - [TestMethod] - public void TestOptionObject2Decorator_SetFieldValue_ReturnsExpectedForms() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.SetFieldValue("123.45", "modified value"); - var actual = decorator.Return().AsOptionObject2(); - Assert.AreEqual(1, actual.Forms.Count); - } - - [TestMethod] - public void TestOptionObject2Decorator_SetFieldValue_WithFormAndRowIds_ReturnsExpectedForms() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.SetFieldValue("456", "456||1", "123.45", "modified value"); - var actual = decorator.Return().AsOptionObject2(); - Assert.AreEqual(1, actual.Forms.Count); - } - - #endregion - - #region AddRowObject - - [TestMethod] - public void TestOptionObject2Decorator_AddRowObject_Success() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - var rowObject = new RowObject(); - decorator.AddRowObject("1", rowObject); - Assert.IsNotNull(decorator.Forms[0].CurrentRow); - Assert.AreEqual("1||1", decorator.Forms[0].CurrentRow.RowId); - } - - [TestMethod] - public void TestOptionObject2Decorator_AddRowObject_FormNotFound() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - var rowObject = new RowObject(); - Assert.ThrowsException(() => decorator.AddRowObject("99", rowObject)); - } - - [TestMethod] - public void TestOptionObject2Decorator_AddRowObject_NullRowObject() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.AddRowObject("1", null)); - } - - [TestMethod] - public void TestOptionObject2Decorator_AddRowObject_WithMultipleRows() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.AddRowObject("1", new RowObject()); - decorator.AddRowObject("1", new RowObject()); - Assert.AreEqual(1, decorator.Forms[0].OtherRows.Count); - Assert.AreEqual("1||2", decorator.Forms[0].OtherRows[0].RowId); - } - - #endregion - - #region Edge Case Tests - Regression & Coverage - - [TestMethod] - public void TestOptionObject2Decorator_Constructor_WithEmptyFormsCollection() - { - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.IsNotNull(decorator.Forms); - Assert.AreEqual(0, decorator.Forms.Count); - } - - #endregion - - #region DisableAllFieldObjects - - [TestMethod] - public void DisableAllFieldObjects_AllFieldsDisabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_WithExcludedFields() - { - var fieldObject1 = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = "124", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject1, fieldObject2], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DisableAllFieldObjects(new List { "123" }); - Assert.IsTrue(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[1].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_NullExcludedFieldsList_ThrowsException() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.DisableAllFieldObjects(null)); - } - - [TestMethod] - public void DisableAllFieldObjects_EmptyForms_ThrowsException() - { - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObject2Decorator(optionObject); - Assert.ThrowsException(() => decorator.DisableAllFieldObjects()); - } - - [TestMethod] - public void DisableAllFieldObjects_NullForms_ThrowsException() - { - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.Forms = null; - Assert.ThrowsException(() => decorator.DisableAllFieldObjects()); - } - - [TestMethod] - public void DisableAllFieldObjects_NullForms_WithExclusionList_ThrowsException() - { - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.Forms = null; - Assert.ThrowsException(() => decorator.DisableAllFieldObjects(new List())); - } - - [TestMethod] - public void DisableAllFieldObjects_EmptyExclusionList() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DisableAllFieldObjects(new List()); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_PreservesNamespaceName() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - NamespaceName = "NAMESPACE", - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("NAMESPACE", decorator.NamespaceName); - } - - [TestMethod] - public void DisableAllFieldObjects_PreservesServerName() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - ServerName = "SERVERNAME", - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("SERVERNAME", decorator.ServerName); - } - - [TestMethod] - public void DisableAllFieldObjects_MultipleIterationForm() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var otherRow = new RowObject() - { - Fields = [fieldObject], - RowId = "2", - ParentRowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true, - OtherRows = [otherRow] - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.Forms[0].OtherRows[0].Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_SetsRowActionToEdit() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1", - RowAction = "" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("EDIT", decorator.Forms[0].CurrentRow.RowAction); - } - - [TestMethod] - public void DisableAllFieldObjects_PreservesExistingRowAction() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1", - RowAction = "DELETE" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("DELETE", decorator.Forms[0].CurrentRow.RowAction); - } - - [TestMethod] - public void DisableAllFieldObjects_WithNullCurrentRow() - { - var formObject = new FormObject() - { - FormId = "1" - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsNull(decorator.Forms[0].CurrentRow); - } - - [TestMethod] - public void DisableAllFieldObjects_NonMultipleIterationForm() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var otherRow = new RowObject() - { - Fields = [fieldObject], - RowId = "2", - ParentRowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject, - MultipleIteration = false, - OtherRows = [otherRow] - }; - var optionObject = new OptionObject2() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObject2Decorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - Assert.IsFalse(decorator.Forms[0].OtherRows[0].Fields[0].Enabled); - } - - #endregion -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/OptionObjectDecoratorTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/OptionObjectDecoratorTests.cs deleted file mode 100644 index 4f974cf6..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/OptionObjectDecoratorTests.cs +++ /dev/null @@ -1,2124 +0,0 @@ -using RarelySimple.AvatarScriptLink.Net.Decorators; -using RarelySimple.AvatarScriptLink.Net.Exceptions; -using RarelySimple.AvatarScriptLink.Objects; -using static RarelySimple.AvatarScriptLink.Objects.RowObject; - -namespace RarelySimple.AvatarScriptLink.Net.Tests.Decorators; - -[TestClass] -public class OptionObjectDecoratorTests -{ - #region Constructor - - [TestMethod] - public void TestOptionObjectDecorator_Constructor_NullOptionObject() - { - Assert.ThrowsException(() => new OptionObjectDecorator(null)); - } - - #endregion - - [TestMethod] - public void TestOptionObjectDecorator_ReturnsNoForms() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - var actual = decorator.Return().AsOptionObject(); - Assert.AreEqual(0, actual.Forms.Count); - } - - #region AddFormObject - - [TestMethod] - public void AddFormObject_Expected() { - var expected = new FormObject() { - FormId = "1" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.AddFormObject(expected); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectDecorator_Expected() { - var expected = FormObjectDecorator.Builder().FormId("1").Build(); - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.AddFormObject(expected); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectById_Expected() { - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.AddFormObject("1"); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_Expected() { - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.AddFormObject("1", false); - Assert.IsTrue(decorator.IsFormPresent("1")); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_ArgumentNullException() { - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject(null, false)); - } - - [TestMethod] - public void AddFormObject_MICannotBeFirst() { - var expected = new FormObject() { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectDecorator_MICannotBeFirst() { - var expected = FormObjectDecorator.Builder().FormId("1").MultipleIteration().Build(); - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_MICannotBeFirst() { - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.AddFormObject("1", true)); - } - - [TestMethod] - public void AddFormObject_DuplicateForms() { - var expected = new FormObject() { - FormId = "1" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.AddFormObject(expected); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectDecorator_DuplicateForms() { - var expected = FormObjectDecorator.Builder().FormId("1").Build(); - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.AddFormObject(expected); - Assert.ThrowsException(() => decorator.AddFormObject(expected)); - } - - [TestMethod] - public void AddFormObjectById_DuplicateForms() { - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.AddFormObject("1"); - Assert.ThrowsException(() => decorator.AddFormObject("1")); - } - - [TestMethod] - public void AddFormObjectByIdAndMI_DuplicateForms() { - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.AddFormObject("1", false); - Assert.ThrowsException(() => decorator.AddFormObject("1", false)); - } - - #endregion - - #region GetCurrentRowId - - [TestMethod] - public void TestOptionObjectDecorator_GetCurrentRowId_Expected() { - var expected = "456||1"; - RowObject rowObject = new() { - RowId = expected - }; - FormObject formObject = new() { - FormId = "456", - CurrentRow = rowObject - }; - OptionObject optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObjectDecorator decorator = new(optionObject); - Assert.AreEqual(expected, decorator.GetCurrentRowId("456")); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetCurrentRowId_Exception() { - FormObject formObject = new() { - FormId = "456" - }; - OptionObject optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObjectDecorator decorator = new(optionObject); - Assert.ThrowsException(() => decorator.GetCurrentRowId("456")); - } - - #endregion - - #region GetFieldValue - - - [TestMethod] - public void TestOptionObjectDecorator_GetFieldValue_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetFieldValue_NotPresent() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.GetFieldValue("678.90")); - } - - #endregion - - #region GetFieldValues - - [TestMethod] - public void TestOptionObjectDecorator_GetFieldValues_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.AreEqual(1, decorator.GetFieldValues(fieldNumber).Count); - Assert.AreEqual(expected, decorator.GetFieldValues(fieldNumber)[0]); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetFieldValues_MultipleRows_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var expected2 = "initial value 2"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected2, - Lock = "0", - Required = "0" - }; - var rowObject2 = new RowObject() - { - Fields = [fieldObject2], - RowId = "456||2", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2], - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.AreEqual(2, decorator.GetFieldValues(fieldNumber).Count); - Assert.AreEqual(expected, decorator.GetFieldValues(fieldNumber)[0]); - Assert.AreEqual(expected2, decorator.GetFieldValues(fieldNumber)[1]); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetFieldValues_NotPresent() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.AreEqual(0, decorator.GetFieldValues("457||1").Count); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetFieldValues_Empty() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.GetFieldValues("")); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetFieldValues_Null() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1", - ParentRowId = "455||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.GetFieldValues(null)); - } - - #endregion - - #region GetMultipleIterationStatus - - [TestMethod] - public void TestOptionObjectDecorator_GetMultipleIterationStatus_ReturnsBool() - { - var formId = "456"; - var expected = false; - var formObject = new FormObject() - { - FormId = formId - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.AreEqual(expected.GetType(), decorator.GetMultipleIterationStatus(formId).GetType()); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetMultipleIterationStatus_ReturnsFalse() - { - var formId = "456"; - var formObject = new FormObject() - { - FormId = formId - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.GetMultipleIterationStatus(formId)); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetMultipleIterationStatus_ReturnsTrue() - { - var formId = "456"; - var formObject = new FormObject() - { - FormId = formId, - MultipleIteration = true - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsTrue(decorator.GetMultipleIterationStatus(formId)); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetMultipleIterationStatus_ReturnsFormObjectNotFoundException() - { - var formId = "456"; - var formObject = new FormObject() - { - FormId = "123", - MultipleIteration = true - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.GetMultipleIterationStatus(formId)); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetMultipleIterationStatus_NoForms_ReturnsFormObjectNotFoundException() - { - var formId = "456"; - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.GetMultipleIterationStatus(formId)); - } - - #endregion - - #region GetParentRowId - - [TestMethod] - public void TestOptionObjectDecorator_GetParentRowId_Expected() { - var expected = "456||1"; - RowObject rowObject = new() { - RowId = "456||3", - ParentRowId = expected - }; - FormObject formObject = new() { - FormId = "456", - CurrentRow = rowObject - }; - OptionObject optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObjectDecorator decorator = new(optionObject); - Assert.AreEqual(expected, decorator.GetParentRowId("456")); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetParentRowId_Exception() { - FormObject formObject = new() { - FormId = "456" - }; - OptionObject optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObjectDecorator decorator = new(optionObject); - Assert.ThrowsException(() => decorator.GetParentRowId("456")); - } - - [TestMethod] - public void TestOptionObjectDecorator_GetParentRowId_Null() { - RowObject rowObject = new() { - RowId = "456||3", - }; - FormObject formObject = new() { - FormId = "456", - CurrentRow = rowObject - }; - OptionObject optionObject = new() { - OptionId = "USER123", - Forms = [formObject] - }; - OptionObjectDecorator decorator = new(optionObject); - Assert.IsNull(decorator.GetParentRowId("456")); - } - - #endregion - - #region IsFieldEnabled - - [TestMethod] - public void IsFieldEnabled_OptionObject_FirstForm_IsEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsTrue(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject_SecondForm_IsEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsTrue(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject_FirstForm_IsNotEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject_SecondForm_IsNotEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_OptionObject_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.IsFieldEnabled("678.90")); - } - - #endregion - - #region IsFieldLocked - - [TestMethod] - public void IsFieldLocked_OptionObject_FirstForm_IsLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "1", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsTrue(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject_SecondForm_IsLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "1", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsTrue(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject_FirstForm_IsNotLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject_SecondForm_IsNotLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_OptionObject_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.IsFieldLocked("678.90")); - } - - #endregion - - #region IsFieldModified - - [TestMethod] - public void IsFieldModified_OptionObject_IsFalse() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - RowId = "1||1", - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - OptionObject optionObject = new() { - Forms = [formObject] - }; - OptionObjectDecorator decorator = new(optionObject); - Assert.IsFalse(decorator.IsFieldModified("123")); - } - - [TestMethod] - public void IsFieldModified_OptionObject_IsTrue() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - RowId = "1||1", - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - OptionObject optionObject = new() { - Forms = [formObject] - }; - OptionObjectDecorator decorator = new(optionObject); - decorator.SetFieldValue("123", "MODIFIED"); - Assert.IsTrue(decorator.IsFieldModified("123")); - } - - [TestMethod] - public void IsFieldModified_OptionObject_IsFalse_NullFieldNumber() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - RowId = "1||1", - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - FormObject formObject = new() { - FormId = "1", - CurrentRow = rowObject - }; - OptionObject optionObject = new() { - Forms = [formObject] - }; - OptionObjectDecorator decorator = new(optionObject); - Assert.ThrowsException(() => decorator.IsFieldModified(null)); - } - - #endregion - - #region IsFieldPresent - - [TestMethod] - public void TestOptionObjectDecorator_FieldIsPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsTrue(decorator.IsFieldPresent("123.45")); - } - - [TestMethod] - public void TestOptionObjectDecorator_FieldIsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.IsFieldPresent("678.90")); - } - - #endregion - - #region IsFieldRequired - - [TestMethod] - public void IsFieldRequired_OptionObject_FirstForm_IsRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "1" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsTrue(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject_SecondForm_IsRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "1" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsTrue(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject_FirstForm_IsNotRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject_SecondForm_IsNotRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_OptionObject_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.IsFieldRequired("678.90")); - } - - #endregion - - #region IsFormPresent - - [TestMethod] - public void IsFormPresent_Expected() - { - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsTrue(decorator.IsFormPresent("123")); - Assert.IsTrue(decorator.IsFormPresent("456")); - Assert.IsFalse(decorator.IsFormPresent("789")); - } - - [TestMethod] - public void IsFormPresent_NoForms_Expected() - { - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.IsFormPresent("123")); - } - - [TestMethod] - public void IsFormPresent_Null() - { - var formObject = new FormObject() - { - FormId = "123" - }; - var formObject2 = new FormObject() - { - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject,formObject2] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.IsFormPresent(null)); - } - - #endregion - - #region IsRowMarkedForDeletion - - [TestMethod] - public void IsRowMarkedForDeletion_Expected() - { - var rowObject1 = new RowObject() - { - RowId = "456||1" - }; - var rowObject2 = new RowObject() - { - RowId = "456||2", - RowAction = RowActions.Delete - }; - var formObject = new FormObject() - { - CurrentRow = rowObject1, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2] - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.IsRowMarkedForDeletion("456||1")); - Assert.IsTrue(decorator.IsRowMarkedForDeletion("456||2")); - } - - [TestMethod] - public void IsRowMarkedForDeletion_NullRowId() - { - var rowObject1 = new RowObject() - { - RowId = "456||1" - }; - var rowObject2 = new RowObject() - { - RowId = "456||2", - RowAction = RowActions.Delete - }; - var formObject = new FormObject() - { - CurrentRow = rowObject1, - FormId = "456", - MultipleIteration = true, - OtherRows = [rowObject2] - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.IsRowMarkedForDeletion(null)); - } - - #endregion - - #region DeleteRowObject - - [TestMethod] - public void TestOptionObjectDecorator_DeleteRowObject_CurrentRow() - { - var rowObject = new RowObject() - { - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DeleteRowObject("456", "456||1"); - Assert.AreEqual(RowActions.Delete, decorator.Forms[0].CurrentRow.RowAction); - } - - [TestMethod] - public void TestOptionObjectDecorator_DeleteRowObject_Errors() - { - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.DeleteRowObject(null, "1||1")); - Assert.ThrowsException(() => decorator.DeleteRowObject("456", null)); - Assert.ThrowsException(() => decorator.DeleteRowObject("999", "1||1")); - } - - [TestMethod] - public void TestOptionObjectDecorator_DeleteRowObject_OtherRow() - { - var row1 = new RowObject() { RowId = "456||1" }; - var row2 = new RowObject() { RowId = "456||2" }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = row1, - MultipleIteration = true, - OtherRows = [row2] - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DeleteRowObject("456", "456||2"); - Assert.AreEqual(RowActions.Delete, decorator.Forms[0].OtherRows[0].RowAction); - } - - #endregion - - #region IsRowPresent - - [TestMethod] - public void IsRowPresent_Expected() - { - var rowObject = new RowObject() - { - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsTrue(decorator.IsRowPresent("456||1")); - } - - [TestMethod] - public void IsRowPresent_NoForms_Expected() - { - var optionObject = new OptionObject() - { - OptionId = "TEST123" - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsFalse(decorator.IsRowPresent("123||1")); - } - - [TestMethod] - public void IsRowPresent_Null() - { - var rowObject = new RowObject() - { - RowId = "456||1" - }; - var formObject = new FormObject() - { - FormId = "456", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.IsRowPresent(null)); - } - - #endregion - - #region SetFieldValue - - [TestMethod] - public void TestOptionObjectDecorator_SetFieldValue_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "modified value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.SetFieldValue(fieldNumber, expected); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - } - - [TestMethod] - public void TestOptionObjectDecorator_SetFieldValue_ReturnsExpectedForms() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.SetFieldValue("123.45", "modified value"); - var actual = decorator.Return().AsOptionObject(); - Assert.AreEqual(1, actual.Forms.Count); - } - - [TestMethod] - public void TestOptionObjectDecorator_SetFieldValue_WithFormAndRowIds_ReturnsExpectedForms() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var formObject = new FormObject() - { - CurrentRow = rowObject, - FormId = "456" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.SetFieldValue("456", "456||1", "123.45", "modified value"); - var actual = decorator.Return().AsOptionObject(); - Assert.AreEqual(1, actual.Forms.Count); - } - - #endregion - - #region AddRowObject - - [TestMethod] - public void TestOptionObjectDecorator_AddRowObject_Success() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - var rowObject = new RowObject(); - decorator.AddRowObject("1", rowObject); - Assert.IsNotNull(decorator.Forms[0].CurrentRow); - Assert.AreEqual("1||1", decorator.Forms[0].CurrentRow.RowId); - } - - [TestMethod] - public void TestOptionObjectDecorator_AddRowObject_FormNotFound() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - var rowObject = new RowObject(); - Assert.ThrowsException(() => decorator.AddRowObject("99", rowObject)); - } - - [TestMethod] - public void TestOptionObjectDecorator_AddRowObject_NullRowObject() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.AddRowObject("1", null)); - } - - [TestMethod] - public void TestOptionObjectDecorator_AddRowObject_NullFormId() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - var rowObject = new RowObject(); - Assert.ThrowsException(() => decorator.AddRowObject(null, rowObject)); - } - - [TestMethod] - public void TestOptionObjectDecorator_AddRowObject_WithMultipleRows() - { - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.AddRowObject("1", new RowObject()); - decorator.AddRowObject("1", new RowObject()); - Assert.AreEqual(1, decorator.Forms[0].OtherRows.Count); - Assert.AreEqual("1||2", decorator.Forms[0].OtherRows[0].RowId); - } - - #endregion - - #region Edge Case Tests - Regression & Coverage - - [TestMethod] - public void TestOptionObjectDecorator_Constructor_WithEmptyFormsCollection() - { - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.IsNotNull(decorator.Forms); - Assert.AreEqual(0, decorator.Forms.Count); - } - - #endregion - - #region DisableAllFieldObjects - - [TestMethod] - public void DisableAllFieldObjects_AllFieldsDisabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_WithExcludedFields() - { - var fieldObject1 = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = "124", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject1, fieldObject2], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DisableAllFieldObjects(new List { "123" }); - Assert.IsTrue(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[1].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_EmptyExclusionList() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DisableAllFieldObjects(new List()); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_NullExcludedFieldsList_ThrowsException() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.DisableAllFieldObjects(null)); - } - - [TestMethod] - public void DisableAllFieldObjects_EmptyForms_ThrowsException() - { - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObjectDecorator(optionObject); - Assert.ThrowsException(() => decorator.DisableAllFieldObjects()); - } - - [TestMethod] - public void DisableAllFieldObjects_NullForms_ThrowsException() - { - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.Forms = null; - Assert.ThrowsException(() => decorator.DisableAllFieldObjects()); - } - - [TestMethod] - public void DisableAllFieldObjects_NullForms_WithExclusionList_ThrowsException() - { - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = new List() - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.Forms = null; - Assert.ThrowsException(() => decorator.DisableAllFieldObjects(new List())); - } - - [TestMethod] - public void DisableAllFieldObjects_PreservesEntityID() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - EntityID = "123456", - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("123456", decorator.EntityID); - } - - [TestMethod] - public void DisableAllFieldObjects_PreservesOptionId() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("TEST123", decorator.OptionId); - } - - [TestMethod] - public void DisableAllFieldObjects_MultipleIterationForm() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var otherRow = new RowObject() - { - Fields = [fieldObject], - RowId = "2", - ParentRowId = "1" - }; - var formObject = new FormObject() - { - FormId = "1", - MultipleIteration = true, - OtherRows = [otherRow] - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.Forms[0].OtherRows[0].Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_SetsRowActionToEdit() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1", - RowAction = "" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("EDIT", decorator.Forms[0].CurrentRow.RowAction); - } - - [TestMethod] - public void DisableAllFieldObjects_PreservesExistingRowAction() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1", - RowAction = "DELETE" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.AreEqual("DELETE", decorator.Forms[0].CurrentRow.RowAction); - } - - [TestMethod] - public void DisableAllFieldObjects_WithNullCurrentRow() - { - var formObject = new FormObject() - { - FormId = "1" - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsNull(decorator.Forms[0].CurrentRow); - } - - [TestMethod] - public void DisableAllFieldObjects_NonMultipleIterationForm() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var otherRow = new RowObject() - { - Fields = [fieldObject], - RowId = "2" - }; - var formObject = new FormObject() - { - FormId = "1", - CurrentRow = rowObject, - MultipleIteration = false, - OtherRows = [otherRow] - }; - var optionObject = new OptionObject() - { - OptionId = "TEST123", - Forms = [formObject] - }; - var decorator = new OptionObjectDecorator(optionObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.Forms[0].CurrentRow.Fields[0].Enabled); - Assert.IsFalse(decorator.Forms[0].OtherRows[0].Fields[0].Enabled); - } - - #endregion -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/RowObjectDecoratorTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/RowObjectDecoratorTests.cs deleted file mode 100644 index 1d6494ce..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/Decorators/RowObjectDecoratorTests.cs +++ /dev/null @@ -1,667 +0,0 @@ -using RarelySimple.AvatarScriptLink.Net.Decorators; -using RarelySimple.AvatarScriptLink.Net.Exceptions; -using RarelySimple.AvatarScriptLink.Objects; -using static RarelySimple.AvatarScriptLink.Objects.RowObject; - -namespace RarelySimple.AvatarScriptLink.Net.Tests.Decorators; - -[TestClass] -public class RowObjectDecoratorTests -{ - #region Constructor - - [TestMethod] - public void TestRowObjectDecorator_Constructor_NullRowObject() - { - Assert.ThrowsException(() => new RowObjectDecorator(null)); - } - - #endregion - - [TestMethod] - public void TestRowObjectDecorator_ReturnsNoFields() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - var actual = decorator.Return().AsRowObject(); - Assert.AreEqual(RowActions.None, actual.RowAction); - Assert.AreEqual(0, actual.Fields.Count); - } - - #region AddFieldObject - - [TestMethod] - public void TestRowObjectDecorator_AddFieldObject_Succeeds() - { - var fieldNumber = "123.45"; - var expected = "initial value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = expected, - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - decorator.AddFieldObject(fieldObject); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - } - - [TestMethod] - public void TestRowObjectDecorator_AddFieldObject_ReturnsExpectedFields() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.46", - FieldValue = "another field", - Lock = "0", - Required = "0" - }; - decorator.AddFieldObject(fieldObject2); - var actual = decorator.Return().AsRowObject(); - Assert.AreEqual(RowActions.Edit, actual.RowAction); - Assert.AreEqual(1, actual.Fields.Count); - } - - #endregion - - #region GetFieldValue - - [TestMethod] - public void TestRowObjectDecorator_GetFieldValue_Succeeds() - { - string fieldNumber = "123"; - string expected = "TEST"; - var fieldObject = new FieldObject() { - FieldNumber = fieldNumber, - FieldValue = expected - }; - var rowObject = new RowObject() { - RowId = "1||1", - Fields = [ fieldObject ] - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - Assert.AreEqual(expected.GetType(), decorator.GetFieldValue(fieldNumber).GetType()); - } - - #endregion - - #region IsFieldEnabled - - [TestMethod] - public void IsFieldEnabled_RowObject_IsEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.IsTrue(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_RowObject_IsNotEnabled() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.IsFalse(decorator.IsFieldEnabled("123.45")); - } - - [TestMethod] - public void IsFieldEnabled_RowObject_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.ThrowsException(() => decorator.IsFieldEnabled("678.90")); - } - - #endregion - - #region IsFieldLocked - - [TestMethod] - public void IsFieldLocked_RowObject_IsLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "1", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.IsTrue(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_RowObject_IsNotLocked() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.IsFalse(decorator.IsFieldLocked("123.45")); - } - - [TestMethod] - public void IsFieldLocked_RowObject_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.ThrowsException(() => decorator.IsFieldLocked("678.90")); - } - - #endregion - - #region IsFieldModified - - [TestMethod] - public void IsFieldModified_RowObject_IsFalse() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - RowObjectDecorator rowObject01 = new(rowObject); - Assert.IsFalse(rowObject01.IsFieldModified("123")); - } - - [TestMethod] - public void IsFieldModified_RowObject_IsTrue() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - RowObjectDecorator rowObject01 = new(rowObject); - rowObject01.SetFieldValue("123", "MODIFIED"); - Assert.IsTrue(rowObject01.IsFieldModified("123")); - } - - [TestMethod] - public void IsFieldModified_RowObject_IsFalse_NullFieldNumber() - { - FieldObject fieldObject01 = new() - { - FieldNumber = "123", - FieldValue = "" - }; - FieldObject fieldObject02 = new() - { - FieldNumber = "124", - FieldValue = "" - }; - FieldObject fieldObject03 = new() - { - FieldNumber = "125", - FieldValue = "" - }; - RowObject rowObject = new() { - Fields = [fieldObject01, fieldObject02, fieldObject03] - }; - RowObjectDecorator rowObject01 = new(rowObject); - Assert.ThrowsException(() => rowObject01.IsFieldModified(null)); - } - - #endregion - - #region IsFieldPresent - - [TestMethod] - public void TestRowObjectDecorator_FieldIsPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.IsTrue(decorator.IsFieldPresent("123.45")); - } - - [TestMethod] - public void TestRowObjectDecorator_FieldIsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.IsFalse(decorator.IsFieldPresent("678.90")); - } - - #endregion - - #region IsFieldRequired - - [TestMethod] - public void IsFieldRequired_RowObject_IsRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "1" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.IsTrue(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_RowObject_IsNotRequired() - { - var fieldObject = new FieldObject() - { - Enabled = "0", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.IsFalse(decorator.IsFieldRequired("123.45")); - } - - [TestMethod] - public void IsFieldRequired_RowObject_IsNotPresent() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.ThrowsException(() => decorator.IsFieldRequired("678.90")); - } - - #endregion - - #region SetFieldValue - - [TestMethod] - public void TestRowObjectDecorator_SetFieldValueSucceeds() - { - var fieldNumber = "123.45"; - var expected = "modified value"; - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = fieldNumber, - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [ fieldObject ], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - decorator.SetFieldValue(fieldNumber, expected); - Assert.AreEqual(expected, decorator.GetFieldValue(fieldNumber)); - } - - [TestMethod] - public void TestRowObjectDecorator_SetFieldValue_ReturnsExpectedFields() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123.45", - FieldValue = "initial value", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "456||1" - }; - var decorator = new RowObjectDecorator(rowObject); - decorator.SetFieldValue("123.45", "modified value"); - var actual = decorator.Return().AsRowObject(); - Assert.AreEqual(RowActions.Edit, actual.RowAction); - Assert.AreEqual(1, actual.Fields.Count); - } - - #endregion - - #region DisableAllFieldObjects - - [TestMethod] - public void DisableAllFieldObjects_NullExclusionList_ThrowsException() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var decorator = new RowObjectDecorator(rowObject); - Assert.ThrowsException(() => decorator.DisableAllFieldObjects(null)); - } - - [TestMethod] - public void DisableAllFieldObjects_DisablesAllFields() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var decorator = new RowObjectDecorator(rowObject); - decorator.DisableAllFieldObjects(new List()); - Assert.IsFalse(decorator.Fields[0].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_ExcludedFieldsRemainEnabled() - { - var fieldObject1 = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = "124", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject1, fieldObject2], - RowId = "1" - }; - var decorator = new RowObjectDecorator(rowObject); - decorator.DisableAllFieldObjects(new List { "123" }); - Assert.IsTrue(decorator.Fields[0].Enabled); - Assert.IsFalse(decorator.Fields[1].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_MultipleFields() - { - var fieldObject1 = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var fieldObject2 = new FieldObject() - { - Enabled = "1", - FieldNumber = "124", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var fieldObject3 = new FieldObject() - { - Enabled = "1", - FieldNumber = "125", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject1, fieldObject2, fieldObject3], - RowId = "1" - }; - var decorator = new RowObjectDecorator(rowObject); - decorator.DisableAllFieldObjects(new List { "124" }); - Assert.IsFalse(decorator.Fields[0].Enabled); - Assert.IsTrue(decorator.Fields[1].Enabled); - Assert.IsFalse(decorator.Fields[2].Enabled); - } - - [TestMethod] - public void DisableAllFieldObjects_SetsRowActionToEdit() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1", - RowAction = "" - }; - var decorator = new RowObjectDecorator(rowObject); - decorator.DisableAllFieldObjects(new List()); - Assert.AreEqual(RowActions.Edit, decorator.RowAction); - } - - [TestMethod] - public void DisableAllFieldObjects_PreservesExistingRowAction() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1", - RowAction = "DELETE" - }; - var decorator = new RowObjectDecorator(rowObject); - decorator.DisableAllFieldObjects(new List()); - Assert.AreEqual("DELETE", decorator.RowAction); - } - - [TestMethod] - public void DisableAllFieldObjects_WithoutExclusionList() - { - var fieldObject = new FieldObject() - { - Enabled = "1", - FieldNumber = "123", - FieldValue = "test", - Lock = "0", - Required = "0" - }; - var rowObject = new RowObject() - { - Fields = [fieldObject], - RowId = "1" - }; - var decorator = new RowObjectDecorator(rowObject); - decorator.DisableAllFieldObjects(); - Assert.IsFalse(decorator.Fields[0].Enabled); - Assert.AreEqual(RowActions.Edit, decorator.RowAction); - } - - #endregion -} \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/GlobalUsings.cs b/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/GlobalUsings.cs deleted file mode 100644 index ab67c7ea..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net.Tests/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/DecoratorHelper.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/DecoratorHelper.cs deleted file mode 100644 index ea10c6ca..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/DecoratorHelper.cs +++ /dev/null @@ -1,45 +0,0 @@ -using static RarelySimple.AvatarScriptLink.Objects.RowObject; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public abstract class DecoratorHelper - { - protected const string FieldNumberAlreadyExists = "fieldNumberAlreadyExists"; - protected const string FieldObjectAlreadyExists = "fieldObjectAlreadyExists"; - protected const string FormObjectMissingCurrentRow = "formObjectMissingCurrentRow"; - protected const string NoFieldObjectsFoundByFieldNumber = "noFieldObjectsFoundByFieldNumber"; - protected const string NoFormObjectsFoundByFormId = "noFormObjectsFoundByFormId"; - protected const string OptionObjectMissingForms = "optionObjectMissingForms"; - protected const string ParameterCannotBeNull = "parameterCannotBeNull"; - protected const string RowObjectMissingFields = "rowObjectMissingFields"; - protected const string UnableToIdentifyFieldObject = "unableToIdentifyFieldObject"; - - /// - /// Returns whether a supplied RowAction value is valid. - /// - /// - /// - public static bool IsValidRowAction(string rowAction) - { - if (rowAction == RowActions.Add || - rowAction == RowActions.Delete || - rowAction == RowActions.Edit || - string.IsNullOrEmpty(rowAction)) // same as == RowAction.None - return true; - return false; - } - /// - /// Returns whether a supplied RowAction value is valid for return. - /// - /// - /// - public static bool IsValidReturnRowAction(string rowAction) - { - if (rowAction == RowActions.Add || - rowAction == RowActions.Delete || - rowAction == RowActions.Edit) - return true; - return false; - } - } -} \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FieldObjectDecorator.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FieldObjectDecorator.cs deleted file mode 100644 index 9d23c98b..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FieldObjectDecorator.cs +++ /dev/null @@ -1,62 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects; -using System; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class FieldObjectDecorator - { - private readonly FieldObject _fieldObject; - - public bool Enabled { get; set; } - public string FieldNumber { get; } - public string FieldValue { get; set; } - public bool Locked { get; set; } - public bool Required { get; set; } - - public FieldObjectDecorator() - { - _fieldObject = FieldObject.Initialize(); - Enabled = false; - FieldNumber = string.Empty; - FieldValue = string.Empty; - Locked = false; - Required = false; - } - - public FieldObjectDecorator(string fieldNumber) - { - _fieldObject = FieldObject.Initialize(); - Enabled = false; - FieldNumber = fieldNumber; - FieldValue = string.Empty; - Locked = false; - Required = false; - } - - public FieldObjectDecorator(FieldObject fieldObject) - { - if (fieldObject == null) - throw new ArgumentNullException(nameof(fieldObject)); - _fieldObject = fieldObject; - Enabled = fieldObject.IsEnabled(); - FieldNumber = fieldObject.FieldNumber; - FieldValue = fieldObject.FieldValue; - Locked = fieldObject.IsLocked(); - Required = fieldObject.IsRequired(); - } - - public bool IsModified() - { - return Enabled != _fieldObject.IsEnabled() || - FieldNumber != _fieldObject.FieldNumber || - FieldValue != _fieldObject.FieldValue || - Locked != _fieldObject.IsLocked() || - Required != _fieldObject.IsRequired(); - } - - public FieldObjectDecoratorReturnBuilder Return() - { - return new FieldObjectDecoratorReturnBuilder(this); - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FieldObjectDecoratorReturnBuilder.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FieldObjectDecoratorReturnBuilder.cs deleted file mode 100644 index eac51048..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FieldObjectDecoratorReturnBuilder.cs +++ /dev/null @@ -1,28 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class FieldObjectDecorator - { - public class FieldObjectDecoratorReturnBuilder - { - private readonly FieldObjectDecorator _decorator; - - public FieldObjectDecoratorReturnBuilder(FieldObjectDecorator decorator) - { - _decorator = decorator; - } - - public FieldObject AsFieldObject() - { - var fieldObject = FieldObject.Initialize(); - fieldObject.Enabled = _decorator.Enabled ? "1" : "0"; - fieldObject.FieldNumber = _decorator.FieldNumber; - fieldObject.FieldValue = _decorator.FieldValue; - fieldObject.Lock = _decorator.Locked ? "1" : "0"; - fieldObject.Required = _decorator.Required ? "1" : "0"; - return fieldObject; - } - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecorator.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecorator.cs deleted file mode 100644 index d4e525ef..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecorator.cs +++ /dev/null @@ -1,249 +0,0 @@ -using System; -using System.Collections.Generic; -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class FormObjectDecorator - { - private readonly FormObject _formObject; - - public RowObjectDecorator CurrentRow { get; set; } - public List OtherRows { get; set; } - - public FormObjectDecorator(FormObject formObject) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject)); - _formObject = formObject; - if (formObject.CurrentRow != null) - CurrentRow = new RowObjectDecorator(formObject.CurrentRow); - OtherRows = new List(); - foreach (var rowObject in formObject.OtherRows ?? new List()) - { - OtherRows.Add(new RowObjectDecorator(rowObject)); - } - } - - public string FormId => _formObject.FormId; - public bool MultipleIteration => _formObject.MultipleIteration; - - public static FormObjectDecoratorBuilder Builder() - { - return new FormObjectDecoratorBuilder(); - } - - public static FormObjectDecoratorBuilder Builder(FormObject formObject) - { - return new FormObjectDecoratorBuilder(formObject); - } - - /// - /// Adds a to a . - /// - /// - public void AddRowObject(RowObject rowObject) - { - var tempDecorator = Helper.AddRowObject(this, rowObject); - CurrentRow = tempDecorator.CurrentRow; - OtherRows = tempDecorator.OtherRows; - } - - /// - /// Adds a to a using provided RowId and ParentRowId. - /// - /// - /// - public void AddRowObject(string rowId, string parentRowId) - { - var tempDecorator = Helper.AddRowObject(this, rowId, parentRowId); - CurrentRow = tempDecorator.CurrentRow; - OtherRows = tempDecorator.OtherRows; - } - - /// - /// Adds a to a using provided RowId, ParentRowId, and RowAction. - /// - /// - /// - /// - public void AddRowObject(string rowId, string parentRowId, string rowAction) - { - var tempDecorator = Helper.AddRowObject(this, rowId, parentRowId, rowAction); - CurrentRow = tempDecorator.CurrentRow; - OtherRows = tempDecorator.OtherRows; - } - - /// - /// Flags a for deletion in a . - /// - /// - public void DeleteRowObject(RowObject rowObject) - { - var tempDecorator = Helper.DeleteRowObject(this, rowObject); - CurrentRow = tempDecorator.CurrentRow; - OtherRows = tempDecorator.OtherRows; - } - - /// - /// Flags a for deletion in a by RowId. - /// - /// - public void DeleteRowObject(string rowId) - { - var tempDecorator = Helper.DeleteRowObject(this, rowId); - CurrentRow = tempDecorator.CurrentRow; - OtherRows = tempDecorator.OtherRows; - } - - /// - /// Disables all in the . - /// - public void DisableAllFieldObjects() - { - var tempDecorator = Helper.DisableAllFieldObjects(this); - CurrentRow = tempDecorator.CurrentRow; - OtherRows = tempDecorator.OtherRows; - } - - /// - /// Disables all in the , except for the FieldNumbers specified in the list. - /// - /// - public void DisableAllFieldObjects(List excludedFields) - { - var tempDecorator = Helper.DisableAllFieldObjects(this, excludedFields); - CurrentRow = tempDecorator.CurrentRow; - OtherRows = tempDecorator.OtherRows; - } - - /// - /// Returns the RowId of the . - /// - /// - public string GetCurrentRowId() => Helper.GetCurrentRowId(this); - - /// - /// Returns the value of the in the CurrentRow of the by FieldNumber. - /// - /// - /// - public string GetFieldValue(string fieldNumber) => Helper.GetFieldValue(this, fieldNumber); - - /// - /// Returns the value of the in the of the by RowId and FieldNumber. - /// - /// - /// - /// - public string GetFieldValue(string rowId, string fieldNumber) => Helper.GetFieldValue(this, rowId, fieldNumber); - - /// - /// Returns a of FieldValues in a . - /// - /// - /// - public List GetFieldValues(string fieldNumber) => Helper.GetFieldValues(this, fieldNumber); - - /// - /// Returns the Multiple Iteration Status of the . - /// - /// - public bool GetMultipleIterationStatus() => Helper.GetMultipleIterationStatus(this); - - /// - /// Returns the next available RowId for the . - /// - /// - public string GetNextAvailableRowId() => Helper.GetNextAvailableRowId(this); - - /// - /// Returns the ParentRowId of the . - /// - /// - public string GetParentRowId() => Helper.GetParentRowId(this); - - /// - /// Determines whether the is enabled in the by FieldNumber. - /// - /// - /// - public bool IsFieldEnabled(string fieldNumber) => Helper.IsFieldEnabled(this, fieldNumber); - - /// - /// Determines whether the is locked in the by FieldNumber. - /// - /// - /// - public bool IsFieldLocked(string fieldNumber) => Helper.IsFieldLocked(this, fieldNumber); - - /// - /// Determines whether the is modified in the by FieldNumber. - /// - /// - /// - public bool IsFieldModified(string fieldNumber) => Helper.IsFieldModified(this, fieldNumber); - - /// - /// Determines whether the is present in the by FieldNumber. - /// - /// - /// - public bool IsFieldPresent(string fieldNumber) => Helper.IsFieldPresent(this, fieldNumber); - - /// - /// Determines whether the is required in the by FieldNumber. - /// - /// - /// - public bool IsFieldRequired(string fieldNumber) => Helper.IsFieldRequired(this, fieldNumber); - - /// - /// Determines whether the is marked for deletion in the by RowId. - /// - /// - /// - public bool IsRowMarkedForDeletion(string rowId) => Helper.IsRowMarkedForDeletion(this, rowId); - - /// - /// Determines whether the is present in the by RowId. - /// - /// - /// - public bool IsRowPresent(string rowId) => Helper.IsRowPresent(this, rowId); - - /// - /// Creates a return builder for the . - /// - /// - public FormObjectDecoratorReturnBuilder Return() - { - return new FormObjectDecoratorReturnBuilder(this); - } - - /// - /// Sets the value of a in the of a . - /// - /// - /// - public void SetFieldValue(string fieldNumber, string fieldValue) - { - var tempDecorator = Helper.SetFieldValue(this, fieldNumber, fieldValue); - CurrentRow = tempDecorator.CurrentRow; - OtherRows = tempDecorator.OtherRows; - } - - /// - /// Sets the value of a in a . - /// - /// - /// - /// - public void SetFieldValue(string rowId, string fieldNumber, string fieldValue) - { - var tempDecorator = Helper.SetFieldValue(this, rowId, fieldNumber, fieldValue); - CurrentRow = tempDecorator.CurrentRow; - OtherRows = tempDecorator.OtherRows; - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecoratorBuilder.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecoratorBuilder.cs deleted file mode 100644 index eda8db8e..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecoratorBuilder.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System.Collections.Generic; -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class FormObjectDecorator - { - public class FormObjectDecoratorBuilder - { - private string _formId; - private RowObject _currentRow; - private bool _multipleIteration; - private List _otherRows; - - public FormObjectDecoratorBuilder() { - _otherRows = new List(); - } - - public FormObjectDecoratorBuilder(FormObject formObject) { - if (formObject != null) { - _formId = formObject.FormId; - _currentRow = formObject.CurrentRow; - _multipleIteration = formObject.MultipleIteration; - _otherRows = formObject.OtherRows; - } - } - - public FormObjectDecoratorBuilder CurrentRow(RowObject rowObject) { - _currentRow = rowObject; - return this; - } - - public FormObjectDecoratorBuilder FormId(string formId) { - _formId = formId; - return this; - } - - public FormObjectDecoratorBuilder MultipleIteration() { - _multipleIteration = true; - return this; - } - - public FormObjectDecoratorBuilder MultipleIteration(bool multipleIteration) { - _multipleIteration = multipleIteration; - return this; - } - - public FormObjectDecoratorBuilder OtherRow(RowObject rowObject) { - if (rowObject != null) { - _otherRows.Add(rowObject); - } - return this; - } - - public FormObjectDecoratorBuilder OtherRows(List rowObjects) { - _otherRows = rowObjects; - return this; - } - - public FormObjectDecorator Build() { - FormObject formObject = new FormObject { - FormId = _formId, - CurrentRow = _currentRow, - MultipleIteration = _multipleIteration, - OtherRows = _otherRows - }; - return new FormObjectDecorator(formObject); - } - } - } -} \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecoratorHelper.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecoratorHelper.cs deleted file mode 100644 index 3a00e590..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecoratorHelper.cs +++ /dev/null @@ -1,447 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Reflection; -using System.Resources; -using RarelySimple.AvatarScriptLink.Net.Exceptions; -using RarelySimple.AvatarScriptLink.Objects; -using static RarelySimple.AvatarScriptLink.Objects.RowObject; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class FormObjectDecorator - { - private sealed class Helper : DecoratorHelper - { - private static readonly ResourceManager resourceManager = new ResourceManager("RarelySimple.AvatarScriptLink.Net.Localizations", Assembly.GetExecutingAssembly()); - - /// - /// Gets the CurrentRow.RowId of the . - /// - /// - /// - public static string GetCurrentRowId(FormObjectDecorator formObject) - { - if (formObject.CurrentRow == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString("formObjectMissingCurrentRow", CultureInfo.CurrentCulture)); - return formObject.CurrentRow.RowId; - } - /// - /// Returns the FieldValue of a in the curent row of a by FieldNumber. - /// - /// - /// - /// - public static string GetFieldValue(FormObjectDecorator formObject, string fieldNumber) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return GetFieldValue(formObject, formObject.CurrentRow.RowId, fieldNumber); - } - /// - /// Returns the FieldValue of a in a by RowId and FieldNumber. - /// - /// - /// - /// - /// - public static string GetFieldValue(FormObjectDecorator formObject, string rowId, string fieldNumber) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject.CurrentRow.RowId == rowId) - return formObject.CurrentRow.GetFieldValue(fieldNumber); - foreach (RowObjectDecorator rowObject in formObject.OtherRows) - { - if (rowObject.RowId == rowId) - return rowObject.GetFieldValue(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns a list of FieldValues of a specified in the by FieldNumber. - /// - /// - /// - /// - public static List GetFieldValues(FormObjectDecorator formObject, string fieldNumber) - { - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - List values = new List(); - if (IsFieldPresent(formObject, fieldNumber)) - { - values.Add(formObject.CurrentRow.GetFieldValue(fieldNumber)); - if (formObject.MultipleIteration) - { - foreach (RowObjectDecorator rowObject in formObject.OtherRows) - { - values.Add(rowObject.GetFieldValue(fieldNumber)); - } - } - return values; - } - return values; - } - /// - /// Returns whether a is Multiple Iteration. - /// - /// - /// - public static bool GetMultipleIterationStatus(FormObjectDecorator formObject) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return formObject.MultipleIteration; - } - /// - /// Returns the ParentRowId of a . - /// - /// - /// - public static string GetParentRowId(FormObjectDecorator formObject) - { - if (formObject.CurrentRow == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString("formObjectMissingCurrentRow", CultureInfo.CurrentCulture)); - return formObject.CurrentRow.ParentRowId; - } - /// - /// Returns whether the in the is enabled by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldEnabled(FormObjectDecorator formObject, string fieldNumber) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject.CurrentRow == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(FormObjectMissingCurrentRow, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return formObject.CurrentRow.IsFieldEnabled(fieldNumber); - } - /// - /// Returns whether the in the is locked by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldLocked(FormObjectDecorator formObject, string fieldNumber) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject.CurrentRow == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(FormObjectMissingCurrentRow, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return formObject.CurrentRow.IsFieldLocked(fieldNumber); - } - /// - /// Returns whether the in the is modified by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldModified(FormObjectDecorator formObject, string fieldNumber) - { - if (formObject.CurrentRow == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString("formObjectMissingCurrentRow", CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return formObject.CurrentRow.IsFieldModified(fieldNumber); - } - /// - /// Returns whether the in the is present by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldPresent(FormObjectDecorator decorator, string fieldNumber) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.CurrentRow == null) - return false; - return decorator.CurrentRow.IsFieldPresent(fieldNumber); - } - /// - /// Returns whether the in the is required by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldRequired(FormObjectDecorator formObject, string fieldNumber) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject.CurrentRow == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(FormObjectMissingCurrentRow, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return formObject.CurrentRow.IsFieldRequired(fieldNumber); - } - /// - /// Returns whether the in an is marked for deletion by RowId. - /// - /// - /// - /// - public static bool IsRowMarkedForDeletion(FormObjectDecorator formObject, string rowId) - { - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject.CurrentRow.RowId == rowId) - return formObject.CurrentRow.RowAction == RowActions.Delete; - if (formObject.MultipleIteration) - return formObject.OtherRows.Exists(r => r.RowId == rowId && r.RowAction == RowActions.Delete); - return false; - } - /// - /// Returns whether the in the is enabled by RowId. - /// - /// - /// - /// - public static bool IsRowPresent(FormObjectDecorator formObject, string rowId) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject.CurrentRow != null && formObject.CurrentRow.RowId == rowId) - return true; - if (formObject.MultipleIteration) - return formObject.OtherRows.Exists(r => r.RowId == rowId); - return false; - } - /// - /// Sets the FieldValue of a in a by FieldNumber. - /// - /// - /// - /// - /// - public static FormObjectDecorator SetFieldValue(FormObjectDecorator decorator, string fieldNumber, string fieldValue) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.CurrentRow == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(FormObjectMissingCurrentRow, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.MultipleIteration && decorator.OtherRows.Count > 0) - throw new ArgumentException(resourceManager.GetString(UnableToIdentifyFieldObject, CultureInfo.CurrentCulture)); - return SetFieldValue(decorator, decorator.CurrentRow.RowId, fieldNumber, fieldValue); - } - /// - /// Sets the FieldValue of a in a by RowId and FieldNumber. - /// - /// - /// - /// - /// - /// - public static FormObjectDecorator SetFieldValue(FormObjectDecorator decorator, string rowId, string fieldNumber, string fieldValue) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.CurrentRow == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(FormObjectMissingCurrentRow, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.CurrentRow.RowId == rowId) - { - decorator.CurrentRow.SetFieldValue(fieldNumber, fieldValue); - return decorator; - } - if (decorator.MultipleIteration) - { - for (int i = 0; i < decorator.OtherRows.Count; i++) - { - if (decorator.OtherRows[i].RowId == rowId) - { - decorator.OtherRows[i].SetFieldValue(fieldNumber, fieldValue); - return decorator; - } - } - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns the next available RowId for a . - /// - /// - /// - public static string GetNextAvailableRowId(FormObjectDecorator formObject) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject.CurrentRow != null && !formObject.MultipleIteration) - throw new ArgumentOutOfRangeException(resourceManager.GetString("cannotAddAnotherRowObject", CultureInfo.CurrentCulture)); - int maximumNumberOfMultipleIterationRows = 9999; - if (formObject.CurrentRow != null && formObject.OtherRows.Count + 1 >= maximumNumberOfMultipleIterationRows) - throw new ArgumentOutOfRangeException(resourceManager.GetString("cannotAddAnotherRowObject", CultureInfo.CurrentCulture)); - for (int i = 1; i <= maximumNumberOfMultipleIterationRows; i++) - { - string tempRowId = formObject.FormId + "||" + i.ToString(CultureInfo.InvariantCulture); - if ((formObject.CurrentRow == null || formObject.CurrentRow.RowId != tempRowId) - && !formObject.OtherRows.Exists(r => r.RowId == tempRowId)) - return tempRowId; - } - throw new ArgumentException(resourceManager.GetString("couldNotDetermineNextRowId", CultureInfo.CurrentCulture)); - } - /// - /// Adds a to a provided . - /// - /// - /// - /// - public static FormObjectDecorator AddRowObject(FormObjectDecorator formObject, RowObject rowObject) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (!formObject.MultipleIteration && formObject.CurrentRow != null) - throw new ArgumentException(resourceManager.GetString("cannotAddAnotherRowObject", CultureInfo.CurrentCulture)); - - if ((formObject.CurrentRow != null && formObject.CurrentRow.RowId == rowObject.RowId && !string.IsNullOrEmpty(rowObject.RowId)) || - (formObject.OtherRows != null && formObject.OtherRows.Exists(r => r.RowId == rowObject.RowId && !string.IsNullOrEmpty(rowObject.RowId)))) - throw new ArgumentException(resourceManager.GetString("rowIdAlreadyExists", CultureInfo.CurrentCulture)); - - if (formObject.CurrentRow == null) - { - rowObject.RowId = GetNextAvailableRowId(formObject); - formObject.CurrentRow = new RowObjectDecorator(rowObject); - } - else - { - if (string.IsNullOrEmpty(rowObject.RowId)) - rowObject.RowId = GetNextAvailableRowId(formObject); - formObject.OtherRows.Add(new RowObjectDecorator(rowObject)); - } - return formObject; - } - /// - /// Adds a to a provided using provided RowId and ParentRowId. - /// - /// - /// - /// - /// - public static FormObjectDecorator AddRowObject(FormObjectDecorator formObject, string rowId, string parentRowId) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return AddRowObject(formObject, rowId, parentRowId, RowActions.Add); - } - /// - /// Adds a to a provided using provided RowId, ParentRowId, and RowAction. - /// - /// - /// - /// - /// - /// - public static FormObjectDecorator AddRowObject(FormObjectDecorator formObject, string rowId, string parentRowId, string rowAction) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - RowObject rowObject = new RowObject - { - ParentRowId = parentRowId, - RowAction = rowAction, - RowId = rowId - }; - return AddRowObject(formObject, rowObject); - } - /// - /// Flags a for deletion in a . - /// - /// - /// - /// - public static FormObjectDecorator DeleteRowObject(FormObjectDecorator formObject, RowObject rowObject) - { - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return DeleteRowObject(formObject, rowObject.RowId); - } - /// - /// Flags a for deletion in a by RowId. - /// - /// - /// - /// - public static FormObjectDecorator DeleteRowObject(FormObjectDecorator formObject, string rowId) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - - if (formObject.CurrentRow?.RowId == rowId) - { - formObject.CurrentRow.RowAction = RowActions.Delete; - return formObject; - } - - if (formObject.MultipleIteration) - { - int rowIndex = formObject.OtherRows.FindIndex(r => r.RowId == rowId); - if (rowIndex >= 0) - { - formObject.OtherRows[rowIndex].RowAction = RowActions.Delete; - return formObject; - } - } - - throw new ArgumentException(resourceManager.GetString("noRowObjectsFoundByRowId", CultureInfo.CurrentCulture), nameof(rowId)); - } - /// - /// Disables all in the . - /// - /// - /// - public static FormObjectDecorator DisableAllFieldObjects(FormObjectDecorator formObject) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return DisableAllFieldObjects(formObject, new List()); - } - /// - /// Disables all in the , except for the FieldNumbers specified in the list. - /// - /// - /// - /// - public static FormObjectDecorator DisableAllFieldObjects(FormObjectDecorator formObject, List excludedFields) - { - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (excludedFields == null) - throw new ArgumentNullException(nameof(excludedFields), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - - if (formObject.CurrentRow != null) - { - formObject.CurrentRow.DisableAllFieldObjects(excludedFields); - } - - // Process all OtherRows unconditionally, matching legacy implementation behavior. - // This ensures fields in OtherRows are disabled regardless of the MultipleIteration flag. - formObject.OtherRows.ForEach(r => r.DisableAllFieldObjects(excludedFields)); - - return formObject; - } - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecoratorReturnBuilder.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecoratorReturnBuilder.cs deleted file mode 100644 index f3b97c77..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/FormObjectDecoratorReturnBuilder.cs +++ /dev/null @@ -1,44 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class FormObjectDecorator - { - public class FormObjectDecoratorReturnBuilder - { - private readonly FormObjectDecorator _decorator; - - public FormObjectDecoratorReturnBuilder(FormObjectDecorator decorator) - { - _decorator = decorator; - } - - public FormObject AsFormObject() - { - var formObject = FormObject.Initialize(); - formObject.FormId = _decorator.FormId; - - var currentRow = _decorator.CurrentRow.Return().AsRowObject(); - if (currentRow != null && - DecoratorHelper.IsValidReturnRowAction(currentRow.RowAction) && - currentRow.Fields.Count > 0) - formObject.CurrentRow = currentRow; - - if (_decorator.MultipleIteration) - { - formObject.MultipleIteration = _decorator.MultipleIteration; - foreach (var rowObject in _decorator.OtherRows) - { - var otherRow = rowObject.Return().AsRowObject(); - if (otherRow != null && - DecoratorHelper.IsValidReturnRowAction(otherRow.RowAction) && - otherRow.Fields.Count > 0) - formObject.OtherRows.Add(otherRow); - } - } - - return formObject; - } - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2015Decorator.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2015Decorator.cs deleted file mode 100644 index 39414c2f..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2015Decorator.cs +++ /dev/null @@ -1,228 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects; -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; -using System; -using System.Collections.Generic; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class OptionObject2015Decorator - { - private readonly IOptionObject2015 _optionObject; - - public double ErrorCode { get; set; } - public string ErrorMesg { get; set; } - public List Forms { get; set; } - - public OptionObject2015Decorator(OptionObject2015 optionObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject)); - _optionObject = optionObject.Clone(); - - Forms = new List(); - foreach (var form in optionObject.Forms ?? new List()) - { - Forms.Add(new FormObjectDecorator(form)); - } - } - - public string EntityID => _optionObject.EntityID; - public double EpisodeNumber => _optionObject.EpisodeNumber; - public string Facility => _optionObject.Facility; - public string NamespaceName => _optionObject.NamespaceName; - public string OptionId => _optionObject.OptionId; - public string OptionStaffId => _optionObject.OptionStaffId; - public string OptionUserId => _optionObject.OptionUserId; - public string ParentNamespace => _optionObject.ParentNamespace; - public string ServerName => _optionObject.ServerName; - public string SessionToken => _optionObject.SessionToken; - public string SystemCode => _optionObject.SystemCode; - - /// - /// Adds a to an . - /// - /// - public void AddFormObject(FormObject formObject) => Forms = Helper.AddFormObject(this, formObject).Forms; - - /// - /// Adds a to an . - /// - /// - public void AddFormObject(FormObjectDecorator formObject) => Forms = Helper.AddFormObject(this, formObject).Forms; - - /// - /// Adds a to an . - /// - /// - public void AddFormObject(string formId) => Forms = Helper.AddFormObject(this, formId).Forms; - - /// - /// Adds a to an . - /// - /// - /// - public void AddFormObject(string formId, bool multipleIteration) => Forms = Helper.AddFormObject(this, formId, multipleIteration).Forms; - - /// - /// Adds a to a specified within the . - /// - /// - /// - public void AddRowObject(string formId, RowObject rowObject) => Forms = Helper.AddRowObject(this, formId, rowObject).Forms; - - /// - /// Flags a for deletion in a specified within the by RowId. - /// - /// - /// - public void DeleteRowObject(string formId, string rowId) => Forms = Helper.DeleteRowObject(this, formId, rowId).Forms; - - /// - /// Disables all in the . - /// - public void DisableAllFieldObjects() => Forms = Helper.DisableAllFieldObjects(this).Forms; - - /// - /// Disables all in the , except for the FieldNumbers specified in the list. - /// - /// - public void DisableAllFieldObjects(List excludedFields) => Forms = Helper.DisableAllFieldObjects(this, excludedFields).Forms; - - /// - /// Returns the CurrentRow RowId of the form matching the FormId. - /// - /// - /// - public string GetCurrentRowId(string formId) => Helper.GetCurrentRowId(this, formId); - - /// - /// Returns the first value of the field matching the Field Number. - /// - /// - /// - public string GetFieldValue(string fieldNumber) => Helper.GetFieldValue(this, fieldNumber); - - /// - /// Returns the value of the matching the Field Number on the specified and . - /// - /// - /// - public string GetFieldValue(string formId, string rowId, string fieldNumber) => Helper.GetFieldValue(this, formId, rowId, fieldNumber); - - /// - /// Returns the values of the field matching the Field Number. - /// - /// - /// - public List GetFieldValues(string fieldNumber) => Helper.GetFieldValues(this, fieldNumber); - - /// - /// Returns the Multiple Iteration Status of the form matching the FormId. - /// - /// - /// - public bool GetMultipleIterationStatus(string formId) => Helper.GetMultipleIterationStatus(this, formId); - - /// - /// Returns the CurrentRow ParentRowId of the form matching the FormId. - /// - /// - /// - public string GetParentRowId(string formId) => Helper.GetParentRowId(this, formId); - - /// - /// Returns whether the specified field is enabled. - /// - /// - /// - public bool IsFieldEnabled(string fieldNumber) => Helper.IsFieldEnabled(this, fieldNumber); - - /// - /// Returns whether the specified field is locked. - /// - /// - /// - public bool IsFieldLocked(string fieldNumber) => Helper.IsFieldLocked(this, fieldNumber); - - /// - /// Returns whether the specified field is modified. - /// - /// - /// - public bool IsFieldModified(string fieldNumber) => Helper.IsFieldModified(this, fieldNumber); - - /// - /// Returns whether the specified field is present. - /// - /// - /// - public bool IsFieldPresent(string fieldNumber) => Helper.IsFieldPresent(this, fieldNumber); - - /// - /// Returns whether the specified field is required. - /// - /// - /// - public bool IsFieldRequired(string fieldNumber) => Helper.IsFieldRequired(this, fieldNumber); - - /// - /// Returns whether the specified is present. - /// - /// - /// - public bool IsFormPresent(string formId) => Helper.IsFormPresent(this, formId); - - /// - /// Returns whether the specified is marked for deletion. - /// - /// - /// - public bool IsRowMarkedForDeletion(string rowId) => Helper.IsRowMarkedForDeletion(this, rowId); - - /// - /// Returns whether the specified is present. - /// - /// - /// - public bool IsRowPresent(string rowId) => Helper.IsRowPresent(this, rowId); - - /// - /// Creates a return builder for the . - /// - /// - public OptionObject2015DecoratorReturnBuilder Return() - { - return new OptionObject2015DecoratorReturnBuilder(this); - } - - /// - /// Sets the FieldValue of a in the on the first form CurrentRow. - /// - /// - /// - public void SetFieldValue(string fieldNumber, string fieldValue) => Forms = Helper.SetFieldValue(this, fieldNumber, fieldValue).Forms; - - /// - /// Sets the FieldValue of a in the - /// - /// - /// - /// - /// - public void SetFieldValue(string formId, string rowId, string fieldNumber, string fieldValue) => Forms = Helper.SetFieldValue(this, formId, rowId, fieldNumber, fieldValue).Forms; - - /// - /// Creates an with the minimal information required to return. - /// - /// - public OptionObject2015 ToReturnOptionObject() => Return().AsOptionObject2015(); - - /// - /// Creates an with the minimal information required to return plus the provide Error Code and Message. - /// - /// - /// - /// - public OptionObject2015 ToReturnOptionObject(double errorCode, string errorMessage) => Return().WithErrorCode(errorCode).WithErrorMesg(errorMessage).AsOptionObject2015(); - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2015DecoratorHelper.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2015DecoratorHelper.cs deleted file mode 100644 index d3c9293c..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2015DecoratorHelper.cs +++ /dev/null @@ -1,480 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Reflection; -using System.Resources; -using RarelySimple.AvatarScriptLink.Net.Exceptions; -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class OptionObject2015Decorator - { - private sealed class Helper : DecoratorHelper - { - private static readonly ResourceManager resourceManager = new ResourceManager("RarelySimple.AvatarScriptLink.Net.Localizations", Assembly.GetExecutingAssembly()); - - /// - /// Adds a to an . - /// - /// - /// - /// - public static OptionObject2015Decorator AddFormObject(OptionObject2015Decorator optionObject, FormObject formObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return AddFormObject(optionObject, new FormObjectDecorator(formObject)); - } - /// - /// Adds a to an . - /// - /// - /// - /// - public static OptionObject2015Decorator AddFormObject(OptionObject2015Decorator optionObject, FormObjectDecorator formObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms.Count == 0 && formObject.MultipleIteration) - throw new ArgumentException(resourceManager.GetString("firstFormCannotBeMultipleIteration", CultureInfo.CurrentCulture)); - if (optionObject.Forms.Contains(formObject) || optionObject.Forms.Exists(f => f.FormId == formObject.FormId)) - throw new ArgumentException(resourceManager.GetString("formIdAlreadyExists", CultureInfo.CurrentCulture)); - optionObject.Forms.Add(formObject); - return optionObject; - } - /// - /// Creates a with specified FormId and adds to an using provided FormId. - /// - /// - /// - /// - public static OptionObject2015Decorator AddFormObject(OptionObject2015Decorator optionObject, string formId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formId == null) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - FormObjectDecorator formObject = FormObjectDecorator.Builder() - .FormId(formId) - .Build(); - return AddFormObject(optionObject, formObject); - } - /// - /// Creates a with specified FormId and adds to an using provided FormId and indicating whether it is a multiple iteration table. - /// - /// - /// - /// - /// - public static OptionObject2015Decorator AddFormObject(OptionObject2015Decorator optionObject, string formId, bool multipleIteration) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formId == null) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - FormObjectDecorator formObject = FormObjectDecorator.Builder() - .FormId(formId) - .MultipleIteration(multipleIteration) - .Build(); - return AddFormObject(optionObject, formObject); - } - /// - /// Gets the CurrentRow.RowId of the in the by FormId. - /// - /// - /// - /// - public static string GetCurrentRowId(OptionObject2015Decorator optionObject, string formId) - { - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (var formObject in optionObject.Forms) - { - if (formObject.FormId == formId) - return formObject.GetCurrentRowId(); - } - throw new ArgumentException(resourceManager.GetString("noFormObjectsFoundByFormId", CultureInfo.CurrentCulture), nameof(optionObject)); - } - /// - /// Returns the FieldValue of a specified in an by FieldNumber. - /// - /// - /// - /// - public static string GetFieldValue(OptionObject2015Decorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.GetFieldValue(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns the FieldValue of a specified in an by FormId, RowId, and FieldNumber. - /// - /// - /// - /// - /// - /// - public static string GetFieldValue(OptionObject2015Decorator optionObject, string formId, string rowId, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (var form in optionObject.Forms) - { - if (form.FormId == formId) - return form.GetFieldValue(rowId, fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns a list of FieldValues of a specified in the by FieldNumber. - /// - /// - /// - /// - public static List GetFieldValues(OptionObject2015Decorator optionObject, string fieldNumber) - { - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(f => f.IsFieldPresent(fieldNumber)); - if (form != null) - return form.GetFieldValues(fieldNumber); - return new List(); - } - /// - /// Returns whether a in the is Multiple Iteration by specified FormId. - /// - /// - /// - /// - public static bool GetMultipleIterationStatus(OptionObject2015Decorator optionObject, string formId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - foreach (var form in optionObject.Forms) - { - if (form.FormId == formId) - return form.GetMultipleIterationStatus(); - } - throw new FormObjectNotFoundException(string.Format(resourceManager.GetString(NoFormObjectsFoundByFormId, CultureInfo.CurrentCulture), formId), formId); - } - /// - /// Returns the ParentRowId of a in the by FormId. - /// - /// - /// - /// - public static string GetParentRowId(OptionObject2015Decorator optionObject, string formId) - { - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (var formObject in optionObject.Forms) - { - if (formObject.FormId == formId) - return formObject.GetParentRowId(); - } - throw new ArgumentException(resourceManager.GetString("noFormObjectsFoundByFormId", CultureInfo.CurrentCulture), nameof(formId)); - } - /// - /// Returns whether the in the is enabled by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldEnabled(OptionObject2015Decorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldEnabled(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether the in the is locked by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldLocked(OptionObject2015Decorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldLocked(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether the in the is modified by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldModified(OptionObject2015Decorator optionObject, string fieldNumber) - { - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(f => f.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldModified(fieldNumber); - } - throw new ArgumentException("The OptionObject2015 does not contain the FieldObject " + fieldNumber + "."); - } - /// - /// Returns whether the in the is present by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldPresent(OptionObject2015Decorator decorator, string fieldNumber) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Forms == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return decorator.Forms.Find(x => x.IsFieldPresent(fieldNumber)) != null; - } - /// - /// Returns whether the in the is required by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldRequired(OptionObject2015Decorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldRequired(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether a exists in an by . - /// - /// - /// - /// - public static bool IsFormPresent(OptionObject2015Decorator optionObject, string formId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null || optionObject.Forms.Count == 0) - return false; - return optionObject.Forms.Exists(f => f.FormId == formId); - } - /// - /// Returns whether the in an is marked for deletion by RowId. - /// - /// - /// - /// - public static bool IsRowMarkedForDeletion(OptionObject2015Decorator optionObject, string rowId) - { - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return optionObject.Forms.Find(f => f.IsRowMarkedForDeletion(rowId)) != null; - } - /// - /// Returns whether the in the is enabled by RowId. - /// - /// - /// - /// - public static bool IsRowPresent(OptionObject2015Decorator optionObject, string rowId) - { - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return optionObject.Forms.Find(x => x.IsRowPresent(rowId)) != null; - } - /// - /// Sets the FieldValue of a in an by FieldNumber. - /// - /// - /// - /// - /// - public static OptionObject2015Decorator SetFieldValue(OptionObject2015Decorator decorator, string fieldNumber, string fieldValue) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Forms == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = decorator.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - if (form.MultipleIteration && form.OtherRows.Count > 0) - throw new ArgumentException(resourceManager.GetString(UnableToIdentifyFieldObject, CultureInfo.CurrentCulture), nameof(decorator)); - return SetFieldValue(decorator, form.FormId, form.CurrentRow.RowId, fieldNumber, fieldValue); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Sets the FieldValue of a in an by FormId, RowID, and FieldNumber. - /// - /// - /// - /// - /// - /// - /// - public static OptionObject2015Decorator SetFieldValue(OptionObject2015Decorator decorator, string formId, string rowId, string fieldNumber, string fieldValue) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Forms == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - for (int i = 0; i < decorator.Forms.Count; i++) - { - if (decorator.Forms[i].FormId == formId) - decorator.Forms[i].SetFieldValue(rowId, fieldNumber, fieldValue); - } - return decorator; - } - /// - /// Executes an operation on a form within the OptionObject2015Decorator by FormId. - /// - /// - /// - /// - /// - private static OptionObject2015Decorator ExecuteOnForm(OptionObject2015Decorator optionObject, string formId, Action action) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms.Exists(f => f.FormId == formId)) - { - int formIndex = optionObject.Forms.FindIndex(f => f.FormId == formId); - if (formIndex >= 0) - { - action(optionObject.Forms[formIndex]); - } - } - else - { - throw new ArgumentException(resourceManager.GetString("noFormObjectsFoundByFormId", CultureInfo.CurrentCulture), nameof(formId)); - } - return optionObject; - } - /// - /// Adds a to a specified within provided . - /// - /// - /// - /// - /// - public static OptionObject2015Decorator AddRowObject(OptionObject2015Decorator optionObject, string formId, RowObject rowObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return ExecuteOnForm(optionObject, formId, form => form.AddRowObject(rowObject)); - } - /// - /// Flags a for deletion in a specified within the by RowId. - /// - /// - /// - /// - /// - public static OptionObject2015Decorator DeleteRowObject(OptionObject2015Decorator optionObject, string formId, string rowId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return ExecuteOnForm(optionObject, formId, form => form.DeleteRowObject(rowId)); - } - /// - /// Disables all in the . - /// - /// - /// - public static OptionObject2015Decorator DisableAllFieldObjects(OptionObject2015Decorator optionObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return DisableAllFieldObjects(optionObject, new List()); - } - /// - /// Disables all in the , except for the FieldNumbers specified in the list. - /// - /// - /// - /// - public static OptionObject2015Decorator DisableAllFieldObjects(OptionObject2015Decorator optionObject, List excludedFields) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (optionObject.Forms.Count == 0) - throw new ArgumentException(resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture), nameof(optionObject)); - if (excludedFields == null) - throw new ArgumentNullException(nameof(excludedFields), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - - optionObject.Forms.ForEach(f => f.DisableAllFieldObjects(excludedFields)); - return optionObject; - } - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2015DecoratorReturnBuilder.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2015DecoratorReturnBuilder.cs deleted file mode 100644 index bf1e87d5..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2015DecoratorReturnBuilder.cs +++ /dev/null @@ -1,58 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class OptionObject2015Decorator - { - public class OptionObject2015DecoratorReturnBuilder - { - private readonly OptionObject2015Decorator _decorator; - - public OptionObject2015DecoratorReturnBuilder(OptionObject2015Decorator decorator) - { - _decorator = decorator; - } - - public OptionObject2015DecoratorReturnBuilder WithErrorCode(double errorCode) - { - _decorator.ErrorCode = errorCode; - return this; - } - - public OptionObject2015DecoratorReturnBuilder WithErrorMesg(string errorMesg) - { - _decorator.ErrorMesg = errorMesg; - return this; - } - - public OptionObject2015 AsOptionObject2015() - { - var optionObject = OptionObject2015.Initialize(); - optionObject.EntityID = _decorator.EntityID; - optionObject.EpisodeNumber = _decorator.EpisodeNumber; - optionObject.ErrorCode = _decorator.ErrorCode; - optionObject.ErrorMesg = _decorator.ErrorMesg; - optionObject.Facility = _decorator.Facility; - optionObject.NamespaceName = _decorator.NamespaceName; - optionObject.OptionId = _decorator.OptionId; - optionObject.OptionStaffId = _decorator.OptionStaffId; - optionObject.OptionUserId = _decorator.OptionUserId; - optionObject.ParentNamespace = _decorator.ParentNamespace; - optionObject.ServerName = _decorator.ServerName; - optionObject.SessionToken = _decorator.SessionToken; - optionObject.SystemCode = _decorator.SystemCode; - - foreach (var form in _decorator.Forms) - { - var formObject = form.Return().AsFormObject(); - if (formObject != null && - (formObject.CurrentRow != null || - formObject.OtherRows.Count > 0)) - optionObject.Forms.Add(formObject); - } - - return optionObject; - } - } - } -} \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2Decorator.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2Decorator.cs deleted file mode 100644 index fc11de1d..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2Decorator.cs +++ /dev/null @@ -1,227 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects; -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; -using System; -using System.Collections.Generic; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class OptionObject2Decorator - { - private readonly IOptionObject2 _optionObject; - - public double ErrorCode { get; set; } - public string ErrorMesg { get; set; } - public List Forms { get; set; } - - public OptionObject2Decorator(OptionObject2 optionObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject)); - _optionObject = optionObject.Clone(); - - Forms = new List(); - foreach (var form in optionObject.Forms ?? new List()) - { - Forms.Add(new FormObjectDecorator(form)); - } - } - - public string EntityID => _optionObject.EntityID; - public double EpisodeNumber => _optionObject.EpisodeNumber; - public string Facility => _optionObject.Facility; - public string NamespaceName => _optionObject.NamespaceName; - public string OptionId => _optionObject.OptionId; - public string OptionStaffId => _optionObject.OptionStaffId; - public string OptionUserId => _optionObject.OptionUserId; - public string ParentNamespace => _optionObject.ParentNamespace; - public string ServerName => _optionObject.ServerName; - public string SystemCode => _optionObject.SystemCode; - - /// - /// Adds a to an . - /// - /// - public void AddFormObject(FormObject formObject) => Forms = Helper.AddFormObject(this, formObject).Forms; - - /// - /// Adds a to an . - /// - /// - public void AddFormObject(FormObjectDecorator formObject) => Forms = Helper.AddFormObject(this, formObject).Forms; - - /// - /// Adds a to an . - /// - /// - public void AddFormObject(string formId) => Forms = Helper.AddFormObject(this, formId).Forms; - - /// - /// Adds a to an . - /// - /// - /// - public void AddFormObject(string formId, bool multipleIteration) => Forms = Helper.AddFormObject(this, formId, multipleIteration).Forms; - - /// - /// Adds a to a specified within the . - /// - /// - /// - public void AddRowObject(string formId, RowObject rowObject) => Forms = Helper.AddRowObject(this, formId, rowObject).Forms; - - /// - /// Flags a for deletion in a specified within the by RowId. - /// - /// - /// - public void DeleteRowObject(string formId, string rowId) => Forms = Helper.DeleteRowObject(this, formId, rowId).Forms; - - /// - /// Disables all in the . - /// - public void DisableAllFieldObjects() => Forms = Helper.DisableAllFieldObjects(this).Forms; - - /// - /// Disables all in the , except for the FieldNumbers specified in the list. - /// - /// - public void DisableAllFieldObjects(List excludedFields) => Forms = Helper.DisableAllFieldObjects(this, excludedFields).Forms; - - /// - /// Returns the CurrentRow RowId of the form matching the FormId. - /// - /// - /// - public string GetCurrentRowId(string formId) => Helper.GetCurrentRowId(this, formId); - - /// - /// Returns the first value of the field matching the Field Number. - /// - /// - /// - public string GetFieldValue(string fieldNumber) => Helper.GetFieldValue(this, fieldNumber); - - /// - /// Returns the value of the matching the Field Number on the specified and . - /// - /// - /// - public string GetFieldValue(string formId, string rowId, string fieldNumber) => Helper.GetFieldValue(this, formId, rowId, fieldNumber); - - /// - /// Returns the values of the field matching the Field Number. - /// - /// - /// - public List GetFieldValues(string fieldNumber) => Helper.GetFieldValues(this, fieldNumber); - - /// - /// Returns the Multiple Iteration Status of the form matching the FormId. - /// - /// - /// - public bool GetMultipleIterationStatus(string formId) => Helper.GetMultipleIterationStatus(this, formId); - - /// - /// Returns the CurrentRow ParentRowId of the form matching the FormId. - /// - /// - /// - public string GetParentRowId(string formId) => Helper.GetParentRowId(this, formId); - - /// - /// Returns whether the specified field is enabled. - /// - /// - /// - public bool IsFieldEnabled(string fieldNumber) => Helper.IsFieldEnabled(this, fieldNumber); - - /// - /// Returns whether the specified field is locked. - /// - /// - /// - public bool IsFieldLocked(string fieldNumber) => Helper.IsFieldLocked(this, fieldNumber); - - /// - /// Returns whether the specified field is modified. - /// - /// - /// - public bool IsFieldModified(string fieldNumber) => Helper.IsFieldModified(this, fieldNumber); - - /// - /// Returns whether the specified field is present. - /// - /// - /// - public bool IsFieldPresent(string fieldNumber) => Helper.IsFieldPresent(this, fieldNumber); - - /// - /// Returns whether the specified field is required. - /// - /// - /// - public bool IsFieldRequired(string fieldNumber) => Helper.IsFieldRequired(this, fieldNumber); - - /// - /// Returns whether the specified is present. - /// - /// - /// - public bool IsFormPresent(string formId) => Helper.IsFormPresent(this, formId); - - /// - /// Returns whether the specified is marked for deletion. - /// - /// - /// - public bool IsRowMarkedForDeletion(string rowId) => Helper.IsRowMarkedForDeletion(this, rowId); - - /// - /// Returns whether the specified is present. - /// - /// - /// - public bool IsRowPresent(string rowId) => Helper.IsRowPresent(this, rowId); - - /// - /// Creates a return builder for the . - /// - /// - public OptionObject2DecoratorReturnBuilder Return() - { - return new OptionObject2DecoratorReturnBuilder(this); - } - - /// - /// Sets the FieldValue of a in the on the first form CurrentRow. - /// - /// - /// - public void SetFieldValue(string fieldNumber, string fieldValue) => Forms = Helper.SetFieldValue(this, fieldNumber, fieldValue).Forms; - - /// - /// Sets the FieldValue of a in the - /// - /// - /// - /// - /// - public void SetFieldValue(string formId, string rowId, string fieldNumber, string fieldValue) => Forms = Helper.SetFieldValue(this, formId, rowId, fieldNumber, fieldValue).Forms; - - /// - /// Creates an with the minimal information required to return. - /// - /// - public OptionObject2 ToReturnOptionObject() => Return().AsOptionObject2(); - - /// - /// Creates an with the minimal information required to return plus the provide Error Code and Message. - /// - /// - /// - /// - public OptionObject2 ToReturnOptionObject(double errorCode, string errorMessage) => Return().WithErrorCode(errorCode).WithErrorMesg(errorMessage).AsOptionObject2(); - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2DecoratorHelper.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2DecoratorHelper.cs deleted file mode 100644 index 692c4093..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2DecoratorHelper.cs +++ /dev/null @@ -1,480 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Reflection; -using System.Resources; -using RarelySimple.AvatarScriptLink.Net.Exceptions; -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class OptionObject2Decorator - { - private sealed class Helper : DecoratorHelper - { - private static readonly ResourceManager resourceManager = new ResourceManager("RarelySimple.AvatarScriptLink.Net.Localizations", Assembly.GetExecutingAssembly()); - - /// - /// Adds a to an . - /// - /// - /// - /// - public static OptionObject2Decorator AddFormObject(OptionObject2Decorator optionObject, FormObject formObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return AddFormObject(optionObject, new FormObjectDecorator(formObject)); - } - /// - /// Adds a to an . - /// - /// - /// - /// - public static OptionObject2Decorator AddFormObject(OptionObject2Decorator optionObject, FormObjectDecorator formObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms.Count == 0 && formObject.MultipleIteration) - throw new ArgumentException(resourceManager.GetString("firstFormCannotBeMultipleIteration", CultureInfo.CurrentCulture)); - if (optionObject.Forms.Contains(formObject) || optionObject.Forms.Exists(f => f.FormId == formObject.FormId)) - throw new ArgumentException(resourceManager.GetString("formIdAlreadyExists", CultureInfo.CurrentCulture)); - optionObject.Forms.Add(formObject); - return optionObject; - } - /// - /// Creates a with specified FormId and adds to an using provided FormId. - /// - /// - /// - /// - public static OptionObject2Decorator AddFormObject(OptionObject2Decorator optionObject, string formId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formId == null) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - FormObjectDecorator formObject = FormObjectDecorator.Builder() - .FormId(formId) - .Build(); - return AddFormObject(optionObject, formObject); - } - /// - /// Creates a with specified FormId and adds to an using provided FormId and indicating whether it is a multiple iteration table. - /// - /// - /// - /// - /// - public static OptionObject2Decorator AddFormObject(OptionObject2Decorator optionObject, string formId, bool multipleIteration) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formId == null) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - FormObjectDecorator formObject = FormObjectDecorator.Builder() - .FormId(formId) - .MultipleIteration(multipleIteration) - .Build(); - return AddFormObject(optionObject, formObject); - } - /// - /// Gets the CurrentRow.RowId of the in the by FormId. - /// - /// - /// - /// - public static string GetCurrentRowId(OptionObject2Decorator optionObject, string formId) - { - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (var formObject in optionObject.Forms) - { - if (formObject.FormId == formId) - return formObject.GetCurrentRowId(); - } - throw new ArgumentException(resourceManager.GetString("noFormObjectsFoundByFormId", CultureInfo.CurrentCulture), nameof(optionObject)); - } - /// - /// Returns the FieldValue of a specified in an by FieldNumber. - /// - /// - /// - /// - public static string GetFieldValue(OptionObject2Decorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.GetFieldValue(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns the FieldValue of a specified in an by FormId, RowId, and FieldNumber. - /// - /// - /// - /// - /// - /// - public static string GetFieldValue(OptionObject2Decorator optionObject, string formId, string rowId, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (var form in optionObject.Forms) - { - if (form.FormId == formId) - return form.GetFieldValue(rowId, fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns a list of FieldValues of a specified in the by FieldNumber. - /// - /// - /// - /// - public static List GetFieldValues(OptionObject2Decorator optionObject, string fieldNumber) - { - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(f => f.IsFieldPresent(fieldNumber)); - if (form != null) - return form.GetFieldValues(fieldNumber); - return new List(); - } - /// - /// Returns whether a in the is Multiple Iteration by specified FormId. - /// - /// - /// - /// - public static bool GetMultipleIterationStatus(OptionObject2Decorator optionObject, string formId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - foreach (var form in optionObject.Forms) - { - if (form.FormId == formId) - return form.GetMultipleIterationStatus(); - } - throw new FormObjectNotFoundException(string.Format(resourceManager.GetString(NoFormObjectsFoundByFormId, CultureInfo.CurrentCulture), formId), formId); - } - /// - /// Returns the ParentRowId of a in the by FormId. - /// - /// - /// - /// - public static string GetParentRowId(OptionObject2Decorator optionObject, string formId) - { - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (var formObject in optionObject.Forms) - { - if (formObject.FormId == formId) - return formObject.GetParentRowId(); - } - throw new ArgumentException(resourceManager.GetString("noFormObjectsFoundByFormId", CultureInfo.CurrentCulture), nameof(formId)); - } - /// - /// Returns whether the in the is enabled by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldEnabled(OptionObject2Decorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldEnabled(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether the in the is locked by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldLocked(OptionObject2Decorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldLocked(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether the in the is modified by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldModified(OptionObject2Decorator optionObject, string fieldNumber) - { - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(f => f.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldModified(fieldNumber); - } - throw new ArgumentException("The OptionObject2 does not contain the FieldObject " + fieldNumber + "."); - } - /// - /// Returns whether the in the is present by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldPresent(OptionObject2Decorator decorator, string fieldNumber) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Forms == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return decorator.Forms.Find(x => x.IsFieldPresent(fieldNumber)) != null; - } - /// - /// Returns whether the in the is required by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldRequired(OptionObject2Decorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldRequired(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether a exists in an by . - /// - /// - /// - /// - public static bool IsFormPresent(OptionObject2Decorator optionObject, string formId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null || optionObject.Forms.Count == 0) - return false; - return optionObject.Forms.Exists(f => f.FormId == formId); - } - /// - /// Returns whether the in an is marked for deletion by RowId. - /// - /// - /// - /// - public static bool IsRowMarkedForDeletion(OptionObject2Decorator optionObject, string rowId) - { - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return optionObject.Forms.Find(f => f.IsRowMarkedForDeletion(rowId)) != null; - } - /// - /// Returns whether the in the is enabled by RowId. - /// - /// - /// - /// - public static bool IsRowPresent(OptionObject2Decorator optionObject, string rowId) - { - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return optionObject.Forms.Find(x => x.IsRowPresent(rowId)) != null; - } - /// - /// Sets the FieldValue of a in an by FieldNumber. - /// - /// - /// - /// - /// - public static OptionObject2Decorator SetFieldValue(OptionObject2Decorator decorator, string fieldNumber, string fieldValue) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Forms == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = decorator.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - if (form.MultipleIteration && form.OtherRows.Count > 0) - throw new ArgumentException(resourceManager.GetString(UnableToIdentifyFieldObject, CultureInfo.CurrentCulture), nameof(decorator)); - return SetFieldValue(decorator, form.FormId, form.CurrentRow.RowId, fieldNumber, fieldValue); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Sets the FieldValue of a in an by FormId, RowID, and FieldNumber. - /// - /// - /// - /// - /// - /// - /// - public static OptionObject2Decorator SetFieldValue(OptionObject2Decorator decorator, string formId, string rowId, string fieldNumber, string fieldValue) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Forms == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - for (int i = 0; i < decorator.Forms.Count; i++) - { - if (decorator.Forms[i].FormId == formId) - decorator.Forms[i].SetFieldValue(rowId, fieldNumber, fieldValue); - } - return decorator; - } - /// - /// Executes an operation on a form within the OptionObject2Decorator by FormId. - /// - /// - /// - /// - /// - private static OptionObject2Decorator ExecuteOnForm(OptionObject2Decorator optionObject, string formId, Action action) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms.Exists(f => f.FormId == formId)) - { - int formIndex = optionObject.Forms.FindIndex(f => f.FormId == formId); - if (formIndex >= 0) - { - action(optionObject.Forms[formIndex]); - } - } - else - { - throw new ArgumentException(resourceManager.GetString("noFormObjectsFoundByFormId", CultureInfo.CurrentCulture), nameof(formId)); - } - return optionObject; - } - /// - /// Adds a to a specified within provided . - /// - /// - /// - /// - /// - public static OptionObject2Decorator AddRowObject(OptionObject2Decorator optionObject, string formId, RowObject rowObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return ExecuteOnForm(optionObject, formId, form => form.AddRowObject(rowObject)); - } - /// - /// Flags a for deletion in a specified within the by RowId. - /// - /// - /// - /// - /// - public static OptionObject2Decorator DeleteRowObject(OptionObject2Decorator optionObject, string formId, string rowId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return ExecuteOnForm(optionObject, formId, form => form.DeleteRowObject(rowId)); - } - /// - /// Disables all in the . - /// - /// - /// - public static OptionObject2Decorator DisableAllFieldObjects(OptionObject2Decorator optionObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return DisableAllFieldObjects(optionObject, new List()); - } - /// - /// Disables all in the , except for the FieldNumbers specified in the list. - /// - /// - /// - /// - public static OptionObject2Decorator DisableAllFieldObjects(OptionObject2Decorator optionObject, List excludedFields) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (optionObject.Forms.Count == 0) - throw new ArgumentException(resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture), nameof(optionObject)); - if (excludedFields == null) - throw new ArgumentNullException(nameof(excludedFields), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - - optionObject.Forms.ForEach(f => f.DisableAllFieldObjects(excludedFields)); - return optionObject; - } - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2DecoratorReturnBuilder.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2DecoratorReturnBuilder.cs deleted file mode 100644 index 6edf6b9c..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObject2DecoratorReturnBuilder.cs +++ /dev/null @@ -1,57 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class OptionObject2Decorator - { - public class OptionObject2DecoratorReturnBuilder - { - private readonly OptionObject2Decorator _decorator; - - public OptionObject2DecoratorReturnBuilder(OptionObject2Decorator decorator) - { - _decorator = decorator; - } - - public OptionObject2DecoratorReturnBuilder WithErrorCode(double errorCode) - { - _decorator.ErrorCode = errorCode; - return this; - } - - public OptionObject2DecoratorReturnBuilder WithErrorMesg(string errorMesg) - { - _decorator.ErrorMesg = errorMesg; - return this; - } - - public OptionObject2 AsOptionObject2() - { - var optionObject = OptionObject2.Initialize(); - optionObject.EntityID = _decorator.EntityID; - optionObject.EpisodeNumber = _decorator.EpisodeNumber; - optionObject.ErrorCode = _decorator.ErrorCode; - optionObject.ErrorMesg = _decorator.ErrorMesg; - optionObject.Facility = _decorator.Facility; - optionObject.NamespaceName = _decorator.NamespaceName; - optionObject.OptionId = _decorator.OptionId; - optionObject.OptionStaffId = _decorator.OptionStaffId; - optionObject.OptionUserId = _decorator.OptionUserId; - optionObject.ParentNamespace = _decorator.ParentNamespace; - optionObject.ServerName = _decorator.ServerName; - optionObject.SystemCode = _decorator.SystemCode; - - foreach (var form in _decorator.Forms) - { - var formObject = form.Return().AsFormObject(); - if (formObject != null && - (formObject.CurrentRow != null || - formObject.OtherRows.Count > 0)) - optionObject.Forms.Add(formObject); - } - - return optionObject; - } - } - } -} \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObjectDecorator.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObjectDecorator.cs deleted file mode 100644 index 0d703e6d..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObjectDecorator.cs +++ /dev/null @@ -1,224 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects; -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; -using System; -using System.Collections.Generic; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class OptionObjectDecorator - { - private readonly IOptionObject _optionObject; - - public double ErrorCode { get; set; } - public string ErrorMesg { get; set; } - public List Forms { get; set; } - - public OptionObjectDecorator(OptionObject optionObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject)); - _optionObject = optionObject.Clone(); - - Forms = new List(); - foreach (var form in optionObject.Forms ?? new List()) - { - Forms.Add(new FormObjectDecorator(form)); - } - } - - public string EntityID => _optionObject.EntityID; - public double EpisodeNumber => _optionObject.EpisodeNumber; - public string Facility => _optionObject.Facility; - public string OptionId => _optionObject.OptionId; - public string OptionStaffId => _optionObject.OptionStaffId; - public string OptionUserId => _optionObject.OptionUserId; - public string SystemCode => _optionObject.SystemCode; - - /// - /// Adds a to an . - /// - /// - public void AddFormObject(FormObject formObject) => Forms = Helper.AddFormObject(this, formObject).Forms; - - /// - /// Adds a to an . - /// - /// - public void AddFormObject(FormObjectDecorator formObject) => Forms = Helper.AddFormObject(this, formObject).Forms; - - /// - /// Adds a to an . - /// - /// - public void AddFormObject(string formId) => Forms = Helper.AddFormObject(this, formId).Forms; - - /// - /// Adds a to an . - /// - /// - /// - public void AddFormObject(string formId, bool multipleIteration) => Forms = Helper.AddFormObject(this, formId, multipleIteration).Forms; - - /// - /// Adds a to a specified within the . - /// - /// - /// - public void AddRowObject(string formId, RowObject rowObject) => Forms = Helper.AddRowObject(this, formId, rowObject).Forms; - - /// - /// Flags a for deletion in a specified within the by RowId. - /// - /// - /// - public void DeleteRowObject(string formId, string rowId) => Forms = Helper.DeleteRowObject(this, formId, rowId).Forms; - - /// - /// Disables all in the . - /// - public void DisableAllFieldObjects() => Forms = Helper.DisableAllFieldObjects(this).Forms; - - /// - /// Disables all in the , except for the FieldNumbers specified in the list. - /// - /// - public void DisableAllFieldObjects(List excludedFields) => Forms = Helper.DisableAllFieldObjects(this, excludedFields).Forms; - - /// - /// Returns the CurrentRow RowId of the form matching the FormId. - /// - /// - /// - public string GetCurrentRowId(string formId) => Helper.GetCurrentRowId(this, formId); - - /// - /// Returns the first value of the field matching the Field Number. - /// - /// - /// - public string GetFieldValue(string fieldNumber) => Helper.GetFieldValue(this, fieldNumber); - - /// - /// Returns the value of the matching the Field Number on the specified and . - /// - /// - /// - public string GetFieldValue(string formId, string rowId, string fieldNumber) => Helper.GetFieldValue(this, formId, rowId, fieldNumber); - - /// - /// Returns the values of the field matching the Field Number. - /// - /// - /// - public List GetFieldValues(string fieldNumber) => Helper.GetFieldValues(this, fieldNumber); - - /// - /// Returns the Multiple Iteration Status of the form matching the FormId. - /// - /// - /// - public bool GetMultipleIterationStatus(string formId) => Helper.GetMultipleIterationStatus(this, formId); - - /// - /// Returns the CurrentRow ParentRowId of the form matching the FormId. - /// - /// - /// - public string GetParentRowId(string formId) => Helper.GetParentRowId(this, formId); - - /// - /// Returns whether the specified field is enabled. - /// - /// - /// - public bool IsFieldEnabled(string fieldNumber) => Helper.IsFieldEnabled(this, fieldNumber); - - /// - /// Returns whether the specified field is locked. - /// - /// - /// - public bool IsFieldLocked(string fieldNumber) => Helper.IsFieldLocked(this, fieldNumber); - - /// - /// Returns whether the specified field is modified. - /// - /// - /// - public bool IsFieldModified(string fieldNumber) => Helper.IsFieldModified(this, fieldNumber); - - /// - /// Returns whether the specified field is present. - /// - /// - /// - public bool IsFieldPresent(string fieldNumber) => Helper.IsFieldPresent(this, fieldNumber); - - /// - /// Returns whether the specified field is required. - /// - /// - /// - public bool IsFieldRequired(string fieldNumber) => Helper.IsFieldRequired(this, fieldNumber); - - /// - /// Returns whether the specified is present. - /// - /// - /// - public bool IsFormPresent(string formId) => Helper.IsFormPresent(this, formId); - - /// - /// Returns whether the specified is marked for deletion. - /// - /// - /// - public bool IsRowMarkedForDeletion(string rowId) => Helper.IsRowMarkedForDeletion(this, rowId); - - /// - /// Returns whether the specified is present. - /// - /// - /// - public bool IsRowPresent(string rowId) => Helper.IsRowPresent(this, rowId); - - /// - /// Creates a return builder for the . - /// - /// - public OptionObjectDecoratorReturnBuilder Return() - { - return new OptionObjectDecoratorReturnBuilder(this); - } - - /// - /// Sets the FieldValue of a in the on the first form CurrentRow. - /// - /// - /// - public void SetFieldValue(string fieldNumber, string fieldValue) => Forms = Helper.SetFieldValue(this, fieldNumber, fieldValue).Forms; - - /// - /// Sets the FieldValue of a in the - /// - /// - /// - /// - /// - public void SetFieldValue(string formId, string rowId, string fieldNumber, string fieldValue) => Forms = Helper.SetFieldValue(this, formId, rowId, fieldNumber, fieldValue).Forms; - - /// - /// Creates an with the minimal information required to return. - /// - /// - public OptionObject ToReturnOptionObject() => Return().AsOptionObject(); - - /// - /// Creates an with the minimal information required to return plus the provide Error Code and Message. - /// - /// - /// - /// - public OptionObject ToReturnOptionObject(double errorCode, string errorMessage) => Return().WithErrorCode(errorCode).WithErrorMesg(errorMessage).AsOptionObject(); - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObjectDecoratorHelper.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObjectDecoratorHelper.cs deleted file mode 100644 index 40193d6b..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObjectDecoratorHelper.cs +++ /dev/null @@ -1,480 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Reflection; -using System.Resources; -using RarelySimple.AvatarScriptLink.Net.Exceptions; -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class OptionObjectDecorator - { - private sealed class Helper : DecoratorHelper - { - private static readonly ResourceManager resourceManager = new ResourceManager("RarelySimple.AvatarScriptLink.Net.Localizations", Assembly.GetExecutingAssembly()); - - /// - /// Adds a to an . - /// - /// - /// - /// - public static OptionObjectDecorator AddFormObject(OptionObjectDecorator optionObject, FormObject formObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return AddFormObject(optionObject, new FormObjectDecorator(formObject)); - } - /// - /// Adds a to an . - /// - /// - /// - /// - public static OptionObjectDecorator AddFormObject(OptionObjectDecorator optionObject, FormObjectDecorator formObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formObject == null) - throw new ArgumentNullException(nameof(formObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms.Count == 0 && formObject.MultipleIteration) - throw new ArgumentException(resourceManager.GetString("firstFormCannotBeMultipleIteration", CultureInfo.CurrentCulture)); - if (optionObject.Forms.Contains(formObject) || optionObject.Forms.Exists(f => f.FormId == formObject.FormId)) - throw new ArgumentException(resourceManager.GetString("formIdAlreadyExists", CultureInfo.CurrentCulture)); - optionObject.Forms.Add(formObject); - return optionObject; - } - /// - /// Creates a with specified FormId and adds to an using provided FormId. - /// - /// - /// - /// - public static OptionObjectDecorator AddFormObject(OptionObjectDecorator optionObject, string formId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formId == null) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - FormObjectDecorator formObject = FormObjectDecorator.Builder() - .FormId(formId) - .Build(); - return AddFormObject(optionObject, formObject); - } - /// - /// Creates a with specified FormId and adds to an using provided FormId and indicating whether it is a multiple iteration table. - /// - /// - /// - /// - /// - public static OptionObjectDecorator AddFormObject(OptionObjectDecorator optionObject, string formId, bool multipleIteration) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (formId == null) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - FormObjectDecorator formObject = FormObjectDecorator.Builder() - .FormId(formId) - .MultipleIteration(multipleIteration) - .Build(); - return AddFormObject(optionObject, formObject); - } - /// - /// Gets the CurrentRow.RowId of the in the by FormId. - /// - /// - /// - /// - public static string GetCurrentRowId(OptionObjectDecorator optionObject, string formId) - { - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (var formObject in optionObject.Forms) - { - if (formObject.FormId == formId) - return formObject.GetCurrentRowId(); - } - throw new ArgumentException(resourceManager.GetString("noFormObjectsFoundByFormId", CultureInfo.CurrentCulture), nameof(optionObject)); - } - /// - /// Returns the FieldValue of a specified in an by FieldNumber. - /// - /// - /// - /// - public static string GetFieldValue(OptionObjectDecorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.GetFieldValue(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns the FieldValue of a specified in an by FormId, RowId, and FieldNumber. - /// - /// - /// - /// - /// - /// - public static string GetFieldValue(OptionObjectDecorator optionObject, string formId, string rowId, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (var form in optionObject.Forms) - { - if (form.FormId == formId) - return form.GetFieldValue(rowId, fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns a list of FieldValues of a specified in the by FieldNumber. - /// - /// - /// - /// - public static List GetFieldValues(OptionObjectDecorator optionObject, string fieldNumber) - { - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(f => f.IsFieldPresent(fieldNumber)); - if (form != null) - return form.GetFieldValues(fieldNumber); - return new List(); - } - /// - /// Returns whether a in the is Multiple Iteration by specified FormId. - /// - /// - /// - /// - public static bool GetMultipleIterationStatus(OptionObjectDecorator optionObject, string formId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - foreach (var form in optionObject.Forms) - { - if (form.FormId == formId) - return form.GetMultipleIterationStatus(); - } - throw new FormObjectNotFoundException(string.Format(resourceManager.GetString(NoFormObjectsFoundByFormId, CultureInfo.CurrentCulture), formId), formId); - } - /// - /// Returns the ParentRowId of a in the by FormId. - /// - /// - /// - /// - public static string GetParentRowId(OptionObjectDecorator optionObject, string formId) - { - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (var formObject in optionObject.Forms) - { - if (formObject.FormId == formId) - return formObject.GetParentRowId(); - } - throw new ArgumentException(resourceManager.GetString("noFormObjectsFoundByFormId", CultureInfo.CurrentCulture), nameof(formId)); - } - /// - /// Returns whether the in the is enabled by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldEnabled(OptionObjectDecorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldEnabled(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether the in the is locked by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldLocked(OptionObjectDecorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldLocked(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether the in the is modified by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldModified(OptionObjectDecorator optionObject, string fieldNumber) - { - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(f => f.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldModified(fieldNumber); - } - throw new ArgumentException("The OptionObject does not contain the FieldObject " + fieldNumber + "."); - } - /// - /// Returns whether the in the is present by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldPresent(OptionObjectDecorator decorator, string fieldNumber) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Forms == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return decorator.Forms.Find(x => x.IsFieldPresent(fieldNumber)) != null; - } - /// - /// Returns whether the in the is required by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldRequired(OptionObjectDecorator optionObject, string fieldNumber) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = optionObject.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - return form.IsFieldRequired(fieldNumber); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether a exists in an by . - /// - /// - /// - /// - public static bool IsFormPresent(OptionObjectDecorator optionObject, string formId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null || optionObject.Forms.Count == 0) - return false; - return optionObject.Forms.Exists(f => f.FormId == formId); - } - /// - /// Returns whether the in an is marked for deletion by RowId. - /// - /// - /// - /// - public static bool IsRowMarkedForDeletion(OptionObjectDecorator optionObject, string rowId) - { - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return optionObject.Forms.Find(f => f.IsRowMarkedForDeletion(rowId)) != null; - } - /// - /// Returns whether the in the is enabled by RowId. - /// - /// - /// - /// - public static bool IsRowPresent(OptionObjectDecorator optionObject, string rowId) - { - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return optionObject.Forms.Find(x => x.IsRowPresent(rowId)) != null; - } - /// - /// Sets the FieldValue of a in an by FieldNumber. - /// - /// - /// - /// - /// - public static OptionObjectDecorator SetFieldValue(OptionObjectDecorator decorator, string fieldNumber, string fieldValue) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Forms == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - var form = decorator.Forms.Find(x => x.IsFieldPresent(fieldNumber)); - if (form != null) - { - if (form.MultipleIteration && form.OtherRows.Count > 0) - throw new ArgumentException(resourceManager.GetString(UnableToIdentifyFieldObject, CultureInfo.CurrentCulture), nameof(decorator)); - return SetFieldValue(decorator, form.FormId, form.CurrentRow.RowId, fieldNumber, fieldValue); - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Sets the FieldValue of a in an by FormId, RowID, and FieldNumber. - /// - /// - /// - /// - /// - /// - /// - public static OptionObjectDecorator SetFieldValue(OptionObjectDecorator decorator, string formId, string rowId, string fieldNumber, string fieldValue) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Forms == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - for (int i = 0; i < decorator.Forms.Count; i++) - { - if (decorator.Forms[i].FormId == formId) - decorator.Forms[i].SetFieldValue(rowId, fieldNumber, fieldValue); - } - return decorator; - } - /// - /// Executes an operation on a form within the OptionObjectDecorator by FormId. - /// - /// - /// - /// - /// - private static OptionObjectDecorator ExecuteOnForm(OptionObjectDecorator optionObject, string formId, Action action) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(formId)) - throw new ArgumentNullException(nameof(formId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms.Exists(f => f.FormId == formId)) - { - int formIndex = optionObject.Forms.FindIndex(f => f.FormId == formId); - if (formIndex >= 0) - { - action(optionObject.Forms[formIndex]); - } - } - else - { - throw new ArgumentException(resourceManager.GetString("noFormObjectsFoundByFormId", CultureInfo.CurrentCulture), nameof(formId)); - } - return optionObject; - } - /// - /// Adds a to a specified within provided . - /// - /// - /// - /// - /// - public static OptionObjectDecorator AddRowObject(OptionObjectDecorator optionObject, string formId, RowObject rowObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return ExecuteOnForm(optionObject, formId, form => form.AddRowObject(rowObject)); - } - /// - /// Flags a for deletion in a specified within the by RowId. - /// - /// - /// - /// - /// - public static OptionObjectDecorator DeleteRowObject(OptionObjectDecorator optionObject, string formId, string rowId) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(rowId)) - throw new ArgumentNullException(nameof(rowId), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return ExecuteOnForm(optionObject, formId, form => form.DeleteRowObject(rowId)); - } - /// - /// Disables all in the . - /// - /// - /// - public static OptionObjectDecorator DisableAllFieldObjects(OptionObjectDecorator optionObject) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return DisableAllFieldObjects(optionObject, new List()); - } - /// - /// Disables all in the , except for the FieldNumbers specified in the list. - /// - /// - /// - /// - public static OptionObjectDecorator DisableAllFieldObjects(OptionObjectDecorator optionObject, List excludedFields) - { - if (optionObject == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (optionObject.Forms == null) - throw new ArgumentNullException(nameof(optionObject), resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture)); - if (optionObject.Forms.Count == 0) - throw new ArgumentException(resourceManager.GetString(OptionObjectMissingForms, CultureInfo.CurrentCulture), nameof(optionObject)); - if (excludedFields == null) - throw new ArgumentNullException(nameof(excludedFields), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - - optionObject.Forms.ForEach(f => f.DisableAllFieldObjects(excludedFields)); - return optionObject; - } - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObjectDecoratorReturnBuilder.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObjectDecoratorReturnBuilder.cs deleted file mode 100644 index fbc26000..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/OptionObjectDecoratorReturnBuilder.cs +++ /dev/null @@ -1,54 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class OptionObjectDecorator - { - public class OptionObjectDecoratorReturnBuilder - { - private readonly OptionObjectDecorator _decorator; - - public OptionObjectDecoratorReturnBuilder(OptionObjectDecorator decorator) - { - _decorator = decorator; - } - - public OptionObjectDecoratorReturnBuilder WithErrorCode(double errorCode) - { - _decorator.ErrorCode = errorCode; - return this; - } - - public OptionObjectDecoratorReturnBuilder WithErrorMesg(string errorMesg) - { - _decorator.ErrorMesg = errorMesg; - return this; - } - - public OptionObject AsOptionObject() - { - var optionObject = OptionObject.Initialize(); - optionObject.EntityID = _decorator.EntityID; - optionObject.EpisodeNumber = _decorator.EpisodeNumber; - optionObject.ErrorCode = _decorator.ErrorCode; - optionObject.ErrorMesg = _decorator.ErrorMesg; - optionObject.Facility = _decorator.Facility; - optionObject.OptionId = _decorator.OptionId; - optionObject.OptionStaffId = _decorator.OptionStaffId; - optionObject.OptionUserId = _decorator.OptionUserId; - optionObject.SystemCode = _decorator.SystemCode; - - foreach (var form in _decorator.Forms) - { - var formObject = form.Return().AsFormObject(); - if (formObject != null && - (formObject.CurrentRow != null || - formObject.OtherRows.Count > 0)) - optionObject.Forms.Add(formObject); - } - - return optionObject; - } - } - } -} \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/RowObjectDecorator.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/RowObjectDecorator.cs deleted file mode 100644 index a3a13b62..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/RowObjectDecorator.cs +++ /dev/null @@ -1,106 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects; -using System; -using System.Collections.Generic; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class RowObjectDecorator - { - private readonly RowObject _rowObject; - - public List Fields { get; set; } - public string RowAction { get; set; } - - public RowObjectDecorator(RowObject rowObject) - { - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject)); - _rowObject = rowObject; - RowAction = rowObject.RowAction; - - Fields = new List(); - foreach (var fieldObject in rowObject.Fields) - { - Fields.Add(new FieldObjectDecorator(fieldObject)); - } - } - - public string ParentRowId => _rowObject.ParentRowId; - public string RowId => _rowObject.RowId; - - public RowObjectDecoratorReturnBuilder Return() - { - return new RowObjectDecoratorReturnBuilder(this); - } - - /// - /// Adds a to a . - /// - /// - public void AddFieldObject(FieldObject fieldObject) => Fields = Helper.AddFieldObject(this, fieldObject).Fields; - - /// - /// Returns the value of a in a - /// - /// - /// - public string GetFieldValue(string fieldNumber) => Helper.GetFieldValue(this, fieldNumber); - - /// - /// Determines whether a is enabled in the . - /// - /// - public bool IsFieldEnabled(string fieldNumber) => Helper.IsFieldEnabled(this, fieldNumber); - - /// - /// Determines whether a is locked in the . - /// - /// - public bool IsFieldLocked(string fieldNumber) => Helper.IsFieldLocked(this, fieldNumber); - - /// - /// Determines whether a is modified in by FieldNumber. - /// - /// - /// - public bool IsFieldModified(string fieldNumber) => Helper.IsFieldModified(this, fieldNumber); - - /// - /// Determines whether a is present in by FieldNumber. - /// - /// - /// - public bool IsFieldPresent(string fieldNumber) => Helper.IsFieldPresent(this, fieldNumber); - - /// - /// Determines whether a is required in the . - /// - /// - public bool IsFieldRequired(string fieldNumber) => Helper.IsFieldRequired(this, fieldNumber); - - /// - /// Sets the value of a in the . - /// - /// - /// - /// - public void SetFieldValue(string fieldNumber, string fieldValue) => Fields = Helper.SetFieldValue(this, fieldNumber, fieldValue).Fields; - - /// - /// Disables all in the . - /// - public void DisableAllFieldObjects() - { - Fields = Helper.DisableAllFieldObjects(this).Fields; - } - - /// - /// Disables all in the , except for the FieldNumbers specified in the list. - /// - /// - public void DisableAllFieldObjects(List excludedFields) - { - Fields = Helper.DisableAllFieldObjects(this, excludedFields).Fields; - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/RowObjectDecoratorHelper.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/RowObjectDecoratorHelper.cs deleted file mode 100644 index d25e8c8b..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/RowObjectDecoratorHelper.cs +++ /dev/null @@ -1,236 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Reflection; -using System.Resources; -using RarelySimple.AvatarScriptLink.Net.Exceptions; -using RarelySimple.AvatarScriptLink.Objects; -using static RarelySimple.AvatarScriptLink.Objects.RowObject; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class RowObjectDecorator - { - private sealed class Helper : DecoratorHelper - { - private static readonly ResourceManager resourceManager = new ResourceManager("RarelySimple.AvatarScriptLink.Net.Localizations", Assembly.GetExecutingAssembly()); - - /// - /// Adds a to a . - /// - /// - /// - /// - public static RowObjectDecorator AddFieldObject(RowObjectDecorator decorator, FieldObject fieldObject) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (fieldObject == null) - throw new ArgumentNullException(nameof(fieldObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Fields.Contains(new FieldObjectDecorator(fieldObject))) - throw new ArgumentException(resourceManager.GetString(FieldObjectAlreadyExists, CultureInfo.CurrentCulture), nameof(fieldObject)); - if (decorator.Fields.Exists(f => f.FieldNumber == fieldObject.FieldNumber)) - throw new ArgumentException(resourceManager.GetString(FieldNumberAlreadyExists, CultureInfo.CurrentCulture)); - decorator.Fields.Add(new FieldObjectDecorator(fieldObject.FieldNumber) - { - // Setting other attributes after to flag as modified - Enabled = fieldObject.IsEnabled(), - FieldValue = fieldObject.FieldValue, - Locked = fieldObject.IsLocked(), - Required = fieldObject.IsRequired() - }); - if (decorator.RowAction == RowActions.None) - decorator.RowAction = RowActions.Edit; - return decorator; - } - /// - /// Returns the FieldValue of a in a by FieldNumber. - /// - /// - /// - /// - public static string GetFieldValue(RowObjectDecorator rowObject, string fieldNumber) - { - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (FieldObjectDecorator field in rowObject.Fields) - { - if (field.FieldNumber == fieldNumber) - return field.FieldValue; - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether the in the is enabled by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldEnabled(RowObjectDecorator rowObject, string fieldNumber) - { - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (rowObject.Fields == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(RowObjectMissingFields, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (FieldObjectDecorator field in rowObject.Fields) - { - if (field.FieldNumber == fieldNumber) - return field.Enabled; - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether the in the is locked by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldLocked(RowObjectDecorator rowObject, string fieldNumber) - { - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (rowObject.Fields == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(RowObjectMissingFields, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (FieldObjectDecorator field in rowObject.Fields) - { - if (field.FieldNumber == fieldNumber) - return field.Locked; - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Returns whether the in the is modified by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldModified(RowObjectDecorator rowObject, string fieldNumber) - { - if (rowObject.Fields == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString("rowObjectMissingFields", CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (FieldObjectDecorator field in rowObject.Fields) - { - if (field.FieldNumber == fieldNumber) - return field.IsModified(); - } - throw new ArgumentException(resourceManager.GetString("noFieldObjectsFoundByFieldNumber", CultureInfo.CurrentCulture) + fieldNumber, nameof(fieldNumber)); - } - /// - /// Returns whether the in the is present by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldPresent(RowObjectDecorator decorator, string fieldNumber) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (decorator.Fields == null) - return false; - foreach (var field in decorator.Fields) - { - if (field.FieldNumber == fieldNumber) - return true; - } - return false; - } - /// - /// Returns whether the in the is required by FieldNumber. - /// - /// - /// - /// - public static bool IsFieldRequired(RowObjectDecorator rowObject, string fieldNumber) - { - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (rowObject.Fields == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(RowObjectMissingFields, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (FieldObjectDecorator field in rowObject.Fields) - { - if (field.FieldNumber == fieldNumber) - return field.Required; - } - throw new FieldObjectNotFoundException(string.Format(resourceManager.GetString(NoFieldObjectsFoundByFieldNumber, CultureInfo.CurrentCulture), fieldNumber), fieldNumber); - } - /// - /// Sets the FieldValue of a in a by FieldNumber. - /// - /// - /// - /// - /// - public static RowObjectDecorator SetFieldValue(RowObjectDecorator decorator, string fieldNumber, string fieldValue) - { - if (decorator == null) - throw new ArgumentNullException(nameof(decorator), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (string.IsNullOrEmpty(fieldNumber)) - throw new ArgumentNullException(nameof(fieldNumber), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - foreach (var fieldObject in decorator.Fields) - { - if (fieldObject.FieldNumber == fieldNumber) - { - fieldObject.FieldValue = fieldValue; - if (decorator.RowAction == RowActions.None) - decorator.RowAction = RowActions.Edit; - break; - } - } - return decorator; - } - /// - /// Disables all in the . - /// - /// - /// - public static RowObjectDecorator DisableAllFieldObjects(RowObjectDecorator rowObject) - { - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - return DisableAllFieldObjects(rowObject, new List()); - } - /// - /// Disables all in the , except for the FieldNumbers specified in the list. - /// - /// - /// - /// - public static RowObjectDecorator DisableAllFieldObjects(RowObjectDecorator rowObject, List excludedFields) - { - if (rowObject == null) - throw new ArgumentNullException(nameof(rowObject), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - if (excludedFields == null) - throw new ArgumentNullException(nameof(excludedFields), resourceManager.GetString(ParameterCannotBeNull, CultureInfo.CurrentCulture)); - - foreach (var field in rowObject.Fields.Where(f => !excludedFields.Contains(f.FieldNumber))) - { - field.Enabled = false; - } - - // Only set RowAction to Edit if it's currently None (no action). - // This preserves existing RowActions like DELETE, ADD, or EDIT: - // - RowActions.None: No action pending (preserve the row; enable Edit mode) - // - RowActions.Add: Adding a new row to the form (don't override) - // - RowActions.Edit: Modifying an existing row (don't override) - // - RowActions.Delete: Removing the row (don't override) - if (rowObject.RowAction == RowActions.None) - rowObject.RowAction = RowActions.Edit; - - return rowObject; - } - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/RowObjectDecoratorReturnBuilder.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/RowObjectDecoratorReturnBuilder.cs deleted file mode 100644 index ae218c4f..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Decorators/RowObjectDecoratorReturnBuilder.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Linq; -using RarelySimple.AvatarScriptLink.Objects; - -namespace RarelySimple.AvatarScriptLink.Net.Decorators -{ - public sealed partial class RowObjectDecorator - { - public class RowObjectDecoratorReturnBuilder - { - private readonly RowObjectDecorator _decorator; - - public RowObjectDecoratorReturnBuilder(RowObjectDecorator decorator) - { - _decorator = decorator; - } - - public RowObject AsRowObject() - { - var rowObject = RowObject.Initialize(); - rowObject.ParentRowId = _decorator.ParentRowId; - rowObject.RowAction = _decorator.RowAction; - rowObject.RowId = _decorator.RowId; - - foreach (var fieldObjectDecorator in _decorator.Fields.Where(field => field.IsModified())) - { - rowObject.Fields.Add(fieldObjectDecorator.Return().AsFieldObject()); - } - return rowObject; - } - } - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/ErrorCode.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/ErrorCode.cs deleted file mode 100644 index 3f9540f6..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/ErrorCode.cs +++ /dev/null @@ -1,73 +0,0 @@ -namespace RarelySimple.AvatarScriptLink.Net -{ - /// - /// The selected ErrorCode informs myAvatar whether an error occurred, there is a message to display, a URL to open, or a form to open. - /// - public static class ErrorCode - { - /// - /// Returns no message. - /// This is the equivalent of . - /// - public const double None = 0; - /// - /// Returns a success code. - /// This is the equivalent of . - /// - public const double Success = 0; - /// - /// Returns provided message with an Ok button. - /// Script processing will be stopped on the form. - /// - public const double Error = 1; - /// - /// Returns provided message with Ok and Cancel buttons. - /// Script processing will be stopped on the form, if user selects Cancel. - /// This is the equivalent of . - /// - public const double OkCancel = 2; - /// - /// Returns provided message with Ok and Cancel buttons. - /// Script processing will be stopped on the form, if user selects Cancel. - /// This is the equivalent of . - /// - public const double Warning = 2; - /// - /// Returns provided message with an Ok button. - /// This is the equivalent of and . - /// - public const double Info = 3; - /// - /// Returns provided message with an Ok button. - /// This is the equivalent of . - /// - public const double Informational = 3; - /// - /// Returns provided message with an Ok button. - /// This is the equivalent of . - /// - public const double Alert = 3; - /// - /// Returns provided message with Yes and No buttons. - /// Script processing will be stopped on the form, if user selects Cancel. - /// This is the equivalent of . - /// - public const double YesNo = 4; - /// - /// Returns provided message with Yes and No buttons. - /// Script processing will be stopped on the form, if user selects Cancel. - /// This is the equivalent of . - /// - public const double Confirm = 4; - /// - /// Opens provided Url in default web browser. - /// The URL to open must be placed in the ErrorMesg property. - /// - public const double OpenUrl = 5; - /// - /// Returns a message with Ok and Cancel buttons. - /// Opens specified form(s) if OK selected. Can only be used at Form Load and FieldObject OnLostFocus events. - /// - public const double OpenForm = 6; - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Exceptions/FieldObjectNotFoundException.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Exceptions/FieldObjectNotFoundException.cs deleted file mode 100644 index bd1a9c8f..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Exceptions/FieldObjectNotFoundException.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; - -namespace RarelySimple.AvatarScriptLink.Net.Exceptions -{ - /// - /// The exception that is thrown when a method call attempts to read or modify a FieldObject that does not exist. - /// - public class FieldObjectNotFoundException : Exception - { - public string FieldNumber { get; } - /// - /// Initializes a new instance of the class. - /// - public FieldObjectNotFoundException() { } - /// - /// Initializes a new instance of the class with a specified error message. - /// - /// - public FieldObjectNotFoundException(string message) : base(message) { } - /// - /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - /// - /// - /// - public FieldObjectNotFoundException(string message, Exception inner) : base(message, inner) { } - /// - /// Initializes a new instance of the class with a specified error message and the field number that could not be found. - /// - /// - /// - public FieldObjectNotFoundException(string message, string fieldNumber) : this(message) - { - FieldNumber = fieldNumber; - } - /// - /// Initializes a new instance of the class with a specified error message, the field number that could not be found, and a reference to the inner exception that is the cause of this exception. - /// - /// - /// - /// - public FieldObjectNotFoundException(string message, string fieldNumber, Exception inner) : this(message, inner) - { - FieldNumber = fieldNumber; - } - } -} \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Exceptions/FormObjectNotFoundException.cs b/dotnet/RarelySimple.AvatarScriptLink.Net/Exceptions/FormObjectNotFoundException.cs deleted file mode 100644 index 0856fece..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Exceptions/FormObjectNotFoundException.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; - -namespace RarelySimple.AvatarScriptLink.Net.Exceptions -{ - /// - /// The exception that is thrown when a method call attempts to read or modify a FormObject that does not exist. - /// - public class FormObjectNotFoundException : Exception - { - public string FormId { get; } - /// - /// Initializes a new instance of the class. - /// - public FormObjectNotFoundException() { } - /// - /// Initializes a new instance of the class with a specified error message. - /// - /// - public FormObjectNotFoundException(string message) : base(message) { } - /// - /// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - /// - /// - /// - public FormObjectNotFoundException(string message, Exception inner) : base(message, inner) { } - /// - /// Initializes a new instance of the class with a specified error message and the field number that could not be found. - /// - /// - /// - public FormObjectNotFoundException(string message, string formId) : this(message) - { - FormId = formId; - } - /// - /// Initializes a new instance of the class with a specified error message, the field number that could not be found, and a reference to the inner exception that is the cause of this exception. - /// - /// - /// - /// - public FormObjectNotFoundException(string message, string formId, Exception inner) : this(message, inner) - { - FormId = formId; - } - } -} \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/Localizations.resx b/dotnet/RarelySimple.AvatarScriptLink.Net/Localizations.resx deleted file mode 100644 index 0ea7d6f5..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/Localizations.resx +++ /dev/null @@ -1,207 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Cannot add another RowObject to this FormObject because either it is not a Multiple Iteration form or it already has the maximun number of rows. - - - Could not determine next available RowId in this FormObject. - - - Error Code is not valid. - - - Error Message is not a valid OpenForm string. - - - Error Message is not a valid URL string. - - - The RowObject already contains a FieldObject with this FieldNumber. - - - The RowObject already contains this FieldObject. - - - The first FormObject cannot be a Multiple Iteration form. - - - A FormObject with this FormId already exists. - - - The FormObject does not contain a CurrentRow. - - - The FormObject does not contain any rows. - - - JSON string could not be deserialized to desired object. - - - This method cannot be inherited. Please create new implementation in the derived class. - - - None of the identified FieldsObjects were found in this OptionObject. - - - No FieldObjects were found matching provided FieldNumber: {0} - - - None of the identified FieldsObjects were able to be set. - - - No FormObjects were found matching provided FormId: {0} - - - No RowObjects were found matching provided RowId: {0}. - - - Object could not be serialized as JSON. - - - Object could not be serialized as XML. - - - Object could not be serialized as XML or JSON. - - - The OptionObject does not contain any forms. - - - Parameter cannot be null. - - - Parameter is not valid. - - - A RowObject with this RowId already exists in this FormObject. - - - The RowObject does not contain any fields. - - - Serialized string is not in a compatible format - - - Unable to determine which FieldObject to update. Please specify the FormId and RowId associated with the intended FieldObject. - - - XML string could not be deserialized to desired object. - - \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/README.md b/dotnet/RarelySimple.AvatarScriptLink.Net/README.md index 930b4c08..07a16ee5 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/README.md +++ b/dotnet/RarelySimple.AvatarScriptLink.Net/README.md @@ -2,64 +2,81 @@ [![NuGet Latest](https://img.shields.io/nuget/v/RarelySimple.AvatarScriptLink.Net)](https://www.nuget.org/packages/RarelySimple.AvatarScriptLink.Net/) [![NuGet Downloads](https://img.shields.io/nuget/dt/RarelySimple.AvatarScriptLink.Net)](https://www.nuget.org/packages/RarelySimple.AvatarScriptLink.Net/) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rarelysimple_RarelySimple.AvatarScriptLink.Net&metric=alert_status)](https://sonarcloud.io/dashboard?id=rarelysimple_RarelySimple.AvatarScriptLink.Net) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=rarelysimple_RarelySimple.AvatarScriptLink.Net&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=rarelysimple_RarelySimple.AvatarScriptLink.Net) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=rarelysimple_RarelySimple.AvatarScriptLink.Net&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=rarelysimple_RarelySimple.AvatarScriptLink.Net) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=rarelysimple_RarelySimple.AvatarScriptLink.Net&metric=security_rating)](https://sonarcloud.io/dashboard?id=rarelysimple_RarelySimple.AvatarScriptLink.Net) -RarelySimple.AvatarScriptLink.Net provides helpers and utilities to accelerate your [myAvatar](https://www.ntst.com/Solutions-and-Services/Offerings/myAvatar) ScriptLink development. +**RarelySimple.AvatarScriptLink.Net** is a batteries-included meta-package that provides all the tools you need for [myAvatar](https://www.ntst.com/Solutions-and-Services/Offerings/myAvatar) ScriptLink development. -# Example +## What's Included -Most ScriptLink-compatible APIs are working with the ScriptLink objects and are resposible for handling all aspects of reading, updating, and returning them. Here's what a "Hello, World!" response might look like in this scenario. +This package includes: + +- **Objects** - Core ScriptLink data types and constants (OptionObject, FormObject, RowObject, FieldObject, ErrorCode) +- **Builders** - Fluent builder pattern for creating ScriptLink objects +- **Converters** - Deep-copy and cross-variant conversion utilities +- **Helpers** - Extension methods for querying and manipulating objects +- **Validators** - Response validation for ScriptLink SOAP requirements + +## Quick Start + +Install the package: + +```bash +dotnet add package RarelySimple.AvatarScriptLink.Net +``` + +Build a simple ScriptLink response: + +```csharp +using RarelySimple.AvatarScriptLink.Net; +using RarelySimple.AvatarScriptLink.Objects; +using RarelySimple.AvatarScriptLink.Objects.Builders; -```c# -// Uncomment annotation for .NET Framework *.asmx -// [WebMethod] public OptionObject2015 RunScript(OptionObject2015 optionObject, string parameter) { - // Create return OptionObject - OptionObject2015 returnOptionObject = new OptionObject2015(); - - // Do work - - // Set Error Code and Message - returnOptionObject.ErrorCode = 3; - returnOptionObject.ErrorMesg = "Hello, World!"; - - // Copy required OptionObject attributes - returnOptionObject.EntityID = optionObject.EntityID; - returnOptionObject.EpisodeNumber = optionObject.EpisodeNumber; - returnOptionObject.Facility = optionObject.Facility; - returnOptionObject.NamespaceName = optionObject.NamespaceName; - returnOptionObject.OptionId = optionObject.OptionId; - returnOptionObject.OptionStaffId = optionObject.OptionStaffId; - returnOptionObject.OptionUserId = optionObject.OptionUserId; - returnOptionObject.ParentNamespace = optionObject.ParentNamespace; - returnOptionObject.ServerName = optionObject.ServerName; - returnOptionObject.SessionToken = optionObject.SessionToken; - returnOptionObject.SystemCode = optionObject.SystemCode; - - return returnOptionObject; + return OptionObject2015Builder + .FromOptionObject(optionObject) + .WithErrorCode(ErrorCode.Informational) + .WithErrorMessage("Hello, World!") + .Build(); } ``` -With AvatarScriptLink.NET, this same code can be simplified to: +Query and manipulate field values: -```c# -// Uncomment annotation for .NET Framework *.asmx -// [WebMethod] -public OptionObject2015 RunScript(OptionObject2015 optionObject, string parameter) +```csharp +using RarelySimple.AvatarScriptLink.Objects.Helpers; + +// Get a field value (searches all forms) +string? patientName = optionObject.GetFieldValue("123"); + +// Check if field is present +if (optionObject.IsFieldPresent("456")) { - - var decorator = new OptionObject2015Decorator(optionObject); + // Set field value + optionObject.SetFieldValue("456", formId, rowId, "New Value"); +} + +// Disable all fields in a row except specific ones +row.DisableAllFieldObjects(excludedFieldNumbers: new List { "789" }); +``` + +Validate responses: - // Do work +```csharp +using RarelySimple.AvatarScriptLink.Objects.Validators; - return decorator.Return() - .WithErrorCode(ErrorCode.Alert) - .WithErrorMesg("Hello World!") - .AsOptionObject2015(); +var result = optionObject.ValidateResponse(); +if (!result.IsValid) +{ + foreach (var error in result.Errors) + { + Console.WriteLine(error); + } } ``` +## Documentation + Check out [the documentation](https://scriptlink.rarelysimple.com/) to learn more. -## Licensing ## +## Licensing AvatarScriptLink.NET is open source under the [MIT License](https://github.com/rarelysimple/RarelySimple.AvatarScriptLink/blob/master/LICENSE) and free for commercial use. diff --git a/dotnet/RarelySimple.AvatarScriptLink.Net/RarelySimple.AvatarScriptLink.Net.csproj b/dotnet/RarelySimple.AvatarScriptLink.Net/RarelySimple.AvatarScriptLink.Net.csproj index 44a68e5e..0763e72d 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Net/RarelySimple.AvatarScriptLink.Net.csproj +++ b/dotnet/RarelySimple.AvatarScriptLink.Net/RarelySimple.AvatarScriptLink.Net.csproj @@ -10,7 +10,7 @@ https://scriptlink.rarelysimple.com/ git Copyright © 2026 Scott Olson Jr - RarelySimple.AvatarScriptLink.Net provides helpers and utilities to accelerate your Netsmart myAvatar ScriptLink development. + RarelySimple.AvatarScriptLink.Net is a batteries-included meta-package that provides all the tools and utilities you need for Netsmart myAvatar ScriptLink development, including Objects, Builders, Converters, Helpers, and Validators. en-US true ../RarelySimple.AvatarScriptLink.snk @@ -33,6 +33,10 @@ + + + + diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/BuilderMethodsTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/BuilderMethodsTests.cs new file mode 100644 index 00000000..7d757eb3 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/BuilderMethodsTests.cs @@ -0,0 +1,420 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders.Tests +{ + [TestClass] + public class FieldObjectBuildersTests + { + [TestMethod] + public void CreateFieldObject_WithFieldNumber_ReturnsFieldObjectWithFieldNumber() + { + // Arrange + string fieldNumber = "001"; + + // Act + FieldObject result = FieldObjectBuilders.CreateFieldObject(fieldNumber); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(fieldNumber, result.FieldNumber); + } + + [TestMethod] + public void WithFieldNumber_SetsFieldNumber() + { + // Arrange + var field = new FieldObject(); + string fieldNumber = "002"; + + // Act + FieldObject result = field.WithFieldNumber(fieldNumber); + + // Assert + Assert.AreSame(field, result); // Check fluent interface + Assert.AreEqual(fieldNumber, field.FieldNumber); + } + + [TestMethod] + public void WithFieldValue_SetsFieldValue() + { + // Arrange + var field = new FieldObject(); + string value = "Test Value"; + + // Act + FieldObject result = field.WithFieldValue(value); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual(value, field.FieldValue); + } + + [TestMethod] + public void AsEnabled_EnablesField() + { + // Arrange + var field = new FieldObject { Enabled = "0" }; + + // Act + FieldObject result = field.AsEnabled(true); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual("1", field.Enabled); + } + + [TestMethod] + public void AsEnabled_DisablesField() + { + // Arrange + var field = new FieldObject { Enabled = "1" }; + + // Act + FieldObject result = field.AsEnabled(false); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual("0", field.Enabled); + } + + [TestMethod] + public void AsLocked_LocksField() + { + // Arrange + var field = new FieldObject { Lock = "0" }; + + // Act + FieldObject result = field.AsLocked(true); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual("1", field.Lock); + } + + [TestMethod] + public void AsRequired_MarksRequired() + { + // Arrange + var field = new FieldObject { Required = "0" }; + + // Act + FieldObject result = field.AsRequired(true); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual("1", field.Required); + } + + [TestMethod] + public void FluentBuilder_ChainsMethods() + { + // Arrange & Act + FieldObject result = FieldObjectBuilders.CreateFieldObject("001") + .WithFieldValue("Test") + .AsEnabled(true) + .AsRequired(true); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual("001", result.FieldNumber); + Assert.AreEqual("Test", result.FieldValue); + Assert.AreEqual("1", result.Enabled); + Assert.AreEqual("1", result.Required); + } + } + + [TestClass] + public class FormObjectBuildersTests + { + [TestMethod] + public void CreateFormObject_WithFormId_ReturnsFormObjectWithFormId() + { + // Arrange + string formId = "TestForm"; + + // Act + FormObject result = FormObjectBuilders.CreateFormObject(formId); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(formId, result.FormId); + } + + [TestMethod] + public void WithFormId_SetsFormId() + { + // Arrange + var form = new FormObject(); + string formId = "Form123"; + + // Act + FormObject result = form.WithFormId(formId); + + // Assert + Assert.AreSame(form, result); + Assert.AreEqual(formId, form.FormId); + } + + [TestMethod] + public void WithMultipleIteration_SetsMultipleIteration() + { + // Arrange + var form = new FormObject(); + + // Act + FormObject result = form.WithMultipleIteration(true); + + // Assert + Assert.AreSame(form, result); + Assert.IsTrue(form.MultipleIteration); + } + + [TestMethod] + public void WithCurrentRow_SetsCurrentRow() + { + // Arrange + var form = new FormObject(); + var row = new RowObject { RowId = "1" }; + + // Act + FormObject result = form.WithCurrentRow(row); + + // Assert + Assert.AreSame(form, result); + Assert.AreSame(row, form.CurrentRow); + } + + [TestMethod] + public void AddRow_AddsRowToOtherRows() + { + // Arrange + var form = new FormObject(); + var row = new RowObject { RowId = "2" }; + + // Act + FormObject result = form.AddRow(row); + + // Assert + Assert.AreSame(form, result); + Assert.AreEqual(1, form.OtherRows.Count); + Assert.AreSame(row, form.OtherRows[0]); + } + + [TestMethod] + public void AddRow_IgnoresNullRow() + { + // Arrange + var form = new FormObject(); + + // Act + FormObject result = form.AddRow(null); + + // Assert + Assert.AreSame(form, result); + Assert.AreEqual(0, form.OtherRows.Count); + } + + [TestMethod] + public void FluentBuilder_ChainsMethods() + { + // Arrange + var row1 = new RowObject { RowId = "1" }; + var row2 = new RowObject { RowId = "2" }; + + // Act + FormObject result = FormObjectBuilders.CreateFormObject("TestForm") + .WithMultipleIteration(true) + .WithCurrentRow(row1) + .AddRow(row2); + + // Assert + Assert.AreEqual("TestForm", result.FormId); + Assert.IsTrue(result.MultipleIteration); + Assert.AreSame(row1, result.CurrentRow); + Assert.AreEqual(1, result.OtherRows.Count); + } + } + + [TestClass] + public class RowObjectBuildersTests + { + [TestMethod] + public void CreateRowObject_WithRowId_ReturnsRowObjectWithRowId() + { + // Arrange + string rowId = "1"; + + // Act + RowObject result = RowObjectBuilders.CreateRowObject(rowId); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(rowId, result.RowId); + } + + [TestMethod] + public void WithRowId_SetsRowId() + { + // Arrange + var row = new RowObject(); + string rowId = "123"; + + // Act + RowObject result = row.WithRowId(rowId); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual(rowId, row.RowId); + } + + [TestMethod] + public void WithParentRowId_SetsParentRowId() + { + // Arrange + var row = new RowObject(); + string parentRowId = "parent123"; + + // Act + RowObject result = row.WithParentRowId(parentRowId); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual(parentRowId, row.ParentRowId); + } + + [TestMethod] + public void WithRowAction_SetsRowAction() + { + // Arrange + var row = new RowObject(); + + // Act + RowObject result = row.WithRowAction("ADD"); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual("ADD", row.RowAction); + } + + [TestMethod] + public void AddField_AddsFieldToFields() + { + // Arrange + var row = new RowObject(); + var field = new FieldObject { FieldNumber = "001" }; + + // Act + RowObject result = row.AddField(field); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual(1, row.Fields.Count); + Assert.AreSame(field, row.Fields[0]); + } + + [TestMethod] + public void AddField_IgnoresNullField() + { + // Arrange + var row = new RowObject(); + + // Act + RowObject result = row.AddField(null); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual(0, row.Fields.Count); + } + } + + [TestClass] + public class OptionObjectBuildersTests + { + [TestMethod] + public void CreateOptionObject_WithEntityId_ReturnsOptionObjectWithEntityId() + { + // Arrange + string entityId = "Patient123"; + + // Act + OptionObject result = OptionObjectBuilders.CreateOptionObject(entityId); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(entityId, result.EntityID); + } + + [TestMethod] + public void WithEntityId_SetsEntityId() + { + // Arrange + var option = new OptionObject(); + string entityId = "Test456"; + + // Act + OptionObject result = option.WithEntityId(entityId); + + // Assert + Assert.AreSame(option, result); + Assert.AreEqual(entityId, option.EntityID); + } + + [TestMethod] + public void WithErrorCodeAndMessage_SetsErrorCodeAndMessage() + { + // Arrange + var option = new OptionObject(); + double errorCode = 1; + string errorMessage = "Test Error"; + + // Act + OptionObject result = option.WithErrorCodeAndMessage(errorCode, errorMessage); + + // Assert + Assert.AreSame(option, result); + Assert.AreEqual(errorCode, option.ErrorCode); + Assert.AreEqual(errorMessage, option.ErrorMesg); + } + + [TestMethod] + public void WithErrorCodeAndMessage_HandlesNullMessage() + { + // Arrange + var option = new OptionObject(); + + // Act + option.WithErrorCodeAndMessage(2, null); + + // Assert + Assert.AreEqual(string.Empty, option.ErrorMesg); + } + + [TestMethod] + public void AddForm_AddsFormToForms() + { + // Arrange + var option = new OptionObject(); + var form = new FormObject { FormId = "TestForm" }; + + // Act + OptionObject result = option.AddForm(form); + + // Assert + Assert.AreSame(option, result); + Assert.AreEqual(1, option.Forms.Count); + Assert.AreSame(form, option.Forms[0]); + } + + [TestMethod] + public void AddForm_IgnoresNullForm() + { + // Arrange + var option = new OptionObject(); + + // Act + OptionObject result = option.AddForm(null); + + // Assert + Assert.AreSame(option, result); + Assert.AreEqual(0, option.Forms.Count); + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/GlobalUsings.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/GlobalUsings.cs new file mode 100644 index 00000000..c7520e13 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/GlobalUsings.cs @@ -0,0 +1,4 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; +global using RarelySimple.AvatarScriptLink.Objects; +global using RarelySimple.AvatarScriptLink.Objects.Builders; +global using RarelySimple.AvatarScriptLink.Objects.Builders.ResponseBuilders; diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/RarelySimple.AvatarScriptLink.Objects.Builders.Tests.csproj b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/RarelySimple.AvatarScriptLink.Objects.Builders.Tests.csproj new file mode 100644 index 00000000..cbd8d147 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/RarelySimple.AvatarScriptLink.Objects.Builders.Tests.csproj @@ -0,0 +1,26 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/ResponseBuilderMethodsTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/ResponseBuilderMethodsTests.cs new file mode 100644 index 00000000..bf794e19 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders.Tests/ResponseBuilderMethodsTests.cs @@ -0,0 +1,202 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders.Tests +{ + [TestClass] + public class OptionObjectResponseBuildersTests + { + [TestMethod] + public void CreateSuccessResponse_SetsSuccessFields() + { + // Arrange + string entityId = "Patient123"; + + // Act + OptionObject response = OptionObjectResponseBuilders.CreateSuccessResponse(entityId); + + // Assert + Assert.AreEqual(entityId, response.EntityID); + Assert.AreEqual(0d, response.ErrorCode); + Assert.AreEqual(string.Empty, response.ErrorMesg); + } + + [TestMethod] + public void CreateErrorResponse_SetsErrorFields() + { + // Arrange + string entityId = "Patient123"; + double errorCode = 2; + string errorMessage = "Response error"; + + // Act + OptionObject response = OptionObjectResponseBuilders.CreateErrorResponse(entityId, errorCode, errorMessage); + + // Assert + Assert.AreEqual(entityId, response.EntityID); + Assert.AreEqual(errorCode, response.ErrorCode); + Assert.AreEqual(errorMessage, response.ErrorMesg); + } + + [TestMethod] + public void CreateSuccessResponse2_SetsSuccessFields() + { + // Arrange + string entityId = "Patient456"; + + // Act + OptionObject2 response = OptionObject2ResponseBuilders.CreateSuccessResponse(entityId); + + // Assert + Assert.AreEqual(entityId, response.EntityID); + Assert.AreEqual(0d, response.ErrorCode); + Assert.AreEqual(string.Empty, response.ErrorMesg); + } + + [TestMethod] + public void CreateErrorResponse2015_SetsErrorFields() + { + // Arrange + string entityId = "Patient789"; + double errorCode = 4; + string errorMessage = "Response error"; + + // Act + OptionObject2015 response = OptionObject2015ResponseBuilders.CreateErrorResponse(entityId, errorCode, errorMessage); + + // Assert + Assert.AreEqual(entityId, response.EntityID); + Assert.AreEqual(errorCode, response.ErrorCode); + Assert.AreEqual(errorMessage, response.ErrorMesg); + } + + [TestMethod] + public void CreateSuccessResponse2015_WithSessionDetails_SetsSessionFields() + { + // Arrange + string entityId = "Patient999"; + string sessionToken = "SESSION-123"; + string optionUserId = "USER-456"; + + // Act + OptionObject2015 response = OptionObject2015ResponseBuilders.CreateSuccessResponse(entityId, sessionToken, optionUserId); + + // Assert + Assert.AreEqual(entityId, response.EntityID); + Assert.AreEqual(0d, response.ErrorCode); + Assert.AreEqual(string.Empty, response.ErrorMesg); + Assert.AreEqual(sessionToken, response.SessionToken); + Assert.AreEqual(optionUserId, response.OptionUserId); + } + + [TestMethod] + public void CreateErrorResponse2015_WithSessionToken_SetsSessionFields() + { + // Arrange + string entityId = "Patient888"; + double errorCode = 3; + string errorMessage = "Session error"; + string sessionToken = "SESSION-999"; + + // Act + OptionObject2015 response = OptionObject2015ResponseBuilders.CreateErrorResponse(entityId, errorCode, errorMessage, sessionToken); + + // Assert + Assert.AreEqual(entityId, response.EntityID); + Assert.AreEqual(errorCode, response.ErrorCode); + Assert.AreEqual(errorMessage, response.ErrorMesg); + Assert.AreEqual(sessionToken, response.SessionToken); + } + + [TestMethod] + public void AddResponseForm_AddsFormAndSetsMultipleIteration() + { + // Arrange + var response = OptionObjectResponseBuilders.CreateSuccessResponse("Patient123"); + + // Act + FormObject form = response.AddResponseForm("FORM1", true); + + // Assert + Assert.AreEqual(1, response.Forms.Count); + Assert.AreSame(form, response.Forms[0]); + Assert.IsTrue(form.MultipleIteration); + } + } + + [TestClass] + public class FormObjectResponseBuildersTests + { + [TestMethod] + public void CreateResponseCurrentRow_SetsRowActionToEdit() + { + // Arrange + var form = FormObjectBuilders.CreateFormObject("FORM1"); + + // Act + RowObject row = form.CreateResponseCurrentRow("1"); + + // Assert + Assert.AreSame(row, form.CurrentRow); + Assert.AreEqual(RowObject.RowActions.Edit, row.RowAction); + } + + [TestMethod] + public void AddResponseRow_DefaultsRowActionToEdit() + { + // Arrange + var form = FormObjectBuilders.CreateFormObject("FORM1"); + + // Act + RowObject row = form.AddResponseRow("2"); + + // Assert + Assert.AreEqual(RowObject.RowActions.Edit, row.RowAction); + Assert.AreEqual(1, form.OtherRows.Count); + } + + [TestMethod] + public void AddResponseRow_RespectsProvidedRowAction() + { + // Arrange + var form = FormObjectBuilders.CreateFormObject("FORM1"); + + // Act + RowObject row = form.AddResponseRow("3", RowObject.RowActions.Add); + + // Assert + Assert.AreEqual(RowObject.RowActions.Add, row.RowAction); + } + } + + [TestClass] + public class RowObjectResponseBuildersTests + { + [TestMethod] + public void AddResponseField_AddsFieldAndSetsRowActionToEdit() + { + // Arrange + var row = RowObjectBuilders.CreateRowObject("1"); + + // Act + FieldObject field = row.AddResponseField("100", "value"); + + // Assert + Assert.AreEqual(RowObject.RowActions.Edit, row.RowAction); + Assert.AreEqual(1, row.Fields.Count); + Assert.AreSame(field, row.Fields[0]); + } + + [TestMethod] + public void AddResponseField_PreservesExistingRowAction() + { + // Arrange + var row = RowObjectBuilders.CreateRowObject("1") + .WithRowAction(RowObject.RowActions.Add); + + // Act + FieldObject field = row.AddResponseField("200", "value"); + + // Assert + Assert.AreEqual(RowObject.RowActions.Add, row.RowAction); + Assert.AreSame(field, row.Fields[0]); + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/FieldObjectBuilders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/FieldObjectBuilders.cs new file mode 100644 index 00000000..b988ccb4 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/FieldObjectBuilders.cs @@ -0,0 +1,79 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders +{ + /// + /// Provides extension methods for building and creating instances. + /// + public static class FieldObjectBuilders + { + /// + /// Creates a new with the specified field number. + /// + /// The field number for the new FieldObject. + /// A new FieldObject with the specified field number. + public static FieldObject CreateFieldObject(string fieldNumber) + { + return FieldObject.Initialize() + .WithFieldNumber(fieldNumber); + } + + /// + /// Sets the FieldNumber on a using a fluent interface. + /// + /// The FieldObject to configure. + /// The field number to set. + /// The FieldObject for method chaining. + public static FieldObject WithFieldNumber(this FieldObject fieldObject, string fieldNumber) + { + fieldObject.FieldNumber = fieldNumber; + return fieldObject; + } + + /// + /// Sets the FieldValue on a using a fluent interface. + /// + /// The FieldObject to configure. + /// The field value to set. + /// The FieldObject for method chaining. + public static FieldObject WithFieldValue(this FieldObject fieldObject, string fieldValue) + { + fieldObject.FieldValue = fieldValue; + return fieldObject; + } + + /// + /// Sets the Enabled status on a using a fluent interface. + /// + /// The FieldObject to configure. + /// True to enable the field, false to disable it. + /// The FieldObject for method chaining. + public static FieldObject AsEnabled(this FieldObject fieldObject, bool enabled) + { + fieldObject.SetEnabled(enabled); + return fieldObject; + } + + /// + /// Sets the Locked status on a using a fluent interface. + /// + /// The FieldObject to configure. + /// True to lock the field, false to unlock it. + /// The FieldObject for method chaining. + public static FieldObject AsLocked(this FieldObject fieldObject, bool locked) + { + fieldObject.SetLocked(locked); + return fieldObject; + } + + /// + /// Sets the Required status on a using a fluent interface. + /// + /// The FieldObject to configure. + /// True to mark the field as required, false to mark as optional. + /// The FieldObject for method chaining. + public static FieldObject AsRequired(this FieldObject fieldObject, bool required) + { + fieldObject.SetRequired(required); + return fieldObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/FormObjectBuilders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/FormObjectBuilders.cs new file mode 100644 index 00000000..1aec7b90 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/FormObjectBuilders.cs @@ -0,0 +1,70 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders +{ + /// + /// Provides extension methods for building and creating instances. + /// + public static class FormObjectBuilders + { + /// + /// Creates a new with the specified form ID. + /// + /// The form ID for the new FormObject. + /// A new FormObject with the specified form ID. + public static FormObject CreateFormObject(string formId) + { + return FormObject.Initialize() + .WithFormId(formId); + } + + /// + /// Sets the FormId on a using a fluent interface. + /// + /// The FormObject to configure. + /// The form ID to set. + /// The FormObject for method chaining. + public static FormObject WithFormId(this FormObject formObject, string formId) + { + formObject.FormId = formId; + return formObject; + } + + /// + /// Sets the MultipleIteration flag on a using a fluent interface. + /// + /// The FormObject to configure. + /// True if the form has multiple iteration, false otherwise. + /// The FormObject for method chaining. + public static FormObject WithMultipleIteration(this FormObject formObject, bool multipleIteration) + { + formObject.MultipleIteration = multipleIteration; + return formObject; + } + + /// + /// Sets the CurrentRow on a using a fluent interface. + /// + /// The FormObject to configure. + /// The current row to set. + /// The FormObject for method chaining. + public static FormObject WithCurrentRow(this FormObject formObject, RowObject currentRow) + { + formObject.CurrentRow = currentRow; + return formObject; + } + + /// + /// Adds a row to the OtherRows collection on a . + /// + /// The FormObject to add to. + /// The row to add. + /// The FormObject for method chaining. + public static FormObject AddRow(this FormObject formObject, RowObject rowObject) + { + if (rowObject != null) + { + formObject.OtherRows.Add(rowObject); + } + return formObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/OptionObject2015Builders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/OptionObject2015Builders.cs new file mode 100644 index 00000000..f6cd07b2 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/OptionObject2015Builders.cs @@ -0,0 +1,87 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders +{ + /// + /// Provides extension methods for building and creating instances. + /// + /// + /// Note: OptionObject2015 includes SessionToken which is not present in OptionObject2. + /// + public static class OptionObject2015Builders + { + /// + /// Creates a new with the specified entity ID. + /// + /// The entity ID for the new OptionObject2015. + /// A new OptionObject2015 with the specified entity ID. + public static OptionObject2015 CreateOptionObject2015(string entityId) + { + return OptionObject2015.Initialize() + .WithEntityId(entityId); + } + + /// + /// Sets the EntityID on an using a fluent interface. + /// + /// The OptionObject2015 to configure. + /// The entity ID to set. + /// The OptionObject2015 for method chaining. + public static OptionObject2015 WithEntityId(this OptionObject2015 optionObject, string entityId) + { + optionObject.EntityID = entityId; + return optionObject; + } + + /// + /// Sets the ErrorCode and ErrorMessage on an using a fluent interface. + /// + /// The OptionObject2015 to configure. + /// The error code to set. + /// The error message to set. + /// The OptionObject2015 for method chaining. + public static OptionObject2015 WithErrorCodeAndMessage(this OptionObject2015 optionObject, double errorCode, string errorMessage) + { + optionObject.ErrorCode = errorCode; + optionObject.ErrorMesg = errorMessage ?? string.Empty; + return optionObject; + } + + /// + /// Adds a form to the Forms collection on an . + /// + /// The OptionObject2015 to add to. + /// The form to add. + /// The OptionObject2015 for method chaining. + public static OptionObject2015 AddForm(this OptionObject2015 optionObject, FormObject formObject) + { + if (formObject != null) + { + optionObject.Forms.Add(formObject); + } + return optionObject; + } + + /// + /// Sets the SessionToken on an using a fluent interface. + /// + /// The OptionObject2015 to configure. + /// The session token to set. + /// The OptionObject2015 for method chaining. + public static OptionObject2015 WithSessionToken(this OptionObject2015 optionObject, string sessionToken) + { + optionObject.SessionToken = sessionToken; + return optionObject; + } + + /// + /// Sets the OptionUserId on an using a fluent interface. + /// + /// The OptionObject2015 to configure. + /// The option user ID to set. + /// The OptionObject2015 for method chaining. + public static OptionObject2015 WithOptionUserId(this OptionObject2015 optionObject, string userId) + { + optionObject.OptionUserId = userId; + return optionObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/OptionObject2Builders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/OptionObject2Builders.cs new file mode 100644 index 00000000..24bc2502 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/OptionObject2Builders.cs @@ -0,0 +1,63 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders +{ + /// + /// Provides extension methods for building and creating instances. + /// + /// + /// Note: OptionObject2 includes SessionToken but not ContinuationToken as found in other implementations. + /// + public static class OptionObject2Builders + { + /// + /// Creates a new with the specified entity ID. + /// + /// The entity ID for the new OptionObject2. + /// A new OptionObject2 with the specified entity ID. + public static OptionObject2 CreateOptionObject2(string entityId) + { + return OptionObject2.Initialize() + .WithEntityId(entityId); + } + + /// + /// Sets the EntityID on an using a fluent interface. + /// + /// The OptionObject2 to configure. + /// The entity ID to set. + /// The OptionObject2 for method chaining. + public static OptionObject2 WithEntityId(this OptionObject2 optionObject, string entityId) + { + optionObject.EntityID = entityId; + return optionObject; + } + + /// + /// Sets the ErrorCode and ErrorMessage on an using a fluent interface. + /// + /// The OptionObject2 to configure. + /// The error code to set. + /// The error message to set. + /// The OptionObject2 for method chaining. + public static OptionObject2 WithErrorCodeAndMessage(this OptionObject2 optionObject, double errorCode, string errorMessage) + { + optionObject.ErrorCode = errorCode; + optionObject.ErrorMesg = errorMessage ?? string.Empty; + return optionObject; + } + + /// + /// Adds a form to the Forms collection on an . + /// + /// The OptionObject2 to add to. + /// The form to add. + /// The OptionObject2 for method chaining. + public static OptionObject2 AddForm(this OptionObject2 optionObject, FormObject formObject) + { + if (formObject != null) + { + optionObject.Forms.Add(formObject); + } + return optionObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/OptionObjectBuilders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/OptionObjectBuilders.cs new file mode 100644 index 00000000..5238568c --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/OptionObjectBuilders.cs @@ -0,0 +1,60 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders +{ + /// + /// Provides extension methods for building and creating instances. + /// + public static class OptionObjectBuilders + { + /// + /// Creates a new with the specified entity ID. + /// + /// The entity ID for the new OptionObject. + /// A new OptionObject with the specified entity ID. + public static OptionObject CreateOptionObject(string entityId) + { + return OptionObject.Initialize() + .WithEntityId(entityId); + } + + /// + /// Sets the EntityID on an using a fluent interface. + /// + /// The OptionObject to configure. + /// The entity ID to set. + /// The OptionObject for method chaining. + public static OptionObject WithEntityId(this OptionObject optionObject, string entityId) + { + optionObject.EntityID = entityId; + return optionObject; + } + + /// + /// Sets the ErrorCode and ErrorMessage on an using a fluent interface. + /// + /// The OptionObject to configure. + /// The error code to set. + /// The error message to set. + /// The OptionObject for method chaining. + public static OptionObject WithErrorCodeAndMessage(this OptionObject optionObject, double errorCode, string errorMessage) + { + optionObject.ErrorCode = errorCode; + optionObject.ErrorMesg = errorMessage ?? string.Empty; + return optionObject; + } + + /// + /// Adds a form to the Forms collection on an . + /// + /// The OptionObject to add to. + /// The form to add. + /// The OptionObject for method chaining. + public static OptionObject AddForm(this OptionObject optionObject, FormObject formObject) + { + if (formObject != null) + { + optionObject.Forms.Add(formObject); + } + return optionObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/README.md b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/README.md new file mode 100644 index 00000000..33be37c8 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/README.md @@ -0,0 +1,38 @@ +# RarelySimple.AvatarScriptLink.Objects.Builders + +Extension methods for building and creating ScriptLink objects. + +## Usage + +```csharp +using RarelySimple.AvatarScriptLink.Objects.Builders; +using RarelySimple.AvatarScriptLink.Objects.Builders.ResponseBuilders; + +// Create a field using builder extension methods +var field = FieldObject.Initialize() + .WithFieldNumber("12345.0") + .WithFieldValue("value") + .AsEnabled(true); + +// Create a simple success response with a form, row, and field +var response = OptionObjectResponseBuilders.CreateSuccessResponse("PATID123"); +var form = response.AddResponseForm("FORM1", multipleIteration: true); +var row = form.CreateResponseCurrentRow("1"); +row.AddResponseField("100", "value"); +``` + +## Features + +- Factory and builder extension methods for creating ScriptLink objects +- Fluent interface for convenient object construction +- Response builder extensions for creating proper SOAP responses +- Comprehensive XML documentation + +## Dependencies + +- **RarelySimple.AvatarScriptLink.Objects** - Core object definitions +- .NET Standard 2.0+ + +## License + +MIT diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/RarelySimple.AvatarScriptLink.Objects.Builders.csproj b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/RarelySimple.AvatarScriptLink.Objects.Builders.csproj new file mode 100644 index 00000000..27e0e569 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/RarelySimple.AvatarScriptLink.Objects.Builders.csproj @@ -0,0 +1,44 @@ + + + + netstandard2.0 + 8.0 + false + Scott Olson Jr + Rarely Simple + MIT + https://github.com/rarelysimple/RarelySimple.AvatarScriptLink + https://scriptlink.rarelysimple.com/ + git + Copyright © 2026 Scott Olson Jr + RarelySimple.AvatarScriptLink.Objects.Builders provides extension methods for building and creating ScriptLink objects with fluent interfaces and factory methods. + en-US + true + ../RarelySimple.AvatarScriptLink.snk + ../RarelySimple.AvatarScriptLink.ruleset + RarelySimple.AvatarScriptLink.Objects.Builders + README.md + true + 2.0.0 + $(Version) + $(Version) + v + preview.0 + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/FormObjectResponseBuilders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/FormObjectResponseBuilders.cs new file mode 100644 index 00000000..01210f28 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/FormObjectResponseBuilders.cs @@ -0,0 +1,75 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders.ResponseBuilders +{ + /// + /// Provides response builder extensions for instances. + /// + public static class FormObjectResponseBuilders + { + /// + /// Sets the current row and ensures it will be included in a response payload. + /// + /// The FormObject to configure. + /// The row to set as current. + /// The FormObject for method chaining. + public static FormObject SetResponseCurrentRow(this FormObject formObject, RowObject rowObject) + { + EnsureRowActionSet(rowObject); + formObject.CurrentRow = rowObject; + return formObject; + } + + /// + /// Creates a current row and ensures it will be included in a response payload. + /// + /// The FormObject to configure. + /// The row ID to assign. + /// The created RowObject. + public static RowObject CreateResponseCurrentRow(this FormObject formObject, string rowId) + { + var rowObject = RowObjectBuilders.CreateRowObject(rowId); + EnsureRowActionSet(rowObject); + formObject.CurrentRow = rowObject; + return rowObject; + } + + /// + /// Adds a response row to the OtherRows collection. + /// + /// The FormObject to add to. + /// The row to add. + /// The FormObject for method chaining. + public static FormObject AddResponseRow(this FormObject formObject, RowObject rowObject) + { + EnsureRowActionSet(rowObject); + formObject.AddRow(rowObject); + return formObject; + } + + /// + /// Creates and adds a response row to the OtherRows collection. + /// + /// The FormObject to add to. + /// The row ID to assign. + /// The row action to apply (e.g., ADD, EDIT, DELETE). + /// The created RowObject. + public static RowObject AddResponseRow(this FormObject formObject, string rowId, string rowAction = null) + { + var rowObject = RowObjectBuilders.CreateRowObject(rowId); + if (!string.IsNullOrEmpty(rowAction)) + { + rowObject.RowAction = rowAction; + } + EnsureRowActionSet(rowObject); + formObject.AddRow(rowObject); + return rowObject; + } + + private static void EnsureRowActionSet(RowObject rowObject) + { + if (rowObject != null && string.IsNullOrEmpty(rowObject.RowAction)) + { + rowObject.RowAction = RowObject.RowActions.Edit; + } + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/OptionObject2015ResponseBuilders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/OptionObject2015ResponseBuilders.cs new file mode 100644 index 00000000..f84c302c --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/OptionObject2015ResponseBuilders.cs @@ -0,0 +1,110 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders.ResponseBuilders +{ + /// + /// Provides response builder extensions for instances. + /// + public static class OptionObject2015ResponseBuilders + { + /// + /// Creates a success response with the specified entity ID. + /// + /// The entity ID for the response. + /// A success response OptionObject2015. + public static OptionObject2015 CreateSuccessResponse(string entityId) + { + return OptionObject2015.Initialize() + .WithEntityId(entityId) + .AsSuccessResponse(); + } + + /// + /// Creates a success response with the specified entity ID and session details. + /// + /// The entity ID for the response. + /// The session token to set. + /// The option user ID to set, if provided. + /// A success response OptionObject2015. + public static OptionObject2015 CreateSuccessResponse(string entityId, string sessionToken, string optionUserId = null) + { + var optionObject = CreateSuccessResponse(entityId); + optionObject.SessionToken = sessionToken; + if (optionUserId != null) + { + optionObject.OptionUserId = optionUserId; + } + return optionObject; + } + + /// + /// Creates an error response with the specified entity ID and error details. + /// + /// The entity ID for the response. + /// The error code to set. + /// The error message to set. + /// An error response OptionObject2015. + public static OptionObject2015 CreateErrorResponse(string entityId, double errorCode, string errorMessage) + { + return OptionObject2015.Initialize() + .WithEntityId(entityId) + .AsErrorResponse(errorCode, errorMessage); + } + + /// + /// Creates an error response with the specified entity ID, error details, and session details. + /// + /// The entity ID for the response. + /// The error code to set. + /// The error message to set. + /// The session token to set. + /// The option user ID to set, if provided. + /// An error response OptionObject2015. + public static OptionObject2015 CreateErrorResponse(string entityId, double errorCode, string errorMessage, string sessionToken, string optionUserId = null) + { + var optionObject = CreateErrorResponse(entityId, errorCode, errorMessage); + optionObject.SessionToken = sessionToken; + if (optionUserId != null) + { + optionObject.OptionUserId = optionUserId; + } + return optionObject; + } + + /// + /// Marks an as a success response. + /// + /// The OptionObject2015 to configure. + /// The OptionObject2015 for method chaining. + public static OptionObject2015 AsSuccessResponse(this OptionObject2015 optionObject) + { + return optionObject.WithErrorCodeAndMessage(0, string.Empty); + } + + /// + /// Marks an as an error response. + /// + /// The OptionObject2015 to configure. + /// The error code to set. + /// The error message to set. + /// The OptionObject2015 for method chaining. + public static OptionObject2015 AsErrorResponse(this OptionObject2015 optionObject, double errorCode, string errorMessage) + { + return optionObject.WithErrorCodeAndMessage(errorCode, errorMessage); + } + + /// + /// Creates and adds a response form to an . + /// + /// The OptionObject2015 to add to. + /// The form ID to assign. + /// True if the form has multiple iteration, false otherwise. + /// The created FormObject. + public static FormObject AddResponseForm(this OptionObject2015 optionObject, string formId, bool multipleIteration = false) + { + var formObject = FormObjectBuilders.CreateFormObject(formId) + .WithMultipleIteration(multipleIteration); + + optionObject.AddForm(formObject); + return formObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/OptionObject2ResponseBuilders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/OptionObject2ResponseBuilders.cs new file mode 100644 index 00000000..d1ff5be2 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/OptionObject2ResponseBuilders.cs @@ -0,0 +1,72 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders.ResponseBuilders +{ + /// + /// Provides response builder extensions for instances. + /// + public static class OptionObject2ResponseBuilders + { + /// + /// Creates a success response with the specified entity ID. + /// + /// The entity ID for the response. + /// A success response OptionObject2. + public static OptionObject2 CreateSuccessResponse(string entityId) + { + return OptionObject2.Initialize() + .WithEntityId(entityId) + .AsSuccessResponse(); + } + + /// + /// Creates an error response with the specified entity ID and error details. + /// + /// The entity ID for the response. + /// The error code to set. + /// The error message to set. + /// An error response OptionObject2. + public static OptionObject2 CreateErrorResponse(string entityId, double errorCode, string errorMessage) + { + return OptionObject2.Initialize() + .WithEntityId(entityId) + .AsErrorResponse(errorCode, errorMessage); + } + + /// + /// Marks an as a success response. + /// + /// The OptionObject2 to configure. + /// The OptionObject2 for method chaining. + public static OptionObject2 AsSuccessResponse(this OptionObject2 optionObject) + { + return optionObject.WithErrorCodeAndMessage(0, string.Empty); + } + + /// + /// Marks an as an error response. + /// + /// The OptionObject2 to configure. + /// The error code to set. + /// The error message to set. + /// The OptionObject2 for method chaining. + public static OptionObject2 AsErrorResponse(this OptionObject2 optionObject, double errorCode, string errorMessage) + { + return optionObject.WithErrorCodeAndMessage(errorCode, errorMessage); + } + + /// + /// Creates and adds a response form to an . + /// + /// The OptionObject2 to add to. + /// The form ID to assign. + /// True if the form has multiple iteration, false otherwise. + /// The created FormObject. + public static FormObject AddResponseForm(this OptionObject2 optionObject, string formId, bool multipleIteration = false) + { + var formObject = FormObjectBuilders.CreateFormObject(formId) + .WithMultipleIteration(multipleIteration); + + optionObject.AddForm(formObject); + return formObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/OptionObjectResponseBuilders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/OptionObjectResponseBuilders.cs new file mode 100644 index 00000000..40a44143 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/OptionObjectResponseBuilders.cs @@ -0,0 +1,72 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders.ResponseBuilders +{ + /// + /// Provides response builder extensions for instances. + /// + public static class OptionObjectResponseBuilders + { + /// + /// Creates a success response with the specified entity ID. + /// + /// The entity ID for the response. + /// A success response OptionObject. + public static OptionObject CreateSuccessResponse(string entityId) + { + return OptionObject.Initialize() + .WithEntityId(entityId) + .AsSuccessResponse(); + } + + /// + /// Creates an error response with the specified entity ID and error details. + /// + /// The entity ID for the response. + /// The error code to set. + /// The error message to set. + /// An error response OptionObject. + public static OptionObject CreateErrorResponse(string entityId, double errorCode, string errorMessage) + { + return OptionObject.Initialize() + .WithEntityId(entityId) + .AsErrorResponse(errorCode, errorMessage); + } + + /// + /// Marks an as a success response. + /// + /// The OptionObject to configure. + /// The OptionObject for method chaining. + public static OptionObject AsSuccessResponse(this OptionObject optionObject) + { + return optionObject.WithErrorCodeAndMessage(0, string.Empty); + } + + /// + /// Marks an as an error response. + /// + /// The OptionObject to configure. + /// The error code to set. + /// The error message to set. + /// The OptionObject for method chaining. + public static OptionObject AsErrorResponse(this OptionObject optionObject, double errorCode, string errorMessage) + { + return optionObject.WithErrorCodeAndMessage(errorCode, errorMessage); + } + + /// + /// Creates and adds a response form to an . + /// + /// The OptionObject to add to. + /// The form ID to assign. + /// True if the form has multiple iteration, false otherwise. + /// The created FormObject. + public static FormObject AddResponseForm(this OptionObject optionObject, string formId, bool multipleIteration = false) + { + var formObject = FormObjectBuilders.CreateFormObject(formId) + .WithMultipleIteration(multipleIteration); + + optionObject.AddForm(formObject); + return formObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/RowObjectResponseBuilders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/RowObjectResponseBuilders.cs new file mode 100644 index 00000000..0cc43d4f --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/ResponseBuilders/RowObjectResponseBuilders.cs @@ -0,0 +1,47 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders.ResponseBuilders +{ + /// + /// Provides response builder extensions for instances. + /// + public static class RowObjectResponseBuilders + { + /// + /// Adds a field to a response row and ensures the row will be included in the payload. + /// + /// The row to add to. + /// The field to add. + /// The added FieldObject. + public static FieldObject AddResponseField(this RowObject rowObject, FieldObject fieldObject) + { + EnsureRowActionSet(rowObject); + if (fieldObject != null) + { + rowObject.AddField(fieldObject); + } + return fieldObject; + } + + /// + /// Creates and adds a field to a response row and ensures the row will be included in the payload. + /// + /// The row to add to. + /// The field number to assign. + /// The field value to assign. + /// The created FieldObject. + public static FieldObject AddResponseField(this RowObject rowObject, string fieldNumber, string fieldValue) + { + var fieldObject = FieldObjectBuilders.CreateFieldObject(fieldNumber) + .WithFieldValue(fieldValue); + + return rowObject.AddResponseField(fieldObject); + } + + private static void EnsureRowActionSet(RowObject rowObject) + { + if (rowObject != null && string.IsNullOrEmpty(rowObject.RowAction)) + { + rowObject.RowAction = RowObject.RowActions.Edit; + } + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/RowObjectBuilders.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/RowObjectBuilders.cs new file mode 100644 index 00000000..e0728625 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Builders/RowObjectBuilders.cs @@ -0,0 +1,70 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Builders +{ + /// + /// Provides extension methods for building and creating instances. + /// + public static class RowObjectBuilders + { + /// + /// Creates a new with the specified row ID. + /// + /// The row ID for the new RowObject. + /// A new RowObject with the specified row ID. + public static RowObject CreateRowObject(string rowId) + { + return RowObject.Initialize() + .WithRowId(rowId); + } + + /// + /// Sets the RowId on a using a fluent interface. + /// + /// The RowObject to configure. + /// The row ID to set. + /// The RowObject for method chaining. + public static RowObject WithRowId(this RowObject rowObject, string rowId) + { + rowObject.RowId = rowId; + return rowObject; + } + + /// + /// Sets the ParentRowId on a using a fluent interface. + /// + /// The RowObject to configure. + /// The parent row ID to set. + /// The RowObject for method chaining. + public static RowObject WithParentRowId(this RowObject rowObject, string parentRowId) + { + rowObject.ParentRowId = parentRowId; + return rowObject; + } + + /// + /// Sets the RowAction on a using a fluent interface. + /// + /// The RowObject to configure. + /// The row action to set (e.g., "ADD", "EDIT", "DELETE"). + /// The RowObject for method chaining. + public static RowObject WithRowAction(this RowObject rowObject, string rowAction) + { + rowObject.RowAction = rowAction; + return rowObject; + } + + /// + /// Adds a field to the Fields collection on a . + /// + /// The RowObject to add to. + /// The field to add. + /// The RowObject for method chaining. + public static RowObject AddField(this RowObject rowObject, FieldObject fieldObject) + { + if (fieldObject != null) + { + rowObject.Fields.Add(fieldObject); + } + return rowObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters.Tests/ConverterMethodsTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters.Tests/ConverterMethodsTests.cs new file mode 100644 index 00000000..82674357 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters.Tests/ConverterMethodsTests.cs @@ -0,0 +1,279 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Converters.Tests +{ + [TestClass] + public class FieldObjectConvertersTests + { + [TestMethod] + public void ToFieldObject_CopiesValues() + { + // Arrange + var source = new FieldObject + { + FieldNumber = "100", + FieldValue = "value", + Enabled = "1", + Lock = "0", + Required = "1" + }; + + // Act + FieldObject? result = source.ToFieldObject(); + + // Assert + Assert.IsNotNull(result); + Assert.AreNotSame(source, result); + Assert.AreEqual(source.FieldNumber, result.FieldNumber); + Assert.AreEqual(source.FieldValue, result.FieldValue); + Assert.AreEqual(source.Enabled, result.Enabled); + Assert.AreEqual(source.Lock, result.Lock); + Assert.AreEqual(source.Required, result.Required); + } + } + + [TestClass] + public class RowObjectConvertersTests + { + [TestMethod] + public void ToRowObject_CopiesFields_WhenIncluded() + { + // Arrange + var source = new RowObject { RowId = "1", ParentRowId = "P1", RowAction = RowObject.RowActions.Edit }; + source.Fields.Add(new FieldObject { FieldNumber = "100" }); + + // Act + RowObject? result = source.ToRowObject(); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(source.RowId, result.RowId); + Assert.AreEqual(source.ParentRowId, result.ParentRowId); + Assert.AreEqual(source.RowAction, result.RowAction); + Assert.AreEqual(1, result.Fields.Count); + Assert.AreNotSame(source.Fields[0], result.Fields[0]); + } + + [TestMethod] + public void ToRowObject_ExcludesFields_WhenNotIncluded() + { + // Arrange + var source = new RowObject { RowId = "1" }; + source.Fields.Add(new FieldObject { FieldNumber = "200" }); + + // Act + RowObject? result = source.ToRowObject(includeFields: false); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(0, result.Fields.Count); + } + } + + [TestClass] + public class FormObjectConvertersTests + { + [TestMethod] + public void ToFormObject_CopiesRows_WhenIncluded() + { + // Arrange + var source = new FormObject { FormId = "FORM1", MultipleIteration = true }; + source.CurrentRow = new RowObject { RowId = "1" }; + source.OtherRows.Add(new RowObject { RowId = "2" }); + + // Act + FormObject? result = source.ToFormObject(); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(source.FormId, result.FormId); + Assert.IsTrue(result.MultipleIteration); + Assert.IsNotNull(result.CurrentRow); + Assert.AreEqual(1, result.OtherRows.Count); + } + + [TestMethod] + public void ToFormObject_ExcludesRows_WhenNotIncluded() + { + // Arrange + var source = new FormObject { FormId = "FORM2", MultipleIteration = true }; + source.CurrentRow = new RowObject { RowId = "1" }; + source.OtherRows.Add(new RowObject { RowId = "2" }); + + // Act + FormObject? result = source.ToFormObject(includeRows: false); + + // Assert + Assert.IsNotNull(result); + Assert.IsNull(result.CurrentRow); + Assert.AreEqual(0, result.OtherRows.Count); + } + } + + [TestClass] + public class OptionObjectConvertersTests + { + [TestMethod] + public void ToOptionObject_CopiesCommonFieldsAndForms() + { + // Arrange + var source = new OptionObject2 + { + EntityID = "PATID1", + ErrorCode = 1, + ErrorMesg = "Error", + Facility = "1", + SystemCode = "LIVE", + OptionUserId = "USER1" + }; + source.Forms.Add(new FormObject { FormId = "FORM1" }); + + // Act + OptionObject? result = source.ToOptionObject(); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(source.EntityID, result.EntityID); + Assert.AreEqual(source.ErrorCode, result.ErrorCode); + Assert.AreEqual(source.ErrorMesg, result.ErrorMesg); + Assert.AreEqual(1, result.Forms.Count); + } + + [TestMethod] + public void ToOptionObject_ExcludesForms_WhenNotIncluded() + { + // Arrange + var source = new OptionObject2 { EntityID = "PATID2" }; + source.Forms.Add(new FormObject { FormId = "FORM2" }); + + // Act + OptionObject? result = source.ToOptionObject(includeForms: false); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(0, result.Forms.Count); + } + + [TestMethod] + public void ToOptionObject_CopiesForms_AsDeepCopy() + { + // Arrange + var source = new OptionObject2 { EntityID = "PATID2" }; + var form = new FormObject { FormId = "FORM2" }; + source.Forms.Add(form); + + // Act + OptionObject? result = source.ToOptionObject(); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(1, result.Forms.Count); + Assert.AreNotSame(form, result.Forms[0]); + Assert.AreEqual(form.FormId, result.Forms[0].FormId); + } + + [TestMethod] + public void ToOptionObject2_CopiesNamespaceFields_FromOptionObject2015() + { + // Arrange + var source = new OptionObject2015 + { + EntityID = "PATID3", + NamespaceName = "NS", + ParentNamespace = "PARENT", + ServerName = "SERVER" + }; + + // Act + OptionObject2? result = source.ToOptionObject2(); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(source.NamespaceName, result.NamespaceName); + Assert.AreEqual(source.ParentNamespace, result.ParentNamespace); + Assert.AreEqual(source.ServerName, result.ServerName); + } + + [TestMethod] + public void ToOptionObject2_CopiesCommonFields_FromOptionObject() + { + // Arrange + var source = new OptionObject + { + EntityID = "PATID6", + ErrorCode = 2, + ErrorMesg = "Error", + Facility = "2", + SystemCode = "UAT", + OptionUserId = "USER6" + }; + + // Act + OptionObject2? result = source.ToOptionObject2(); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual(source.EntityID, result.EntityID); + Assert.AreEqual(source.ErrorCode, result.ErrorCode); + Assert.AreEqual(source.ErrorMesg, result.ErrorMesg); + Assert.AreEqual(source.Facility, result.Facility); + Assert.AreEqual(source.SystemCode, result.SystemCode); + Assert.AreEqual(source.OptionUserId, result.OptionUserId); + } + + [TestMethod] + public void ToOptionObject2015_AppliesSessionDetails_WhenProvided() + { + // Arrange + var source = new OptionObject2 { EntityID = "PATID4", OptionUserId = "USER2" }; + + // Act + OptionObject2015? result = source.ToOptionObject2015(sessionToken: "TOKEN", optionUserId: "USERX"); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual("TOKEN", result.SessionToken); + Assert.AreEqual("USERX", result.OptionUserId); + } + + [TestMethod] + public void ToOptionObject2015_DoesNotOverrideOptionUserId_WhenNull() + { + // Arrange + var source = new OptionObject2 { EntityID = "PATID7", OptionUserId = "USER7" }; + + // Act + OptionObject2015? result = source.ToOptionObject2015(sessionToken: "TOKEN"); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual("TOKEN", result.SessionToken); + Assert.AreEqual("USER7", result.OptionUserId); + } + + [TestMethod] + public void ToOptionObject2015_UsesFallbackOptionUserId_WhenNotProvided() + { + // Arrange + var source = new OptionObject { EntityID = "PATID5", OptionUserId = "USER3" }; + + // Act + OptionObject2015? result = source.ToOptionObject2015(); + + // Assert + Assert.IsNotNull(result); + Assert.AreEqual("USER3", result.OptionUserId); + } + + [TestMethod] + public void ToOptionObject_ReturnsNull_WhenSourceIsNull() + { + // Arrange + OptionObject2? source = null; + + // Act + OptionObject? result = source.ToOptionObject(); + + // Assert + Assert.IsNull(result); + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters.Tests/GlobalUsings.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters.Tests/GlobalUsings.cs new file mode 100644 index 00000000..8ecebfb7 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters.Tests/GlobalUsings.cs @@ -0,0 +1,3 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; +global using RarelySimple.AvatarScriptLink.Objects; +global using RarelySimple.AvatarScriptLink.Objects.Converters; diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters.Tests/RarelySimple.AvatarScriptLink.Objects.Converters.Tests.csproj b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters.Tests/RarelySimple.AvatarScriptLink.Objects.Converters.Tests.csproj new file mode 100644 index 00000000..e52c6570 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters.Tests/RarelySimple.AvatarScriptLink.Objects.Converters.Tests.csproj @@ -0,0 +1,26 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/FieldObjectConverters.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/FieldObjectConverters.cs new file mode 100644 index 00000000..d1aa5140 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/FieldObjectConverters.cs @@ -0,0 +1,30 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Converters +{ + /// + /// Provides conversion extensions for instances. + /// + public static class FieldObjectConverters + { + /// + /// Creates a copy of a . + /// + /// The FieldObject to convert. + /// A new FieldObject with copied values, or null if the source is null. + public static FieldObject? ToFieldObject(this FieldObject? source) + { + if (source == null) + { + return null; + } + + return new FieldObject + { + FieldNumber = source.FieldNumber, + FieldValue = source.FieldValue, + Enabled = source.Enabled, + Lock = source.Lock, + Required = source.Required + }; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/FormObjectConverters.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/FormObjectConverters.cs new file mode 100644 index 00000000..72efabe6 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/FormObjectConverters.cs @@ -0,0 +1,48 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Converters +{ + /// + /// Provides conversion extensions for instances. + /// + public static class FormObjectConverters + { + /// + /// Creates a copy of a . + /// + /// The FormObject to convert. + /// True to copy rows, false to ignore them. + /// A new FormObject with copied values, or null if the source is null. + public static FormObject? ToFormObject(this FormObject? source, bool includeRows = true) + { + if (source == null) + { + return null; + } + + var formObject = new FormObject + { + FormId = source.FormId, + MultipleIteration = source.MultipleIteration + }; + + if (!includeRows) + { + return formObject; + } + + formObject.CurrentRow = source.CurrentRow.ToRowObject(); + if (source.OtherRows != null) + { + foreach (var row in source.OtherRows) + { + var convertedRow = row.ToRowObject(); + if (convertedRow != null) + { + formObject.OtherRows.Add(convertedRow); + } + } + } + + return formObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/OptionObjectConverters.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/OptionObjectConverters.cs new file mode 100644 index 00000000..fcd02188 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/OptionObjectConverters.cs @@ -0,0 +1,209 @@ +using RarelySimple.AvatarScriptLink.Objects.Interfaces; + +namespace RarelySimple.AvatarScriptLink.Objects.Converters +{ + /// + /// Provides conversion extensions for OptionObject variants. + /// + public static class OptionObjectConverters + { + /// + /// Converts an to an . + /// + /// The OptionObject2 to convert. + /// True to copy forms, false to ignore them. + /// A new OptionObject with copied values, or null if the source is null. + public static OptionObject? ToOptionObject(this OptionObject2? source, bool includeForms = true) + { + if (source == null) + { + return null; + } + + var optionObject = OptionObject.Initialize(); + CopyCommonFields(source, optionObject); + CopyForms(source, optionObject, includeForms); + return optionObject; + } + + /// + /// Converts an to an . + /// + /// The OptionObject2015 to convert. + /// True to copy forms, false to ignore them. + /// A new OptionObject with copied values, or null if the source is null. + public static OptionObject? ToOptionObject(this OptionObject2015? source, bool includeForms = true) + { + if (source == null) + { + return null; + } + + var optionObject = OptionObject.Initialize(); + CopyCommonFields(source, optionObject); + CopyForms(source, optionObject, includeForms); + return optionObject; + } + + /// + /// Converts an to an . + /// + /// The OptionObject to convert. + /// True to copy forms, false to ignore them. + /// A new OptionObject2 with copied values, or null if the source is null. + public static OptionObject2? ToOptionObject2(this OptionObject? source, bool includeForms = true) + { + if (source == null) + { + return null; + } + + var optionObject = OptionObject2.Initialize(); + CopyCommonFields(source, optionObject); + CopyForms(source, optionObject, includeForms); + return optionObject; + } + + /// + /// Converts an to an . + /// + /// The OptionObject2015 to convert. + /// True to copy forms, false to ignore them. + /// A new OptionObject2 with copied values, or null if the source is null. + public static OptionObject2? ToOptionObject2(this OptionObject2015? source, bool includeForms = true) + { + if (source == null) + { + return null; + } + + var optionObject = OptionObject2.Initialize(); + CopyCommonFields(source, optionObject); + optionObject.NamespaceName = source.NamespaceName; + optionObject.ParentNamespace = source.ParentNamespace; + optionObject.ServerName = source.ServerName; + CopyForms(source, optionObject, includeForms); + return optionObject; + } + + /// + /// Converts an to an . + /// + /// The OptionObject to convert. + /// True to copy forms, false to ignore them. + /// The session token to set, if provided. + /// The option user ID to set, if provided. + /// A new OptionObject2015 with copied values, or null if the source is null. + public static OptionObject2015? ToOptionObject2015(this OptionObject? source, bool includeForms = true, string? sessionToken = null, string? optionUserId = null) + { + if (source == null) + { + return null; + } + + var optionObject = OptionObject2015.Initialize(); + CopyCommonFields(source, optionObject); + ApplySessionDetails(optionObject, sessionToken, optionUserId, source.OptionUserId); + CopyForms(source, optionObject, includeForms); + return optionObject; + } + + /// + /// Converts an to an . + /// + /// The OptionObject2 to convert. + /// True to copy forms, false to ignore them. + /// The session token to set, if provided. + /// The option user ID to set, if provided. + /// A new OptionObject2015 with copied values, or null if the source is null. + public static OptionObject2015? ToOptionObject2015(this OptionObject2? source, bool includeForms = true, string? sessionToken = null, string? optionUserId = null) + { + if (source == null) + { + return null; + } + + var optionObject = OptionObject2015.Initialize(); + CopyCommonFields(source, optionObject); + optionObject.NamespaceName = source.NamespaceName; + optionObject.ParentNamespace = source.ParentNamespace; + optionObject.ServerName = source.ServerName; + ApplySessionDetails(optionObject, sessionToken, optionUserId, source.OptionUserId); + CopyForms(source, optionObject, includeForms); + return optionObject; + } + + private static void CopyCommonFields(OptionObject source, IOptionObject target) + { + target.EntityID = source.EntityID; + target.EpisodeNumber = source.EpisodeNumber; + target.ErrorCode = source.ErrorCode; + target.ErrorMesg = source.ErrorMesg; + target.Facility = source.Facility; + target.OptionId = source.OptionId; + target.OptionStaffId = source.OptionStaffId; + target.OptionUserId = source.OptionUserId; + target.SystemCode = source.SystemCode; + } + + private static void CopyCommonFields(OptionObject2 source, IOptionObject target) + { + target.EntityID = source.EntityID; + target.EpisodeNumber = source.EpisodeNumber; + target.ErrorCode = source.ErrorCode; + target.ErrorMesg = source.ErrorMesg; + target.Facility = source.Facility; + target.OptionId = source.OptionId; + target.OptionStaffId = source.OptionStaffId; + target.OptionUserId = source.OptionUserId; + target.SystemCode = source.SystemCode; + } + + private static void CopyCommonFields(OptionObject2015 source, IOptionObject target) + { + target.EntityID = source.EntityID; + target.EpisodeNumber = source.EpisodeNumber; + target.ErrorCode = source.ErrorCode; + target.ErrorMesg = source.ErrorMesg; + target.Facility = source.Facility; + target.OptionId = source.OptionId; + target.OptionStaffId = source.OptionStaffId; + target.OptionUserId = source.OptionUserId; + target.SystemCode = source.SystemCode; + } + + private static void ApplySessionDetails(OptionObject2015 target, string? sessionToken, string? optionUserId, string? fallbackOptionUserId) + { + if (sessionToken != null) + { + target.SessionToken = sessionToken; + } + + if (optionUserId != null) + { + target.OptionUserId = optionUserId; + } + else if (fallbackOptionUserId != null) + { + target.OptionUserId = fallbackOptionUserId; + } + } + + private static void CopyForms(IOptionObject source, IOptionObject target, bool includeForms) + { + if (!includeForms || source.Forms == null) + { + return; + } + + foreach (var form in source.Forms) + { + var convertedForm = form.ToFormObject(); + if (convertedForm != null) + { + target.Forms.Add(convertedForm); + } + } + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/README.md b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/README.md new file mode 100644 index 00000000..a9e876a2 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/README.md @@ -0,0 +1,35 @@ +# RarelySimple.AvatarScriptLink.Objects.Converters + +Extension methods for converting ScriptLink objects between variants and cloning structures. + +## Usage + +```csharp +using RarelySimple.AvatarScriptLink.Objects; +using RarelySimple.AvatarScriptLink.Objects.Converters; + +var option2 = new OptionObject2 +{ + EntityID = "PATID123", + ErrorCode = 0, + ErrorMesg = string.Empty +}; + +OptionObject? option = option2.ToOptionObject(); +``` + +## Features + +- Converters between OptionObject variants +- Deep-copy helpers for FormObject, RowObject, and FieldObject +- Optional flags to include or exclude nested data +- Comprehensive XML documentation + +## Dependencies + +- **RarelySimple.AvatarScriptLink.Objects** - Core object definitions +- .NET Standard 2.0+ + +## License + +MIT diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/RarelySimple.AvatarScriptLink.Objects.Converters.csproj b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/RarelySimple.AvatarScriptLink.Objects.Converters.csproj new file mode 100644 index 00000000..7036c2cd --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/RarelySimple.AvatarScriptLink.Objects.Converters.csproj @@ -0,0 +1,45 @@ + + + + netstandard2.0 + 8.0 + enable + false + Scott Olson Jr + Rarely Simple + MIT + https://github.com/rarelysimple/RarelySimple.AvatarScriptLink + https://scriptlink.rarelysimple.com/ + git + Copyright © 2026 Scott Olson Jr + RarelySimple.AvatarScriptLink.Objects.Converters provides extension methods for converting between ScriptLink objects and cloning structures. + en-US + true + ../RarelySimple.AvatarScriptLink.snk + ../RarelySimple.AvatarScriptLink.ruleset + RarelySimple.AvatarScriptLink.Objects.Converters + README.md + true + 2.0.0 + $(Version) + $(Version) + v + preview.0 + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/RowObjectConverters.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/RowObjectConverters.cs new file mode 100644 index 00000000..0aca88b7 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Converters/RowObjectConverters.cs @@ -0,0 +1,43 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Converters +{ + /// + /// Provides conversion extensions for instances. + /// + public static class RowObjectConverters + { + /// + /// Creates a copy of a . + /// + /// The RowObject to convert. + /// True to copy fields, false to ignore them. + /// A new RowObject with copied values, or null if the source is null. + public static RowObject? ToRowObject(this RowObject? source, bool includeFields = true) + { + if (source == null) + { + return null; + } + + var rowObject = new RowObject + { + RowId = source.RowId, + ParentRowId = source.ParentRowId, + RowAction = source.RowAction + }; + + if (includeFields && source.Fields != null) + { + foreach (var field in source.Fields) + { + var convertedField = field.ToFieldObject(); + if (convertedField != null) + { + rowObject.Fields.Add(convertedField); + } + } + } + + return rowObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/ExtensionMethodsTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/ExtensionMethodsTests.cs new file mode 100644 index 00000000..f62b10f0 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/ExtensionMethodsTests.cs @@ -0,0 +1,967 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Helpers.Tests +{ + /// + /// Tests for FieldObjectHelpers extension methods + /// + [TestClass] + public class FieldObjectHelpersTests + { + [TestMethod] + public void GetValue_WithValue_ReturnsValue() + { + // Arrange + var field = new FieldObject { FieldValue = "TestValue" }; + + // Act + var result = field.GetValue(); + + // Assert + Assert.AreEqual("TestValue", result); + } + + [TestMethod] + public void GetValue_WithNull_ReturnsNull() + { + // Arrange + FieldObject? field = null; + + // Act + var result = field?.GetValue(); + + // Assert + Assert.IsNull(result); + } + + [TestMethod] + public void SetValue_WithValue_SetsFieldValue() + { + // Arrange + var field = new FieldObject(); + + // Act + field.SetValue("NewValue"); + + // Assert + Assert.AreEqual("NewValue", field.FieldValue); + } + + [TestMethod] + public void SetValue_WithNull_SetsEmptyString() + { + // Arrange + var field = new FieldObject { FieldValue = "OldValue" }; + + // Act + field.SetValue(null!); + + // Assert + Assert.AreEqual(string.Empty, field.FieldValue); + } + + [TestMethod] + public void SetValue_WithNullField_DoesNotThrow() + { + // Arrange + FieldObject? field = null; + + // Act - calling extension method on null should not throw + field?.SetValue("Value"); + // If we reach here, no exception was thrown - test passes + } + + [TestMethod] + public void ClearValue_WithValue_ClearsFieldValue() + { + // Arrange + var field = new FieldObject { FieldValue = "SomeValue" }; + + // Act + field.ClearValue(); + + // Assert + Assert.AreEqual(string.Empty, field.FieldValue); + } + + [TestMethod] + public void ClearValue_WithNullField_DoesNotThrow() + { + // Arrange + FieldObject? field = null; + + // Act - calling extension method on null should not throw + field?.ClearValue(); + // If we reach here, no exception was thrown - test passes + } + } + + /// + /// Tests for RowObjectHelpers extension methods + /// + [TestClass] + public class RowObjectHelpersTests + { + [TestMethod] + public void GetRowId_WithRowId_ReturnsRowId() + { + // Arrange + var row = new RowObject { RowId = "123" }; + + // Act + var result = row.GetRowId(); + + // Assert + Assert.AreEqual("123", result); + } + + [TestMethod] + public void GetRowId_WithNull_ReturnsNull() + { + // Arrange + RowObject? row = null; + + // Act + var result = row?.GetRowId(); + + // Assert + Assert.IsNull(result); + } + + [TestMethod] + public void GetParentRowId_WithParentRowId_ReturnsParentRowId() + { + // Arrange + var row = new RowObject { ParentRowId = "456" }; + + // Act + var result = row.GetParentRowId(); + + // Assert + Assert.AreEqual("456", result); + } + + [TestMethod] + public void GetRowAction_WithRowAction_ReturnsRowAction() + { + // Arrange + var row = new RowObject { RowAction = "EDIT" }; + + // Act + var result = row.GetRowAction(); + + // Assert + Assert.AreEqual("EDIT", result); + } + + [TestMethod] + public void IsMarkedForDeletion_WithDeleteAction_ReturnsTrue() + { + // Arrange + var row = new RowObject { RowAction = "DELETE" }; + + // Act + var result = row.IsMarkedForDeletion(); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsMarkedForDeletion_WithEditAction_ReturnsFalse() + { + // Arrange + var row = new RowObject { RowAction = "EDIT" }; + + // Act + var result = row.IsMarkedForDeletion(); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void GetFieldCount_WithFields_ReturnsCount() + { + // Arrange + var row = new RowObject(); + row.Fields.Add(new FieldObject()); + row.Fields.Add(new FieldObject()); + + // Act + var result = row.GetFieldCount(); + + // Assert + Assert.AreEqual(2, result); + } + + [TestMethod] + public void GetFieldCount_WithNull_ReturnsZero() + { + // Arrange + RowObject? row = null; + + // Act + var result = row?.GetFieldCount() ?? 0; + + // Assert + Assert.AreEqual(0, result); + } + + [TestMethod] + public void GetFieldValue_WithExistingField_ReturnsValue() + { + // Arrange + var row = new RowObject(); + row.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "TestValue" }); + + // Act + var result = row.GetFieldValue("100"); + + // Assert + Assert.AreEqual("TestValue", result); + } + + [TestMethod] + public void GetFieldValue_WithNonExistentField_ReturnsNull() + { + // Arrange + var row = new RowObject(); + row.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "TestValue" }); + + // Act + var result = row.GetFieldValue("999"); + + // Assert + Assert.IsNull(result); + } + + [TestMethod] + public void GetFieldValue_WithNullRow_ReturnsNull() + { + // Arrange + RowObject? row = null; + + // Act + var result = row?.GetFieldValue("100"); + + // Assert + Assert.IsNull(result); + } + + [TestMethod] + public void IsFieldPresent_WithField_ReturnsTrue() + { + // Arrange + var row = new RowObject(); + row.Fields.Add(new FieldObject { FieldNumber = "100" }); + + // Act + var result = row.IsFieldPresent("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsFieldPresent_WithoutField_ReturnsFalse() + { + // Arrange + var row = new RowObject(); + + // Act + var result = row.IsFieldPresent("100"); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void IsFieldEnabled_WithEnabledField_ReturnsTrue() + { + // Arrange + var row = new RowObject(); + row.Fields.Add(new FieldObject { FieldNumber = "100", Enabled = "1" }); + + // Act + var result = row.IsFieldEnabled("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsFieldEnabled_WithDisabledField_ReturnsFalse() + { + // Arrange + var row = new RowObject(); + row.Fields.Add(new FieldObject { FieldNumber = "100", Enabled = "0" }); + + // Act + var result = row.IsFieldEnabled("100"); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void IsFieldLocked_WithLockedField_ReturnsTrue() + { + // Arrange + var row = new RowObject(); + row.Fields.Add(new FieldObject { FieldNumber = "100", Lock = "1" }); + + // Act + var result = row.IsFieldLocked("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsFieldRequired_WithRequiredField_ReturnsTrue() + { + // Arrange + var row = new RowObject(); + row.Fields.Add(new FieldObject { FieldNumber = "100", Required = "1" }); + + // Act + var result = row.IsFieldRequired("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void SetFieldValue_WithExistingField_UpdatesValue() + { + // Arrange + var row = new RowObject { RowAction = "" }; + row.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "OldValue" }); + + // Act + var result = row.SetFieldValue("100", "NewValue"); + + // Assert + Assert.AreEqual("NewValue", row.Fields[0].FieldValue); + Assert.AreEqual("EDIT", row.RowAction); + Assert.AreSame(row, result); + } + + [TestMethod] + public void SetFieldValue_WithNonExistentField_DoesNothing() + { + // Arrange + var row = new RowObject(); + + // Act + var result = row.SetFieldValue("999", "Value"); + + // Assert + Assert.IsNull(result?.Fields.FirstOrDefault(f => f.FieldNumber == "999")); + } + + [TestMethod] + public void SetFieldValue_WithNullRow_ReturnsNull() + { + // Arrange + RowObject? row = null; + + // Act + var result = row?.SetFieldValue("100", "Value"); + + // Assert + Assert.IsNull(result); + } + + [TestMethod] + public void DisableAllFieldObjects_WithoutExclusions_DisablesAll() + { + // Arrange + var row = new RowObject(); + var field1 = new FieldObject { FieldNumber = "100", Enabled = "1" }; + var field2 = new FieldObject { FieldNumber = "101", Enabled = "1" }; + row.Fields.Add(field1); + row.Fields.Add(field2); + + // Act + row.DisableAllFieldObjects(); + + // Assert + Assert.AreEqual("0", field1.Enabled); + Assert.AreEqual("0", field2.Enabled); + Assert.AreEqual("EDIT", row.RowAction); + } + + [TestMethod] + public void DisableAllFieldObjects_WithExclusions_DisablesOnlyNonExcluded() + { + // Arrange + var row = new RowObject(); + var field1 = new FieldObject { FieldNumber = "100", Enabled = "1" }; + var field2 = new FieldObject { FieldNumber = "101", Enabled = "1" }; + row.Fields.Add(field1); + row.Fields.Add(field2); + + // Act + row.DisableAllFieldObjects(new List { "101" }); + + // Assert + Assert.AreEqual("0", field1.Enabled); + Assert.AreEqual("1", field2.Enabled); + } + + [TestMethod] + public void EnableAllFieldObjects_WithoutExclusions_EnablesAll() + { + // Arrange + var row = new RowObject(); + var field1 = new FieldObject { FieldNumber = "100", Enabled = "0" }; + var field2 = new FieldObject { FieldNumber = "101", Enabled = "0" }; + row.Fields.Add(field1); + row.Fields.Add(field2); + + // Act + row.EnableAllFieldObjects(); + + // Assert + Assert.AreEqual("1", field1.Enabled); + Assert.AreEqual("1", field2.Enabled); + } + + [TestMethod] + public void EnableAllFieldObjects_WithExclusions_EnablesOnlyNonExcluded() + { + // Arrange + var row = new RowObject(); + var field1 = new FieldObject { FieldNumber = "100", Enabled = "0" }; + var field2 = new FieldObject { FieldNumber = "101", Enabled = "0" }; + row.Fields.Add(field1); + row.Fields.Add(field2); + + // Act + row.EnableAllFieldObjects(new List { "101" }); + + // Assert + Assert.AreEqual("1", field1.Enabled); + Assert.AreEqual("0", field2.Enabled); + } + + [TestMethod] + public void LockAllFieldObjects_LocksAllFields() + { + // Arrange + var row = new RowObject(); + var field = new FieldObject { FieldNumber = "100", Lock = "0" }; + row.Fields.Add(field); + + // Act + row.LockAllFieldObjects(); + + // Assert + Assert.AreEqual("1", field.Lock); + } + + [TestMethod] + public void UnlockAllFieldObjects_UnlocksAllFields() + { + // Arrange + var row = new RowObject(); + var field = new FieldObject { FieldNumber = "100", Lock = "1" }; + row.Fields.Add(field); + + // Act + row.UnlockAllFieldObjects(); + + // Assert + Assert.AreEqual("0", field.Lock); + } + } + + /// + /// Tests for FormObjectHelpers extension methods + /// + [TestClass] + public class FormObjectHelpersTests + { + [TestMethod] + public void IsRowPresent_WithCurrentRow_ReturnsTrue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject { RowId = "1" } }; + + // Act + var result = form.IsRowPresent("1"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsRowPresent_WithOtherRow_ReturnsTrue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject { RowId = "1" }, MultipleIteration = true }; + form.OtherRows.Add(new RowObject { RowId = "2" }); + + // Act + var result = form.IsRowPresent("2"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsRowPresent_WithAbsentRow_ReturnsFalse() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject { RowId = "1" } }; + + // Act + var result = form.IsRowPresent("999"); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void IsRowMarkedForDeletion_WithDeletedRow_ReturnsTrue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject { RowId = "1", RowAction = "DELETE" } }; + + // Act + var result = form.IsRowMarkedForDeletion("1"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsRowMarkedForDeletion_WithNormalRow_ReturnsFalse() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject { RowId = "1", RowAction = "EDIT" } }; + + // Act + var result = form.IsRowMarkedForDeletion("1"); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void IsFieldPresent_InCurrentRow_ReturnsTrue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject() }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100" }); + + // Act + var result = form.IsFieldPresent("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsFieldEnabled_WithEnabledField_ReturnsTrue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject() }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", Enabled = "1" }); + + // Act + var result = form.IsFieldEnabled("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsFieldLocked_WithLockedField_ReturnsTrue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject() }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", Lock = "1" }); + + // Act + var result = form.IsFieldLocked("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsFieldRequired_WithRequiredField_ReturnsTrue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject() }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", Required = "1" }); + + // Act + var result = form.IsFieldRequired("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void GetFieldValue_FromCurrentRow_ReturnsValue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject() }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "TestValue" }); + + // Act + var result = form.GetFieldValue("100"); + + // Assert + Assert.AreEqual("TestValue", result); + } + + [TestMethod] + public void GetFieldValue_WithRowIdAndFieldNumber_ReturnsValue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject { RowId = "1" } }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "TestValue" }); + + // Act + var result = form.GetFieldValue("1", "100"); + + // Assert + Assert.AreEqual("TestValue", result); + } + + [TestMethod] + public void GetFieldValueFromOtherRows_WithRowIdAndFieldNumber_ReturnsValue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject { RowId = "1" }, MultipleIteration = true }; + var otherRow = new RowObject { RowId = "2" }; + otherRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "OtherValue" }); + form.OtherRows.Add(otherRow); + + // Act + var result = form.GetFieldValue("2", "100"); + + // Assert + Assert.AreEqual("OtherValue", result); + } + + [TestMethod] + public void GetFieldValues_ReturnsAllValues() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject { RowId = "1" }, MultipleIteration = true }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "Value1" }); + + var otherRow = new RowObject { RowId = "2" }; + otherRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "Value2" }); + form.OtherRows.Add(otherRow); + + // Act + var result = form.GetFieldValues("100"); + + // Assert + Assert.AreEqual(2, result.Count); + CollectionAssert.Contains(result, "Value1"); + CollectionAssert.Contains(result, "Value2"); + } + + [TestMethod] + public void SetFieldValue_InCurrentRow_UpdatesValue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject { RowId = "1" } }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "OldValue" }); + + // Act + form.SetFieldValue("100", "NewValue"); + + // Assert + Assert.AreEqual("NewValue", form.CurrentRow.Fields[0].FieldValue); + } + + [TestMethod] + public void SetFieldValue_WithRowId_UpdatesValueInSpecificRow() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject { RowId = "1" }, MultipleIteration = true }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "Value1" }); + + var otherRow = new RowObject { RowId = "2" }; + otherRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "Value2" }); + form.OtherRows.Add(otherRow); + + // Act + form.SetFieldValue("2", "100", "NewValue"); + + // Assert + Assert.AreEqual("Value1", form.CurrentRow.Fields[0].FieldValue); + Assert.AreEqual("NewValue", otherRow.Fields[0].FieldValue); + } + } + + /// + /// Tests for OptionObjectHelpers extension methods + /// + [TestClass] + public class OptionObjectHelpersTests + { + [TestMethod] + public void GetCurrentRowId_ReturnsCurrrentRowId() + { + // Arrange + var optionObject = new OptionObject(); + var form = new FormObject { FormId = "1", CurrentRow = new RowObject { RowId = "100" } }; + optionObject.Forms.Add(form); + + // Act + var result = optionObject.GetCurrentRowId("1"); + + // Assert + Assert.AreEqual("100", result); + } + + [TestMethod] + public void GetCurrentRowId_WithNonExistentForm_ReturnsNull() + { + // Arrange + var optionObject = new OptionObject(); + + // Act + var result = optionObject.GetCurrentRowId("999"); + + // Assert + Assert.IsNull(result); + } + + [TestMethod] + public void GetParentRowId_ReturnsParentRowId() + { + // Arrange + var optionObject = new OptionObject(); + var form = new FormObject { FormId = "1", CurrentRow = new RowObject { ParentRowId = "200" } }; + optionObject.Forms.Add(form); + + // Act + var result = optionObject.GetParentRowId("1"); + + // Assert + Assert.AreEqual("200", result); + } + + [TestMethod] + public void GetFieldValue_FromAnyForm_ReturnsValue() + { + // Arrange + var optionObject = new OptionObject(); + var form = new FormObject { FormId = "1", CurrentRow = new RowObject() }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "TestValue" }); + optionObject.Forms.Add(form); + + // Act + var result = optionObject.GetFieldValue("100"); + + // Assert + Assert.AreEqual("TestValue", result); + } + + [TestMethod] + public void GetFieldValue_WithFormIdRowIdFieldNumber_ReturnsValue() + { + // Arrange + var optionObject = new OptionObject(); + var form = new FormObject { FormId = "1", CurrentRow = new RowObject { RowId = "1" } }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "TestValue" }); + optionObject.Forms.Add(form); + + // Act + var result = optionObject.GetFieldValue("1", "1", "100"); + + // Assert + Assert.AreEqual("TestValue", result); + } + + [TestMethod] + public void GetFieldValues_ReturnsAllValues() + { + // Arrange + var optionObject = new OptionObject(); + var form1 = new FormObject { FormId = "1", CurrentRow = new RowObject { RowId = "1" } }; + form1.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "Value1" }); + optionObject.Forms.Add(form1); + + var form2 = new FormObject { FormId = "2", CurrentRow = new RowObject { RowId = "2" } }; + form2.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "Value2" }); + optionObject.Forms.Add(form2); + + // Act + var result = optionObject.GetFieldValues("100"); + + // Assert + Assert.AreEqual(2, result.Count); + CollectionAssert.Contains(result, "Value1"); + CollectionAssert.Contains(result, "Value2"); + } + + [TestMethod] + public void GetMultipleIterationStatus_ReturnsStatus() + { + // Arrange + var optionObject = new OptionObject(); + var form = new FormObject { FormId = "1", CurrentRow = new RowObject(), MultipleIteration = true }; + optionObject.Forms.Add(form); + + // Act + var result = optionObject.GetMultipleIterationStatus("1"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsFieldPresent_InAnyForm_ReturnsTrue() + { + // Arrange + var optionObject = new OptionObject(); + var form = new FormObject { FormId = "1", CurrentRow = new RowObject() }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100" }); + optionObject.Forms.Add(form); + + // Act + var result = optionObject.IsFieldPresent("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsFieldEnabled_InAnyForm_ReturnsTrue() + { + // Arrange + var optionObject = new OptionObject(); + var form = new FormObject { FormId = "1", CurrentRow = new RowObject() }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", Enabled = "1" }); + optionObject.Forms.Add(form); + + // Act + var result = optionObject.IsFieldEnabled("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsFieldLocked_InAnyForm_ReturnsTrue() + { + // Arrange + var optionObject = new OptionObject(); + var form = new FormObject { FormId = "1", CurrentRow = new RowObject() }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", Lock = "1" }); + optionObject.Forms.Add(form); + + // Act + var result = optionObject.IsFieldLocked("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsFieldRequired_InAnyForm_ReturnsTrue() + { + // Arrange + var optionObject = new OptionObject(); + var form = new FormObject { FormId = "1", CurrentRow = new RowObject() }; + form.CurrentRow.Fields.Add(new FieldObject { FieldNumber = "100", Required = "1" }); + optionObject.Forms.Add(form); + + // Act + var result = optionObject.IsFieldRequired("100"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void GetErrorCode_ReturnsErrorCode() + { + // Arrange + var optionObject = new OptionObject { ErrorCode = 1.0 }; + + // Act + var result = optionObject.GetErrorCode(); + + // Assert + Assert.AreEqual(1.0, result); + } + + [TestMethod] + public void GetErrorMessage_ReturnsErrorMessage() + { + // Arrange + var optionObject = new OptionObject { ErrorMesg = "Test Error" }; + + // Act + var result = optionObject.GetErrorMessage(); + + // Assert + Assert.AreEqual("Test Error", result); + } + + [TestMethod] + public void GetEntityId_ReturnsEntityId() + { + // Arrange + var optionObject = new OptionObject { EntityID = "12345" }; + + // Act + var result = optionObject.GetEntityId(); + + // Assert + Assert.AreEqual("12345", result); + } + + [TestMethod] + public void GetFormCount_ReturnsFormCount() + { + // Arrange + var optionObject = new OptionObject(); + optionObject.Forms.Add(new FormObject { FormId = "1" }); + optionObject.Forms.Add(new FormObject { FormId = "2" }); + + // Act + var result = optionObject.GetFormCount(); + + // Assert + Assert.AreEqual(2, result); + } + + [TestMethod] + public void HasError_WithNonZeroErrorCode_ReturnsTrue() + { + // Arrange + var optionObject = new OptionObject { ErrorCode = 1.0 }; + + // Act + var result = optionObject.HasError(); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void HasError_WithZeroErrorCode_ReturnsFalse() + { + // Arrange + var optionObject = new OptionObject { ErrorCode = 0.0 }; + + // Act + var result = optionObject.HasError(); + + // Assert + Assert.IsFalse(result); + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/GlobalUsings.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/GlobalUsings.cs new file mode 100644 index 00000000..4e07290d --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/GlobalUsings.cs @@ -0,0 +1,5 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; +global using RarelySimple.AvatarScriptLink.Objects; +global using RarelySimple.AvatarScriptLink.Objects.Helpers; +global using RarelySimple.AvatarScriptLink.Objects.Helpers.Manipulators; +global using RarelySimple.AvatarScriptLink.Objects.Helpers.Validators; diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/HelperMethodsTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/HelperMethodsTests.cs new file mode 100644 index 00000000..59d51fc3 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/HelperMethodsTests.cs @@ -0,0 +1,566 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Helpers.Tests +{ + [TestClass] + public class FieldObjectManipulatorsTests + { + [TestMethod] + public void Enable_EnablesField() + { + // Arrange + var field = new FieldObject { Enabled = "0" }; + + // Act + FieldObject? result = field.Enable(); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual("1", field.Enabled); + } + + [TestMethod] + public void Disable_DisablesField() + { + // Arrange + var field = new FieldObject { Enabled = "1" }; + + // Act + FieldObject? result = field.Disable(); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual("0", field.Enabled); + } + + [TestMethod] + public void Lock_LocksField() + { + // Arrange + var field = new FieldObject { Lock = "0" }; + + // Act + FieldObject? result = field.Lock(); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual("1", field.Lock); + } + + [TestMethod] + public void Unlock_UnlocksField() + { + // Arrange + var field = new FieldObject { Lock = "1" }; + + // Act + FieldObject? result = field.Unlock(); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual("0", field.Lock); + } + + [TestMethod] + public void MarkRequired_MarksFieldRequired() + { + // Arrange + var field = new FieldObject { Required = "0" }; + + // Act + FieldObject? result = field.MarkRequired(); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual("1", field.Required); + } + + [TestMethod] + public void MarkOptional_MarksFieldOptional() + { + // Arrange + var field = new FieldObject { Required = "1" }; + + // Act + FieldObject? result = field.MarkOptional(); + + // Assert + Assert.AreSame(field, result); + Assert.AreEqual("0", field.Required); + } + + [TestMethod] + public void ChainedManipulations_WorkCorrectly() + { + // Arrange + var field = new FieldObject { Enabled = "0", Lock = "0", Required = "0" }; + + // Act + field.Enable().Lock().MarkRequired(); + + // Assert + Assert.AreEqual("1", field.Enabled); + Assert.AreEqual("1", field.Lock); + Assert.AreEqual("1", field.Required); + } + } + + [TestClass] + public class RowObjectManipulatorsTests + { + [TestMethod] + public void MarkForAddition_SetsRowActionToAdd() + { + // Arrange + var row = new RowObject(); + + // Act + RowObject? result = row.MarkForAddition(); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual("ADD", row.RowAction); + } + + [TestMethod] + public void MarkForEdit_SetsRowActionToEdit() + { + // Arrange + var row = new RowObject(); + + // Act + RowObject? result = row.MarkForEdit(); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual("EDIT", row.RowAction); + } + + [TestMethod] + public void MarkForDeletion_SetsRowActionToDelete() + { + // Arrange + var row = new RowObject(); + + // Act + RowObject? result = row.MarkForDeletion(); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual("DELETE", row.RowAction); + } + + [TestMethod] + public void ClearRowAction_ClearsRowAction() + { + // Arrange + var row = new RowObject { RowAction = "ADD" }; + + // Act + RowObject? result = row.ClearRowAction(); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual(string.Empty, row.RowAction); + } + + [TestMethod] + public void DisableAllFields_DisablesAllFields() + { + // Arrange + var row = new RowObject(); + var field1 = new FieldObject { FieldNumber = "001", Enabled = "1" }; + var field2 = new FieldObject { FieldNumber = "002", Enabled = "1" }; + row.Fields.Add(field1); + row.Fields.Add(field2); + + // Act + RowObject? result = row.DisableAllFields(); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual("0", field1.Enabled); + Assert.AreEqual("0", field2.Enabled); + } + + [TestMethod] + public void DisableAllFields_WithNullFields_DoesNotThrow() + { + // Arrange + var row = new RowObject(); + + // Act + RowObject? result = row.DisableAllFields(); + + // Assert + Assert.AreSame(row, result); + } + + [TestMethod] + public void EnableAllFields_EnablesAllFields() + { + // Arrange + var row = new RowObject(); + var field1 = new FieldObject { FieldNumber = "001", Enabled = "0" }; + var field2 = new FieldObject { FieldNumber = "002", Enabled = "0" }; + row.Fields.Add(field1); + row.Fields.Add(field2); + + // Act + RowObject? result = row.EnableAllFields(); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual("1", field1.Enabled); + Assert.AreEqual("1", field2.Enabled); + } + + [TestMethod] + public void LockAllFields_LocksAllFields() + { + // Arrange + var row = new RowObject(); + var field1 = new FieldObject { FieldNumber = "001", Lock = "0" }; + var field2 = new FieldObject { FieldNumber = "002", Lock = "0" }; + row.Fields.Add(field1); + row.Fields.Add(field2); + + // Act + RowObject? result = row.LockAllFields(); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual("1", field1.Lock); + Assert.AreEqual("1", field2.Lock); + } + + [TestMethod] + public void UnlockAllFields_UnlocksAllFields() + { + // Arrange + var row = new RowObject(); + var field1 = new FieldObject { FieldNumber = "001", Lock = "1" }; + var field2 = new FieldObject { FieldNumber = "002", Lock = "1" }; + row.Fields.Add(field1); + row.Fields.Add(field2); + + // Act + RowObject? result = row.UnlockAllFields(); + + // Assert + Assert.AreSame(row, result); + Assert.AreEqual("0", field1.Lock); + Assert.AreEqual("0", field2.Lock); + } + } + + [TestClass] + public class FieldObjectValidatorsTests + { + [TestMethod] + public void HasValue_WithValue_ReturnsTrue() + { + // Arrange + var field = new FieldObject { FieldValue = "Test" }; + + // Act + bool result = field.HasValue(); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void HasValue_WithEmpty_ReturnsFalse() + { + // Arrange + var field = new FieldObject { FieldValue = "" }; + + // Act + bool result = field.HasValue(); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void HasValue_WithNull_ReturnsFalse() + { + // Arrange + var field = new FieldObject { FieldValue = null }; + + // Act + bool result = field.HasValue(); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void IsEmpty_WithEmptyValue_ReturnsTrue() + { + // Arrange + var field = new FieldObject { FieldValue = "" }; + + // Act + bool result = field.IsEmpty(); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsEmpty_WithValue_ReturnsFalse() + { + // Arrange + var field = new FieldObject { FieldValue = "Test" }; + + // Act + bool result = field.IsEmpty(); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void ValueEquals_WithMatchingValue_ReturnsTrue() + { + // Arrange + var field = new FieldObject { FieldValue = "Test" }; + + // Act + bool result = field.ValueEquals("Test"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void ValueEquals_WithNonMatchingValue_ReturnsFalse() + { + // Arrange + var field = new FieldObject { FieldValue = "Test" }; + + // Act + bool result = field.ValueEquals("Other"); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void ValueEqualsIgnoreCase_WithMatchingValue_ReturnsTrue() + { + // Arrange + var field = new FieldObject { FieldValue = "Test" }; + + // Act + bool result = field.ValueEqualsIgnoreCase("test"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void ValueContains_WithContainedSubstring_ReturnsTrue() + { + // Arrange + var field = new FieldObject { FieldValue = "Test Value" }; + + // Act + bool result = field.ValueContains("Value"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void ValueContains_WithNonContainedSubstring_ReturnsFalse() + { + // Arrange + var field = new FieldObject { FieldValue = "Test" }; + + // Act + bool result = field.ValueContains("Other"); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void ValueStartsWith_WithMatchingPrefix_ReturnsTrue() + { + // Arrange + var field = new FieldObject { FieldValue = "TestValue" }; + + // Act + bool result = field.ValueStartsWith("Test"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void ValueEndsWith_WithMatchingSuffix_ReturnsTrue() + { + // Arrange + var field = new FieldObject { FieldValue = "TestValue" }; + + // Act + bool result = field.ValueEndsWith("Value"); + + // Assert + Assert.IsTrue(result); + } + } + + [TestClass] + public class FormObjectValidatorsTests + { + [TestMethod] + public void HasField_WithFieldPresent_ReturnsTrue() + { + // Arrange + var form = new FormObject(); + var row = new RowObject(); + var field = new FieldObject { FieldNumber = "001" }; + row.Fields.Add(field); + form.CurrentRow = row; + + // Act + bool result = form.HasField("001"); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void HasField_WithFieldAbsent_ReturnsFalse() + { + // Arrange + var form = new FormObject(); + var row = new RowObject(); + var field = new FieldObject { FieldNumber = "001" }; + row.Fields.Add(field); + form.CurrentRow = row; + + // Act + bool result = form.HasField("002"); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void HasField_WithNoCurrentRow_ReturnsFalse() + { + // Arrange + var form = new FormObject(); + + // Act + bool result = form.HasField("001"); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void HasAnyRows_WithCurrentRow_ReturnsTrue() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject() }; + + // Act + bool result = form.HasAnyRows(); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void HasAnyRows_WithOtherRows_ReturnsTrue() + { + // Arrange + var form = new FormObject(); + form.OtherRows.Add(new RowObject()); + + // Act + bool result = form.HasAnyRows(); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void HasAnyRows_WithNoRows_ReturnsFalse() + { + // Arrange + var form = new FormObject(); + + // Act + bool result = form.HasAnyRows(); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void IsEmpty_WithNoRows_ReturnsTrue() + { + // Arrange + var form = new FormObject(); + + // Act + bool result = form.IsEmpty(); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void IsEmpty_WithRows_ReturnsFalse() + { + // Arrange + var form = new FormObject { CurrentRow = new RowObject() }; + + // Act + bool result = form.IsEmpty(); + + // Assert + Assert.IsFalse(result); + } + + [TestMethod] + public void GetTotalFieldCount_WithMultipleRows_ReturnsTotalCount() + { + // Arrange + var form = new FormObject(); + var row1 = new RowObject(); + row1.Fields.Add(new FieldObject()); + row1.Fields.Add(new FieldObject()); + + var row2 = new RowObject(); + row2.Fields.Add(new FieldObject()); + + form.CurrentRow = row1; + form.OtherRows.Add(row2); + + // Act + int result = form.GetTotalFieldCount(); + + // Assert + Assert.AreEqual(3, result); + } + + [TestMethod] + public void GetTotalFieldCount_WithEmptyForm_ReturnsZero() + { + // Arrange + var form = new FormObject(); + + // Act + int result = form.GetTotalFieldCount(); + + // Assert + Assert.AreEqual(0, result); + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests.csproj b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests.csproj new file mode 100644 index 00000000..363a3938 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests/RarelySimple.AvatarScriptLink.Objects.Helpers.Tests.csproj @@ -0,0 +1,26 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/FieldObjectHelpers.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/FieldObjectHelpers.cs new file mode 100644 index 00000000..d4a52482 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/FieldObjectHelpers.cs @@ -0,0 +1,43 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Helpers +{ + /// + /// Provides extension methods for querying and manipulating instances. + /// + public static class FieldObjectHelpers + { + /// + /// Gets the field value of a . + /// + /// The FieldObject to query. + /// The field value, or null if not set. + public static string? GetValue(this FieldObject fieldObject) + { + return fieldObject?.FieldValue; + } + + /// + /// Sets the field value of a . + /// + /// The FieldObject to modify. + /// The value to set. + public static void SetValue(this FieldObject fieldObject, string value) + { + if (fieldObject != null) + { + fieldObject.FieldValue = value ?? string.Empty; + } + } + + /// + /// Clears the field value of a . + /// + /// The FieldObject to modify. + public static void ClearValue(this FieldObject fieldObject) + { + if (fieldObject != null) + { + fieldObject.FieldValue = string.Empty; + } + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/FormObjectHelpers.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/FormObjectHelpers.cs new file mode 100644 index 00000000..cca31d01 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/FormObjectHelpers.cs @@ -0,0 +1,311 @@ +using System.Collections.Generic; +using System.Linq; + +namespace RarelySimple.AvatarScriptLink.Objects.Helpers +{ + /// + /// Provides extension methods for querying and manipulating instances. + /// + public static class FormObjectHelpers + { + /// + /// Gets the form ID of a . + /// + /// The FormObject to query. + /// The form ID, or null if not set. + public static string? GetFormId(this FormObject formObject) + { + return formObject?.FormId; + } + + /// + /// Determines if a supports multiple iteration. + /// + /// The FormObject to query. + /// True if the form supports multiple iteration, false otherwise. + public static bool IsMultipleIteration(this FormObject formObject) + { + return formObject?.MultipleIteration ?? false; + } + + /// + /// Gets the total number of rows in a (current + other rows). + /// + /// The FormObject to query. + /// The total number of rows. + public static int GetRowCount(this FormObject formObject) + { + if (formObject == null) + { + return 0; + } + + int count = 0; + if (formObject.HasCurrentRow()) + { + count++; + } + if (formObject.HasOtherRows()) + { + count += formObject.OtherRows.Count; + } + return count; + } + + /// + /// Gets the current row ID of a . + /// + /// The FormObject to query. + /// The current row ID, or null if not set. + public static string? GetCurrentRowId(this FormObject formObject) + { + return formObject?.CurrentRow?.RowId; + } + + /// + /// Gets the parent row ID of a . + /// + /// The FormObject to query. + /// The parent row ID, or null if not set. + public static string? GetParentRowId(this FormObject formObject) + { + return formObject?.CurrentRow?.ParentRowId; + } + + /// + /// Gets the field value of a in the current row of a by field number. + /// + /// The FormObject to query. + /// The field number to search for. + /// The field value, or null if not found. + public static string? GetFieldValue(this FormObject formObject, string fieldNumber) + { + if (formObject?.CurrentRow == null || string.IsNullOrEmpty(fieldNumber)) + return null; + + return formObject.CurrentRow.GetFieldValue(fieldNumber); + } + + /// + /// Gets the field value of a in a by row ID and field number. + /// + /// The FormObject to query. + /// The row ID to search for. + /// The field number to search for. + /// The field value, or null if not found. + public static string? GetFieldValue(this FormObject formObject, string rowId, string fieldNumber) + { + if (formObject?.CurrentRow == null || string.IsNullOrEmpty(rowId) || string.IsNullOrEmpty(fieldNumber)) + return null; + + if (formObject.CurrentRow.RowId == rowId) + return formObject.CurrentRow.GetFieldValue(fieldNumber); + + if (formObject.MultipleIteration && formObject.HasOtherRows()) + { + foreach (var row in formObject.OtherRows) + { + if (row.RowId == rowId) + return row.GetFieldValue(fieldNumber); + } + } + + return null; + } + + /// + /// Gets a list of field values for a specified field number across all rows in a . + /// + /// The FormObject to query. + /// The field number to search for. + /// A list of field values, or empty list if not found. + public static List GetFieldValues(this FormObject formObject, string fieldNumber) + { + var values = new List(); + + if (formObject?.CurrentRow == null || string.IsNullOrEmpty(fieldNumber)) + return values; + + AddFieldValueIfPresent(values, formObject.CurrentRow, fieldNumber); + + if (formObject.MultipleIteration && formObject.HasOtherRows()) + { + foreach (var row in formObject.OtherRows) + { + AddFieldValueIfPresent(values, row, fieldNumber); + } + } + + return values; + } + + /// + /// Adds a field value to a list if the field is present in the row. + /// + /// The list to add the value to. + /// The RowObject to search. + /// The field number to search for. + private static void AddFieldValueIfPresent(List values, RowObject row, string fieldNumber) + { + if (row.IsFieldPresent(fieldNumber)) + { + var value = row.GetFieldValue(fieldNumber); + if (value != null) + values.Add(value); + } + } + + /// + /// Determines if a is present in the current row of a by field number. + /// + /// The FormObject to query. + /// The field number to search for. + /// True if the field is present, false otherwise. + public static bool IsFieldPresent(this FormObject formObject, string fieldNumber) + { + if (formObject?.CurrentRow == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return formObject.CurrentRow.IsFieldPresent(fieldNumber); + } + + /// + /// Determines if a in the current row of a is enabled by field number. + /// + /// The FormObject to query. + /// The field number to search for. + /// True if the field is enabled, false if disabled or not found. + public static bool IsFieldEnabled(this FormObject formObject, string fieldNumber) + { + if (formObject?.CurrentRow == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return formObject.CurrentRow.IsFieldEnabled(fieldNumber); + } + + /// + /// Determines if a in the current row of a is locked by field number. + /// + /// The FormObject to query. + /// The field number to search for. + /// True if the field is locked, false if not locked or not found. + public static bool IsFieldLocked(this FormObject formObject, string fieldNumber) + { + if (formObject?.CurrentRow == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return formObject.CurrentRow.IsFieldLocked(fieldNumber); + } + + /// + /// Determines if a in the current row of a is required by field number. + /// + /// The FormObject to query. + /// The field number to search for. + /// True if the field is required, false if not required or not found. + public static bool IsFieldRequired(this FormObject formObject, string fieldNumber) + { + if (formObject?.CurrentRow == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return formObject.CurrentRow.IsFieldRequired(fieldNumber); + } + + /// + /// Determines if a in a is marked for deletion by row ID. + /// + /// The FormObject to query. + /// The row ID to search for. + /// True if the row is marked for deletion, false otherwise. + public static bool IsRowMarkedForDeletion(this FormObject formObject, string rowId) + { + if (formObject == null || formObject.CurrentRow == null || string.IsNullOrEmpty(rowId)) + return false; + + if (formObject.CurrentRow.RowId == rowId) + return formObject.CurrentRow.IsMarkedForDeletion(); + + if (formObject.MultipleIteration && formObject.HasOtherRows()) + { + return formObject.OtherRows + .Any(r => r.RowId == rowId && r.IsMarkedForDeletion()); + } + + return false; + } + + /// + /// Determines if a is present in a by row ID. + /// + /// The FormObject to query. + /// The row ID to search for. + /// True if the row is present, false otherwise. + public static bool IsRowPresent(this FormObject formObject, string rowId) + { + if (formObject == null || formObject.CurrentRow == null || string.IsNullOrEmpty(rowId)) + return false; + + if (formObject.CurrentRow.RowId == rowId) + return true; + + if (formObject.MultipleIteration && formObject.HasOtherRows()) + { + return formObject.OtherRows.Any(r => r.RowId == rowId); + } + + return false; + } + + /// + /// Sets the field value of a in the current row of a by field number. + /// If the form is multiple iteration with other rows, this method does nothing (row must be specified). + /// + /// The FormObject to modify. + /// The field number to search for. + /// The new field value. + /// The modified FormObject, or the original if the field is not found. + public static FormObject? SetFieldValue(this FormObject formObject, string fieldNumber, string fieldValue) + { + if (formObject == null || formObject.CurrentRow == null || string.IsNullOrEmpty(fieldNumber)) + return formObject; + + // Prevent ambiguity for MI forms with multiple rows + if (formObject.MultipleIteration && formObject.HasOtherRows()) + return formObject; + + formObject.CurrentRow.SetFieldValue(fieldNumber, fieldValue); + return formObject; + } + + /// + /// Sets the field value of a in a by row ID and field number. + /// + /// The FormObject to modify. + /// The row ID to search for. + /// The field number to search for. + /// The new field value. + /// The modified FormObject, or the original if the row or field is not found. + public static FormObject? SetFieldValue(this FormObject formObject, string rowId, string fieldNumber, string fieldValue) + { + if (formObject == null || formObject.CurrentRow == null || string.IsNullOrEmpty(rowId) || string.IsNullOrEmpty(fieldNumber)) + return formObject; + + if (formObject.CurrentRow.RowId == rowId) + { + formObject.CurrentRow.SetFieldValue(fieldNumber, fieldValue); + return formObject; + } + + if (formObject.MultipleIteration && formObject.HasOtherRows()) + { + var row = formObject.OtherRows.FirstOrDefault(r => r.RowId == rowId); + if (row != null) + { + row.SetFieldValue(fieldNumber, fieldValue); + } + } + + return formObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Manipulators/FieldObjectManipulators.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Manipulators/FieldObjectManipulators.cs new file mode 100644 index 00000000..4c7692a0 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Manipulators/FieldObjectManipulators.cs @@ -0,0 +1,94 @@ +using System; + +namespace RarelySimple.AvatarScriptLink.Objects.Helpers.Manipulators +{ + /// + /// Provides extension methods for manipulating instances. + /// + public static class FieldObjectManipulators + { + /// + /// Enables a . + /// + /// The FieldObject to manipulate. + /// The FieldObject for method chaining, or null if input is null. + public static FieldObject? Enable(this FieldObject? fieldObject) + { + if (fieldObject != null) + { + fieldObject.SetEnabled(true); + } + return fieldObject; + } + + /// + /// Disables a . + /// + /// The FieldObject to manipulate. + /// The FieldObject for method chaining, or null if input is null. + public static FieldObject? Disable(this FieldObject? fieldObject) + { + if (fieldObject != null) + { + fieldObject.SetEnabled(false); + } + return fieldObject; + } + + /// + /// Locks a . + /// + /// The FieldObject to manipulate. + /// The FieldObject for method chaining, or null if input is null. + public static FieldObject? Lock(this FieldObject? fieldObject) + { + if (fieldObject != null) + { + fieldObject.SetLocked(true); + } + return fieldObject; + } + + /// + /// Unlocks a . + /// + /// The FieldObject to manipulate. + /// The FieldObject for method chaining, or null if input is null. + public static FieldObject? Unlock(this FieldObject? fieldObject) + { + if (fieldObject != null) + { + fieldObject.SetLocked(false); + } + return fieldObject; + } + + /// + /// Marks a as required. + /// + /// The FieldObject to manipulate. + /// The FieldObject for method chaining, or null if input is null. + public static FieldObject? MarkRequired(this FieldObject? fieldObject) + { + if (fieldObject != null) + { + fieldObject.SetRequired(true); + } + return fieldObject; + } + + /// + /// Marks a as optional. + /// + /// The FieldObject to manipulate. + /// The FieldObject for method chaining, or null if input is null. + public static FieldObject? MarkOptional(this FieldObject? fieldObject) + { + if (fieldObject != null) + { + fieldObject.SetRequired(false); + } + return fieldObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Manipulators/RowObjectManipulators.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Manipulators/RowObjectManipulators.cs new file mode 100644 index 00000000..d0d8cc2a --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Manipulators/RowObjectManipulators.cs @@ -0,0 +1,134 @@ +using System; + +namespace RarelySimple.AvatarScriptLink.Objects.Helpers.Manipulators +{ + /// + /// Provides extension methods for manipulating instances. + /// + public static class RowObjectManipulators + { + /// + /// Marks a for addition. + /// + /// The RowObject to manipulate. + /// The RowObject for method chaining, or null if input is null. + public static RowObject? MarkForAddition(this RowObject? rowObject) + { + if (rowObject != null) + { + rowObject.RowAction = "ADD"; + } + return rowObject; + } + + /// + /// Marks a for editing. + /// + /// The RowObject to manipulate. + /// The RowObject for method chaining, or null if input is null. + public static RowObject? MarkForEdit(this RowObject? rowObject) + { + if (rowObject != null) + { + rowObject.RowAction = "EDIT"; + } + return rowObject; + } + + /// + /// Marks a for deletion. + /// + /// The RowObject to manipulate. + /// The RowObject for method chaining, or null if input is null. + public static RowObject? MarkForDeletion(this RowObject? rowObject) + { + if (rowObject != null) + { + rowObject.RowAction = "DELETE"; + } + return rowObject; + } + + /// + /// Clears the RowAction of a . + /// + /// The RowObject to manipulate. + /// The RowObject for method chaining, or null if input is null. + public static RowObject? ClearRowAction(this RowObject? rowObject) + { + if (rowObject != null) + { + rowObject.RowAction = string.Empty; + } + return rowObject; + } + + /// + /// Disables all fields in a . + /// + /// The RowObject to manipulate. + /// The RowObject for method chaining, or null if input is null. + public static RowObject? DisableAllFields(this RowObject? rowObject) + { + if (rowObject?.HasFields() == true) + { + foreach (var field in rowObject.Fields) + { + field?.SetEnabled(false); + } + } + return rowObject; + } + + /// + /// Enables all fields in a . + /// + /// The RowObject to manipulate. + /// The RowObject for method chaining, or null if input is null. + public static RowObject? EnableAllFields(this RowObject? rowObject) + { + if (rowObject?.HasFields() == true) + { + foreach (var field in rowObject.Fields) + { + field?.SetEnabled(true); + } + } + return rowObject; + } + + /// + /// Locks all fields in a . + /// + /// The RowObject to manipulate. + /// The RowObject for method chaining, or null if input is null. + public static RowObject? LockAllFields(this RowObject? rowObject) + { + if (rowObject?.HasFields() == true) + { + foreach (var field in rowObject.Fields) + { + field?.SetLocked(true); + } + } + return rowObject; + } + + /// + /// Unlocks all fields in a . + /// + /// The RowObject to manipulate. + /// The RowObject for method chaining, or null if input is null. + public static RowObject? UnlockAllFields(this RowObject? rowObject) + { + if (rowObject?.HasFields() == true) + { + foreach (var field in rowObject.Fields) + { + field?.SetLocked(false); + } + } + return rowObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObject2015Helpers.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObject2015Helpers.cs new file mode 100644 index 00000000..b9919d0a --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObject2015Helpers.cs @@ -0,0 +1,80 @@ +using System; + +namespace RarelySimple.AvatarScriptLink.Objects.Helpers +{ + /// + /// Provides extension methods for querying and manipulating instances. + /// + public static class OptionObject2015Helpers + { + /// + /// Gets the entity ID of an . + /// + /// The OptionObject2015 to query. + /// The entity ID, or null if not set. + public static string? GetEntityId(this OptionObject2015 optionObject) + { + return optionObject?.EntityID; + } + + /// + /// Gets the error code of an . + /// + /// The OptionObject2015 to query. + /// The error code. + public static double GetErrorCode(this OptionObject2015 optionObject) + { + return optionObject?.ErrorCode ?? 0; + } + + /// + /// Gets the error message of an . + /// + /// The OptionObject2015 to query. + /// The error message, or null if not set. + public static string? GetErrorMessage(this OptionObject2015 optionObject) + { + return optionObject?.ErrorMesg; + } + + /// + /// Gets the total number of forms in an . + /// + /// The OptionObject2015 to query. + /// The number of forms. + public static int GetFormCount(this OptionObject2015 optionObject) + { + return optionObject?.Forms?.Count ?? 0; + } + + /// + /// Gets the session token of an . + /// + /// The OptionObject2015 to query. + /// The session token, or null if not set. + public static string? GetSessionToken(this OptionObject2015 optionObject) + { + return optionObject?.SessionToken; + } + + /// + /// Gets the option user ID of an . + /// + /// The OptionObject2015 to query. + /// The option user ID, or null if not set. + public static string? GetOptionUserId(this OptionObject2015 optionObject) + { + return optionObject?.OptionUserId; + } + + /// + /// Determines if an has an error. + /// + /// The OptionObject2015 to query. + /// True if the error code is not 0, false otherwise. + public static bool HasError(this OptionObject2015 optionObject) + { + return Math.Abs(optionObject?.ErrorCode ?? 0d) > double.Epsilon; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObject2Helpers.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObject2Helpers.cs new file mode 100644 index 00000000..84be4b5f --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObject2Helpers.cs @@ -0,0 +1,60 @@ +using System; + +namespace RarelySimple.AvatarScriptLink.Objects.Helpers +{ + /// + /// Provides extension methods for querying and manipulating instances. + /// + public static class OptionObject2Helpers + { + /// + /// Gets the entity ID of an . + /// + /// The OptionObject2 to query. + /// The entity ID, or null if not set. + public static string? GetEntityId(this OptionObject2 optionObject) + { + return optionObject?.EntityID; + } + + /// + /// Gets the error code of an . + /// + /// The OptionObject2 to query. + /// The error code. + public static double GetErrorCode(this OptionObject2 optionObject) + { + return optionObject?.ErrorCode ?? 0; + } + + /// + /// Gets the error message of an . + /// + /// The OptionObject2 to query. + /// The error message, or null if not set. + public static string? GetErrorMessage(this OptionObject2 optionObject) + { + return optionObject?.ErrorMesg; + } + + /// + /// Gets the total number of forms in an . + /// + /// The OptionObject2 to query. + /// The number of forms. + public static int GetFormCount(this OptionObject2 optionObject) + { + return optionObject?.Forms?.Count ?? 0; + } + + /// + /// Determines if an has an error. + /// + /// The OptionObject2 to query. + /// True if the error code is not 0, false otherwise. + public static bool HasError(this OptionObject2 optionObject) + { + return Math.Abs(optionObject?.ErrorCode ?? 0d) > double.Epsilon; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObjectHelpers.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObjectHelpers.cs new file mode 100644 index 00000000..a35d6ce6 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/OptionObjectHelpers.cs @@ -0,0 +1,232 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace RarelySimple.AvatarScriptLink.Objects.Helpers +{ + /// + /// Provides extension methods for querying and manipulating instances. + /// + public static class OptionObjectHelpers + { + /// + /// Gets the entity ID of an . + /// + /// The OptionObject to query. + /// The entity ID, or null if not set. + public static string? GetEntityId(this OptionObject optionObject) + { + return optionObject?.EntityID; + } + + /// + /// Gets the error code of an . + /// + /// The OptionObject to query. + /// The error code. + public static double GetErrorCode(this OptionObject optionObject) + { + return optionObject?.ErrorCode ?? 0; + } + + /// + /// Gets the error message of an . + /// + /// The OptionObject to query. + /// The error message, or null if not set. + public static string? GetErrorMessage(this OptionObject optionObject) + { + return optionObject?.ErrorMesg; + } + + /// + /// Gets the total number of forms in an . + /// + /// The OptionObject to query. + /// The number of forms. + public static int GetFormCount(this OptionObject optionObject) + { + return optionObject?.Forms?.Count ?? 0; + } + + /// + /// Determines if an has an error. + /// + /// The OptionObject to query. + /// True if the error code is not 0, false otherwise. + public static bool HasError(this OptionObject optionObject) + { + return Math.Abs(optionObject?.ErrorCode ?? 0d) > double.Epsilon; + } + + /// + /// Gets the current row ID of a in an by form ID. + /// + /// The OptionObject to query. + /// The form ID to search for. + /// The current row ID, or null if not found. + public static string? GetCurrentRowId(this OptionObject optionObject, string formId) + { + if (optionObject == null || optionObject.Forms == null || string.IsNullOrEmpty(formId)) + return null; + + return optionObject.Forms + .FirstOrDefault(f => f.FormId == formId)? + .GetCurrentRowId(); + } + + /// + /// Gets the parent row ID of a in an by form ID. + /// + /// The OptionObject to query. + /// The form ID to search for. + /// The parent row ID, or null if not found. + public static string? GetParentRowId(this OptionObject optionObject, string formId) + { + if (optionObject == null || optionObject.Forms == null || string.IsNullOrEmpty(formId)) + return null; + + return optionObject.Forms + .FirstOrDefault(f => f.FormId == formId)? + .GetParentRowId(); + } + + /// + /// Gets the field value of a in an by field number (searches all forms). + /// + /// The OptionObject to query. + /// The field number to search for. + /// The field value, or null if not found. + public static string? GetFieldValue(this OptionObject optionObject, string fieldNumber) + { + if (optionObject == null || optionObject.Forms == null || string.IsNullOrEmpty(fieldNumber)) + return null; + + return optionObject.Forms + .Where(f => f.IsFieldPresent(fieldNumber)) + .Select(f => f.GetFieldValue(fieldNumber)) + .FirstOrDefault(); + } + + /// + /// Gets the field value of a in an by form ID, row ID, and field number. + /// + /// The OptionObject to query. + /// The form ID to search for. + /// The row ID to search for. + /// The field number to search for. + /// The field value, or null if not found. + public static string? GetFieldValue(this OptionObject optionObject, string formId, string rowId, string fieldNumber) + { + if (optionObject == null || optionObject.Forms == null || string.IsNullOrEmpty(formId) || string.IsNullOrEmpty(rowId) || string.IsNullOrEmpty(fieldNumber)) + return null; + + return optionObject.Forms + .FirstOrDefault(f => f.FormId == formId)? + .GetFieldValue(rowId, fieldNumber); + } + + /// + /// Gets a list of field values for a specified field number across all rows in all forms in an . + /// + /// The OptionObject to query. + /// The field number to search for. + /// A list of field values, or empty list if not found. + public static List GetFieldValues(this OptionObject optionObject, string fieldNumber) + { + var values = new List(); + + if (optionObject == null || optionObject.Forms == null || string.IsNullOrEmpty(fieldNumber)) + return values; + + foreach (var form in optionObject.Forms.Where(f => f.IsFieldPresent(fieldNumber))) + { + var formValues = form.GetFieldValues(fieldNumber); + values.AddRange(formValues); + } + + return values; + } + + /// + /// Determines if a in an supports multiple iteration by form ID. + /// + /// The OptionObject to query. + /// The form ID to search for. + /// True if the form supports multiple iteration, false otherwise. + public static bool GetMultipleIterationStatus(this OptionObject optionObject, string formId) + { + if (optionObject == null || optionObject.Forms == null || string.IsNullOrEmpty(formId)) + return false; + + return optionObject.Forms + .FirstOrDefault(f => f.FormId == formId)? + .IsMultipleIteration() ?? false; + } + + /// + /// Determines if a is present in an by field number (searches all forms). + /// + /// The OptionObject to query. + /// The field number to search for. + /// True if the field is present, false otherwise. + public static bool IsFieldPresent(this OptionObject optionObject, string fieldNumber) + { + if (optionObject == null || optionObject.Forms == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return optionObject.Forms.Any(f => f.IsFieldPresent(fieldNumber)); + } + + /// + /// Determines if a in an is enabled by field number (searches all forms). + /// + /// The OptionObject to query. + /// The field number to search for. + /// True if the field is enabled, false if disabled or not found. + public static bool IsFieldEnabled(this OptionObject optionObject, string fieldNumber) + { + if (optionObject == null || optionObject.Forms == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return optionObject.Forms + .Where(f => f.IsFieldPresent(fieldNumber)) + .Select(f => f.IsFieldEnabled(fieldNumber)) + .FirstOrDefault(); + } + + /// + /// Determines if a in an is locked by field number (searches all forms). + /// + /// The OptionObject to query. + /// The field number to search for. + /// True if the field is locked, false if not locked or not found. + public static bool IsFieldLocked(this OptionObject optionObject, string fieldNumber) + { + if (optionObject == null || optionObject.Forms == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return optionObject.Forms + .Where(f => f.IsFieldPresent(fieldNumber)) + .Select(f => f.IsFieldLocked(fieldNumber)) + .FirstOrDefault(); + } + + /// + /// Determines if a in an is required by field number (searches all forms). + /// + /// The OptionObject to query. + /// The field number to search for. + /// True if the field is required, false if not required or not found. + public static bool IsFieldRequired(this OptionObject optionObject, string fieldNumber) + { + if (optionObject == null || optionObject.Forms == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return optionObject.Forms + .Where(f => f.IsFieldPresent(fieldNumber)) + .Select(f => f.IsFieldRequired(fieldNumber)) + .FirstOrDefault(); + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/README.md b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/README.md new file mode 100644 index 00000000..85f47d87 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/README.md @@ -0,0 +1,42 @@ +# RarelySimple.AvatarScriptLink.Objects.Helpers + +Extension methods for querying, manipulating, and validating ScriptLink objects. + +## Usage + +```csharp +using RarelySimple.AvatarScriptLink.Objects.Helpers; + +// Query field status +if (field.IsEnabled() && field.IsRequired()) +{ + // Process required fields +} + +// Safely check for collections +if (form.HasOtherRows()) +{ + // Iterate over rows +} + +// Manipulate field properties +field.SetEnabled(true); +field.SetValue("new value"); +``` + +## Features + +- Query extension methods (IsEnabled, IsLocked, HasForms, etc.) +- Manipulation extension methods for modifying object properties +- Validation extension methods for checking object state +- Helpers organized by concern (Manipulators, Validators, etc.) +- Comprehensive XML documentation + +## Dependencies + +- **RarelySimple.AvatarScriptLink.Objects** - Core object definitions +- .NET Standard 2.0+ + +## License + +MIT diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/RarelySimple.AvatarScriptLink.Objects.Helpers.csproj b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/RarelySimple.AvatarScriptLink.Objects.Helpers.csproj new file mode 100644 index 00000000..65f1aad2 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/RarelySimple.AvatarScriptLink.Objects.Helpers.csproj @@ -0,0 +1,45 @@ + + + + netstandard2.0 + 8.0 + enable + false + Scott Olson Jr + Rarely Simple + MIT + https://github.com/rarelysimple/RarelySimple.AvatarScriptLink + https://scriptlink.rarelysimple.com/ + git + Copyright © 2026 Scott Olson Jr + RarelySimple.AvatarScriptLink.Objects.Helpers provides extension methods for querying, manipulating, and validating ScriptLink objects. + en-US + true + ../RarelySimple.AvatarScriptLink.snk + ../RarelySimple.AvatarScriptLink.ruleset + RarelySimple.AvatarScriptLink.Objects.Helpers + README.md + true + 2.0.0 + $(Version) + $(Version) + v + preview.0 + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/RowObjectHelpers.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/RowObjectHelpers.cs new file mode 100644 index 00000000..ded2b07b --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/RowObjectHelpers.cs @@ -0,0 +1,298 @@ +using System.Collections.Generic; +using System.Linq; +using RarelySimple.AvatarScriptLink.Objects.Helpers.Manipulators; + +namespace RarelySimple.AvatarScriptLink.Objects.Helpers +{ + /// + /// Provides extension methods for querying and manipulating instances. + /// + public static class RowObjectHelpers + { + /// + /// Gets the row ID of a . + /// + /// The RowObject to query. + /// The row ID, or null if not set. + public static string? GetRowId(this RowObject rowObject) + { + return rowObject?.RowId; + } + + /// + /// Gets the parent row ID of a . + /// + /// The RowObject to query. + /// The parent row ID, or null if not set. + public static string? GetParentRowId(this RowObject rowObject) + { + return rowObject?.ParentRowId; + } + + /// + /// Gets the row action of a . + /// + /// The RowObject to query. + /// The row action, or null if not set. + public static string? GetRowAction(this RowObject rowObject) + { + return rowObject?.RowAction; + } + + /// + /// Determines if a is marked for deletion. + /// + /// The RowObject to query. + /// True if the row is marked for deletion, false otherwise. + public static bool IsMarkedForDeletion(this RowObject rowObject) + { + return rowObject?.RowAction == "DELETE"; + } + + /// + /// Gets the number of fields in a . + /// + /// The RowObject to query. + /// The number of fields. + public static int GetFieldCount(this RowObject rowObject) + { + return rowObject?.Fields?.Count ?? 0; + } + + /// + /// Gets the field value of a in a by field number. + /// + /// The RowObject to query. + /// The field number to search for. + /// The field value, or null if not found. + public static string? GetFieldValue(this RowObject rowObject, string fieldNumber) + { + if (rowObject == null || rowObject.Fields == null || string.IsNullOrEmpty(fieldNumber)) + return null; + + return rowObject.Fields + .FirstOrDefault(f => f.FieldNumber == fieldNumber)? + .FieldValue; + } + + /// + /// Determines if a is present in a by field number. + /// + /// The RowObject to query. + /// The field number to search for. + /// True if the field is present, false otherwise. + public static bool IsFieldPresent(this RowObject rowObject, string fieldNumber) + { + if (rowObject == null || rowObject.Fields == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return rowObject.Fields.Any(f => f.FieldNumber == fieldNumber); + } + + /// + /// Determines if a in a is enabled by field number. + /// + /// The RowObject to query. + /// The field number to search for. + /// True if the field is enabled, false if disabled or not found. + public static bool IsFieldEnabled(this RowObject rowObject, string fieldNumber) + { + if (rowObject == null || rowObject.Fields == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return rowObject.Fields + .Where(f => f.FieldNumber == fieldNumber) + .Select(f => f.IsEnabled()) + .FirstOrDefault(); + } + + /// + /// Determines if a in a is locked by field number. + /// + /// The RowObject to query. + /// The field number to search for. + /// True if the field is locked, false if not locked or not found. + public static bool IsFieldLocked(this RowObject rowObject, string fieldNumber) + { + if (rowObject == null || rowObject.Fields == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return rowObject.Fields + .Where(f => f.FieldNumber == fieldNumber) + .Select(f => f.IsLocked()) + .FirstOrDefault(); + } + + /// + /// Determines if a in a is required by field number. + /// + /// The RowObject to query. + /// The field number to search for. + /// True if the field is required, false if not required or not found. + public static bool IsFieldRequired(this RowObject rowObject, string fieldNumber) + { + if (rowObject == null || rowObject.Fields == null || string.IsNullOrEmpty(fieldNumber)) + return false; + + return rowObject.Fields + .Where(f => f.FieldNumber == fieldNumber) + .Select(f => f.IsRequired()) + .FirstOrDefault(); + } + + /// + /// Sets the field value of a in a by field number. + /// If the field is not present, this method does nothing. + /// + /// The RowObject to modify. + /// The field number to search for. + /// The new field value. + /// The modified RowObject, or the original if the field is not found. + public static RowObject? SetFieldValue(this RowObject rowObject, string fieldNumber, string fieldValue) + { + if (rowObject == null || rowObject.Fields == null || string.IsNullOrEmpty(fieldNumber)) + return rowObject; + + var field = rowObject.Fields.FirstOrDefault(f => f.FieldNumber == fieldNumber); + if (field != null) + { + field.SetValue(fieldValue); + if (rowObject.RowAction == "") + rowObject.RowAction = "EDIT"; + } + return rowObject; + } + + /// + /// Disables all instances in a . + /// + /// The RowObject to modify. + /// The modified RowObject. + public static RowObject? DisableAllFieldObjects(this RowObject rowObject) + { + return DisableAllFieldObjects(rowObject, null); + } + + /// + /// Disables all instances in a , except for the field numbers specified in the exclusion list. + /// + /// The RowObject to modify. + /// The field numbers to exclude from disabling. + /// The modified RowObject. + public static RowObject? DisableAllFieldObjects(this RowObject rowObject, List? excludedFieldNumbers) + { + if (rowObject == null || rowObject.Fields == null) + return rowObject; + + var excluded = excludedFieldNumbers ?? new List(); + foreach (var field in rowObject.Fields.Where(f => !excluded.Contains(f.FieldNumber))) + { + field.Disable(); + } + + if (rowObject.RowAction == "") + rowObject.RowAction = "EDIT"; + + return rowObject; + } + + /// + /// Enables all instances in a . + /// + /// The RowObject to modify. + /// The modified RowObject. + public static RowObject? EnableAllFieldObjects(this RowObject rowObject) + { + return EnableAllFieldObjects(rowObject, null); + } + + /// + /// Enables all instances in a , except for the field numbers specified in the exclusion list. + /// + /// The RowObject to modify. + /// The field numbers to exclude from enabling. + /// The modified RowObject. + public static RowObject? EnableAllFieldObjects(this RowObject rowObject, List? excludedFieldNumbers) + { + if (rowObject == null || rowObject.Fields == null) + return rowObject; + + var excluded = excludedFieldNumbers ?? new List(); + foreach (var field in rowObject.Fields.Where(f => !excluded.Contains(f.FieldNumber))) + { + field.Enable(); + } + + if (rowObject.RowAction == "") + rowObject.RowAction = "EDIT"; + + return rowObject; + } + + /// + /// Locks all instances in a . + /// + /// The RowObject to modify. + /// The modified RowObject. + public static RowObject? LockAllFieldObjects(this RowObject rowObject) + { + return LockAllFieldObjects(rowObject, null); + } + + /// + /// Locks all instances in a , except for the field numbers specified in the exclusion list. + /// + /// The RowObject to modify. + /// The field numbers to exclude from locking. + /// The modified RowObject. + public static RowObject? LockAllFieldObjects(this RowObject rowObject, List? excludedFieldNumbers) + { + if (rowObject == null || rowObject.Fields == null) + return rowObject; + + var excluded = excludedFieldNumbers ?? new List(); + foreach (var field in rowObject.Fields.Where(f => !excluded.Contains(f.FieldNumber))) + { + field.Lock(); + } + + if (rowObject.RowAction == "") + rowObject.RowAction = "EDIT"; + + return rowObject; + } + + /// + /// Unlocks all instances in a . + /// + /// The RowObject to modify. + /// The modified RowObject. + public static RowObject? UnlockAllFieldObjects(this RowObject rowObject) + { + return UnlockAllFieldObjects(rowObject, null); + } + + /// + /// Unlocks all instances in a , except for the field numbers specified in the exclusion list. + /// + /// The RowObject to modify. + /// The field numbers to exclude from unlocking. + /// The modified RowObject. + public static RowObject? UnlockAllFieldObjects(this RowObject rowObject, List? excludedFieldNumbers) + { + if (rowObject == null || rowObject.Fields == null) + return rowObject; + + var excluded = excludedFieldNumbers ?? new List(); + foreach (var field in rowObject.Fields.Where(f => !excluded.Contains(f.FieldNumber))) + { + field.Unlock(); + } + + if (rowObject.RowAction == "") + rowObject.RowAction = "EDIT"; + + return rowObject; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Validators/FieldObjectValidators.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Validators/FieldObjectValidators.cs new file mode 100644 index 00000000..c926f663 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Validators/FieldObjectValidators.cs @@ -0,0 +1,85 @@ +using System; + +namespace RarelySimple.AvatarScriptLink.Objects.Helpers.Validators +{ + /// + /// Provides extension methods for validating instances. + /// + public static class FieldObjectValidators + { + /// + /// Determines if a has a value. + /// + /// The FieldObject to validate. + /// True if the field has a non-empty value, false otherwise. + public static bool HasValue(this FieldObject fieldObject) + { + return !string.IsNullOrEmpty(fieldObject?.FieldValue); + } + + /// + /// Determines if a has an empty or null value. + /// + /// The FieldObject to validate. + /// True if the field has an empty or null value, false otherwise. + public static bool IsEmpty(this FieldObject fieldObject) + { + return string.IsNullOrEmpty(fieldObject?.FieldValue); + } + + /// + /// Determines if a matches a specific value. + /// + /// The FieldObject to validate. + /// The value to compare. + /// True if the field value matches the provided value, false otherwise. + public static bool ValueEquals(this FieldObject fieldObject, string value) + { + return fieldObject?.FieldValue == value; + } + + /// + /// Determines if a value matches a value (case-insensitive). + /// + /// The FieldObject to validate. + /// The value to compare. + /// True if the field value matches the provided value (case-insensitive), false otherwise. + public static bool ValueEqualsIgnoreCase(this FieldObject fieldObject, string value) + { + return string.Equals(fieldObject?.FieldValue, value, StringComparison.OrdinalIgnoreCase); + } + + /// + /// Determines if a value contains a specific substring. + /// + /// The FieldObject to validate. + /// The substring to search for. + /// True if the field value contains the substring, false otherwise. + public static bool ValueContains(this FieldObject fieldObject, string substring) + { + return fieldObject?.FieldValue?.Contains(substring) == true; + } + + /// + /// Determines if a value starts with a specific prefix. + /// + /// The FieldObject to validate. + /// The prefix to check for. + /// True if the field value starts with the prefix, false otherwise. + public static bool ValueStartsWith(this FieldObject fieldObject, string prefix) + { + return fieldObject?.FieldValue?.StartsWith(prefix) == true; + } + + /// + /// Determines if a value ends with a specific suffix. + /// + /// The FieldObject to validate. + /// The suffix to check for. + /// True if the field value ends with the suffix, false otherwise. + public static bool ValueEndsWith(this FieldObject fieldObject, string suffix) + { + return fieldObject?.FieldValue?.EndsWith(suffix) == true; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Validators/FormObjectValidators.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Validators/FormObjectValidators.cs new file mode 100644 index 00000000..12189bcd --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Helpers/Validators/FormObjectValidators.cs @@ -0,0 +1,67 @@ +using System.Linq; + +namespace RarelySimple.AvatarScriptLink.Objects.Helpers.Validators +{ + /// + /// Provides extension methods for validating instances. + /// + public static class FormObjectValidators + { + /// + /// Determines if a has a specific field by field number. + /// + /// The FormObject to validate. + /// The field number to search for. + /// True if the form contains a field with the specified field number, false otherwise. + public static bool HasField(this FormObject formObject, string fieldNumber) + { + if (formObject?.HasCurrentRow() == true) + { + return formObject.CurrentRow.Fields.Any(f => f.FieldNumber == fieldNumber); + } + return false; + } + + /// + /// Determines if a has any rows. + /// + /// The FormObject to validate. + /// True if the form has at least one row (current or other), false otherwise. + public static bool HasAnyRows(this FormObject formObject) + { + return formObject?.HasCurrentRow() == true || formObject?.HasOtherRows() == true; + } + + /// + /// Determines if a is empty (no rows or fields). + /// + /// The FormObject to validate. + /// True if the form has no rows, false otherwise. + public static bool IsEmpty(this FormObject formObject) + { + return !formObject?.HasAnyRows() == true; + } + + /// + /// Gets the count of total fields across all rows in a . + /// + /// The FormObject to query. + /// The total number of fields across all rows. + public static int GetTotalFieldCount(this FormObject formObject) + { + int count = 0; + + if (formObject?.HasCurrentRow() == true) + { + count += formObject.CurrentRow.GetFieldCount(); + } + + if (formObject?.HasOtherRows() == true) + { + count += formObject.OtherRows.Sum(row => row?.GetFieldCount() ?? 0); + } + + return count; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/FieldObjectTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/FieldObjectTests.cs index 3ac1fb7d..2558e0e4 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/FieldObjectTests.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/FieldObjectTests.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; namespace RarelySimple.AvatarScriptLink.Objects.Tests { @@ -161,11 +161,11 @@ public void FieldObjectEqualsMethodEmptyFieldsIsTrue() { FieldObject fieldObject1 = new() { - Enabled = "1", - FieldNumber = "12345.0", - FieldValue = "abcdef", - Lock = "0", - Required = "1" + Enabled = string.Empty, + FieldNumber = string.Empty, + FieldValue = string.Empty, + Lock = string.Empty, + Required = string.Empty }; FieldObject fieldObject2 = fieldObject1.Clone(); Assert.IsTrue(fieldObject1.Equals(fieldObject2)); @@ -334,5 +334,159 @@ public void FieldObjectInitializeNotNull() { Assert.IsNotNull(FieldObject.Initialize()); } + + #region Boolean Helper Tests + + [TestMethod] + public void TestFieldObject_IsEnabled_WhenEnabledIs1() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.Enabled = "1"; + Assert.IsTrue(fieldObject.IsEnabled()); + } + + [TestMethod] + public void TestFieldObject_IsEnabled_WhenEnabledIs0() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.Enabled = "0"; + Assert.IsFalse(fieldObject.IsEnabled()); + } + + [TestMethod] + public void TestFieldObject_IsEnabled_WhenEnabledIsEmpty() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.Enabled = string.Empty; + Assert.IsFalse(fieldObject.IsEnabled()); + } + + [TestMethod] + public void TestFieldObject_IsLocked_WhenLockIs1() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.Lock = "1"; + Assert.IsTrue(fieldObject.IsLocked()); + } + + [TestMethod] + public void TestFieldObject_IsLocked_WhenLockIs0() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.Lock = "0"; + Assert.IsFalse(fieldObject.IsLocked()); + } + + [TestMethod] + public void TestFieldObject_IsLocked_WhenLockIsEmpty() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.Lock = string.Empty; + Assert.IsFalse(fieldObject.IsLocked()); + } + + [TestMethod] + public void TestFieldObject_IsRequired_WhenRequiredIs1() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.Required = "1"; + Assert.IsTrue(fieldObject.IsRequired()); + } + + [TestMethod] + public void TestFieldObject_IsRequired_WhenRequiredIs0() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.Required = "0"; + Assert.IsFalse(fieldObject.IsRequired()); + } + + [TestMethod] + public void TestFieldObject_IsRequired_WhenRequiredIsEmpty() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.Required = string.Empty; + Assert.IsFalse(fieldObject.IsRequired()); + } + + [TestMethod] + public void TestFieldObject_SetEnabled_WithTrue() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.SetEnabled(true); + Assert.AreEqual("1", fieldObject.Enabled); + } + + [TestMethod] + public void TestFieldObject_SetEnabled_WithFalse() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.SetEnabled(false); + Assert.AreEqual("0", fieldObject.Enabled); + } + + [TestMethod] + public void TestFieldObject_SetLocked_WithTrue() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.SetLocked(true); + Assert.AreEqual("1", fieldObject.Lock); + } + + [TestMethod] + public void TestFieldObject_SetLocked_WithFalse() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.SetLocked(false); + Assert.AreEqual("0", fieldObject.Lock); + } + + [TestMethod] + public void TestFieldObject_SetRequired_WithTrue() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.SetRequired(true); + Assert.AreEqual("1", fieldObject.Required); + } + + [TestMethod] + public void TestFieldObject_SetRequired_WithFalse() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.SetRequired(false); + Assert.AreEqual("0", fieldObject.Required); + } + + [TestMethod] + public void TestFieldObject_BooleanHelpersRoundTrip_Enabled() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.SetEnabled(true); + Assert.IsTrue(fieldObject.IsEnabled()); + fieldObject.SetEnabled(false); + Assert.IsFalse(fieldObject.IsEnabled()); + } + + [TestMethod] + public void TestFieldObject_BooleanHelpersRoundTrip_Locked() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.SetLocked(true); + Assert.IsTrue(fieldObject.IsLocked()); + fieldObject.SetLocked(false); + Assert.IsFalse(fieldObject.IsLocked()); + } + + [TestMethod] + public void TestFieldObject_BooleanHelpersRoundTrip_Required() + { + var fieldObject = FieldObject.Initialize(); + fieldObject.SetRequired(true); + Assert.IsTrue(fieldObject.IsRequired()); + fieldObject.SetRequired(false); + Assert.IsFalse(fieldObject.IsRequired()); + } + + #endregion } } diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/FormObjectTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/FormObjectTests.cs index 8f65c864..0298436e 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/FormObjectTests.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/FormObjectTests.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; namespace RarelySimple.AvatarScriptLink.Objects.Tests { @@ -230,5 +230,49 @@ public void FormObjectGetHashCodeCloneAreNotEqual() formObject2.MultipleIteration = false; Assert.AreNotEqual(formObject1.GetHashCode(), formObject2.GetHashCode()); } + + #region Collection Presence Helper Tests + + [TestMethod] + public void TestFormObject_HasOtherRows_WhenEmpty() + { + var formObject = FormObject.Initialize(); + Assert.IsFalse(formObject.HasOtherRows()); + } + + [TestMethod] + public void TestFormObject_HasOtherRows_WhenNotEmpty() + { + var formObject = FormObject.Initialize(); + formObject.OtherRows.Add(RowObject.Initialize()); + Assert.IsTrue(formObject.HasOtherRows()); + } + + [TestMethod] + public void TestFormObject_HasOtherRows_WhenMultipleRows() + { + var formObject = FormObject.Initialize(); + formObject.OtherRows.Add(RowObject.Initialize()); + formObject.OtherRows.Add(RowObject.Initialize()); + Assert.IsTrue(formObject.HasOtherRows()); + } + + [TestMethod] + public void TestFormObject_HasCurrentRow_WhenNull() + { + var formObject = FormObject.Initialize(); + formObject.CurrentRow = null; + Assert.IsFalse(formObject.HasCurrentRow()); + } + + [TestMethod] + public void TestFormObject_HasCurrentRow_WhenSet() + { + var formObject = FormObject.Initialize(); + formObject.CurrentRow = RowObject.Initialize(); + Assert.IsTrue(formObject.HasCurrentRow()); + } + + #endregion } } \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObject2015Tests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObject2015Tests.cs index 732625bc..fa4ca236 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObject2015Tests.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObject2015Tests.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; namespace RarelySimple.AvatarScriptLink.Objects.Tests { @@ -371,5 +371,33 @@ public void OptionObject2015GetHashCodeAreNotEqual() optionObject2.ErrorMesg = "modified"; Assert.AreNotEqual(optionObject1.GetHashCode(), optionObject2.GetHashCode()); } + + #region Collection Presence Helper Tests + + [TestMethod] + public void TestOptionObject2015_HasForms_WhenEmpty() + { + var optionObject = OptionObject2015.Initialize(); + Assert.IsFalse(optionObject.HasForms()); + } + + [TestMethod] + public void TestOptionObject2015_HasForms_WhenNotEmpty() + { + var optionObject = OptionObject2015.Initialize(); + optionObject.Forms.Add(FormObject.Initialize()); + Assert.IsTrue(optionObject.HasForms()); + } + + [TestMethod] + public void TestOptionObject2015_HasForms_WhenMultipleForms() + { + var optionObject = OptionObject2015.Initialize(); + optionObject.Forms.Add(FormObject.Initialize()); + optionObject.Forms.Add(FormObject.Initialize()); + Assert.IsTrue(optionObject.HasForms()); + } + + #endregion } } \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObject2Tests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObject2Tests.cs index 410f390b..7af1fd87 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObject2Tests.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObject2Tests.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; namespace RarelySimple.AvatarScriptLink.Objects.Tests { @@ -357,5 +357,33 @@ public void OptionObject2GetHashCodeAreNotEqual() optionObject2.ErrorMesg = "modified"; Assert.AreNotEqual(optionObject1.GetHashCode(), optionObject2.GetHashCode()); } + + #region Collection Presence Helper Tests + + [TestMethod] + public void TestOptionObject2_HasForms_WhenEmpty() + { + var optionObject = OptionObject2.Initialize(); + Assert.IsFalse(optionObject.HasForms()); + } + + [TestMethod] + public void TestOptionObject2_HasForms_WhenNotEmpty() + { + var optionObject = OptionObject2.Initialize(); + optionObject.Forms.Add(FormObject.Initialize()); + Assert.IsTrue(optionObject.HasForms()); + } + + [TestMethod] + public void TestOptionObject2_HasForms_WhenMultipleForms() + { + var optionObject = OptionObject2.Initialize(); + optionObject.Forms.Add(FormObject.Initialize()); + optionObject.Forms.Add(FormObject.Initialize()); + Assert.IsTrue(optionObject.HasForms()); + } + + #endregion } } \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObjectTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObjectTests.cs index 56315558..0539d534 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObjectTests.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/OptionObjectTests.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; namespace RarelySimple.AvatarScriptLink.Objects.Tests { @@ -311,5 +311,33 @@ public void OptionObjectGetHashCodeAreNotEqual() optionObject2.ErrorMesg = "modified"; Assert.AreNotEqual(optionObject1.GetHashCode(), optionObject2.GetHashCode()); } + + #region Collection Presence Helper Tests + + [TestMethod] + public void TestOptionObject_HasForms_WhenEmpty() + { + var optionObject = OptionObject.Initialize(); + Assert.IsFalse(optionObject.HasForms()); + } + + [TestMethod] + public void TestOptionObject_HasForms_WhenNotEmpty() + { + var optionObject = OptionObject.Initialize(); + optionObject.Forms.Add(FormObject.Initialize()); + Assert.IsTrue(optionObject.HasForms()); + } + + [TestMethod] + public void TestOptionObject_HasForms_WhenMultipleForms() + { + var optionObject = OptionObject.Initialize(); + optionObject.Forms.Add(FormObject.Initialize()); + optionObject.Forms.Add(FormObject.Initialize()); + Assert.IsTrue(optionObject.HasForms()); + } + + #endregion } } \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/RowObjectTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/RowObjectTests.cs index 01e15b60..ab106ee7 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/RowObjectTests.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Tests/RowObjectTests.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; namespace RarelySimple.AvatarScriptLink.Objects.Tests { @@ -232,5 +232,33 @@ public void RowObjectGetHashCodeAreNotEqual() rowObject2.RowAction = "EDIT"; Assert.AreNotEqual(rowObject1.GetHashCode(), rowObject2.GetHashCode()); } + + #region Collection Presence Helper Tests + + [TestMethod] + public void TestRowObject_HasFields_WhenEmpty() + { + var rowObject = RowObject.Initialize(); + Assert.IsFalse(rowObject.HasFields()); + } + + [TestMethod] + public void TestRowObject_HasFields_WhenNotEmpty() + { + var rowObject = RowObject.Initialize(); + rowObject.Fields.Add(FieldObject.Initialize()); + Assert.IsTrue(rowObject.HasFields()); + } + + [TestMethod] + public void TestRowObject_HasFields_WhenMultipleFields() + { + var rowObject = RowObject.Initialize(); + rowObject.Fields.Add(FieldObject.Initialize()); + rowObject.Fields.Add(FieldObject.Initialize()); + Assert.IsTrue(rowObject.HasFields()); + } + + #endregion } } \ No newline at end of file diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators.Tests/GlobalUsings.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators.Tests/GlobalUsings.cs new file mode 100644 index 00000000..4ef26e80 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators.Tests/GlobalUsings.cs @@ -0,0 +1,3 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; +global using RarelySimple.AvatarScriptLink.Objects; +global using RarelySimple.AvatarScriptLink.Objects.Validators; diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators.Tests/RarelySimple.AvatarScriptLink.Objects.Validators.Tests.csproj b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators.Tests/RarelySimple.AvatarScriptLink.Objects.Validators.Tests.csproj new file mode 100644 index 00000000..a5b76bf9 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators.Tests/RarelySimple.AvatarScriptLink.Objects.Validators.Tests.csproj @@ -0,0 +1,26 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators.Tests/ResponseValidatorTests.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators.Tests/ResponseValidatorTests.cs new file mode 100644 index 00000000..d702b287 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators.Tests/ResponseValidatorTests.cs @@ -0,0 +1,244 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Validators.Tests +{ + [TestClass] + public class OptionObjectResponseValidatorsTests + { + [TestMethod] + public void ValidateResponse_ReturnsError_WhenOptionObjectIsNull() + { + // Arrange + OptionObject? optionObject = null; + + // Act + ResponseValidationResult result = optionObject.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "OptionObject is null."); + } + + [TestMethod] + public void ValidateResponse_ReturnsError_WhenEntityIdIsMissing() + { + // Arrange + var optionObject = new OptionObject { ErrorCode = 0, ErrorMesg = string.Empty }; + + // Act + ResponseValidationResult result = optionObject.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "EntityID is required."); + } + + [TestMethod] + public void ValidateResponse_ReturnsError_WhenErrorCodeIsInvalid() + { + // Arrange + var optionObject = new OptionObject { EntityID = "PATID", ErrorCode = 7, ErrorMesg = string.Empty }; + + // Act + ResponseValidationResult result = optionObject.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "ErrorCode must be between 0 and 6."); + } + + [TestMethod] + public void ValidateResponse_ReturnsError_WhenErrorCodeIsNonInteger() + { + // Arrange + var optionObject = new OptionObject { EntityID = "PATID", ErrorCode = 2.5, ErrorMesg = "Message" }; + + // Act + ResponseValidationResult result = optionObject.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "ErrorCode must be an integer between 0 and 6."); + } + + [TestMethod] + public void ValidateResponse_ReturnsError_WhenErrorMessagePresentForSuccess() + { + // Arrange + var optionObject = new OptionObject { EntityID = "PATID", ErrorCode = 0, ErrorMesg = "Unexpected" }; + + // Act + ResponseValidationResult result = optionObject.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "ErrorMesg must be empty when ErrorCode is 0."); + } + + [TestMethod] + public void ValidateResponse_ReturnsError_WhenErrorMessageMissingForError() + { + // Arrange + var optionObject = new OptionObject { EntityID = "PATID", ErrorCode = 3, ErrorMesg = string.Empty }; + + // Act + ResponseValidationResult result = optionObject.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "ErrorMesg is required when ErrorCode is between 1 and 4."); + } + + [TestMethod] + public void ValidateResponse_ReturnsError_WhenOpenUrlMessageIsInvalid() + { + // Arrange + var optionObject = new OptionObject { EntityID = "PATID", ErrorCode = 5, ErrorMesg = "not-a-url" }; + + // Act + ResponseValidationResult result = optionObject.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "ErrorMesg must be a valid absolute URL when ErrorCode is 5."); + } + + [TestMethod] + public void ValidateResponse_ReturnsError_WhenOpenFormMessageIsInvalid() + { + // Arrange + var optionObject = new OptionObject { EntityID = "PATID", ErrorCode = 6, ErrorMesg = "invalid form" }; + + // Act + ResponseValidationResult result = optionObject.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "ErrorMesg must be a valid OpenForm string when ErrorCode is 6."); + } + + [TestMethod] + public void ValidateResponse_ReturnsSuccess_WhenResponseIsValid() + { + // Arrange + var optionObject = new OptionObject { EntityID = "PATID", ErrorCode = 1, ErrorMesg = "Message" }; + + // Act + ResponseValidationResult result = optionObject.ValidateResponse(); + + // Assert + Assert.IsTrue(result.IsValid); + Assert.AreEqual(0, result.Errors.Count); + } + + [TestMethod] + public void IsValidResponse_ReturnsTrue_ForValidOptionObject2() + { + // Arrange + var optionObject = new OptionObject2 { EntityID = "PATID", ErrorCode = 0, ErrorMesg = string.Empty }; + + // Act + bool result = optionObject.IsValidResponse(); + + // Assert + Assert.IsTrue(result); + } + + [TestMethod] + public void ValidateResponsePayload_ReturnsErrors_ForInvalidForm() + { + // Arrange + var optionObject = new OptionObject { EntityID = "PATID", ErrorCode = 0, ErrorMesg = string.Empty }; + optionObject.Forms.Add(new FormObject()); + + // Act + ResponseValidationResult result = optionObject.ValidateResponsePayload(); + + // Assert + Assert.IsFalse(result.IsValid); + Assert.IsTrue(result.Errors.Any(error => error.Contains("Forms[0]: FormId is required."))); + } + } + + [TestClass] + public class FormObjectResponseValidatorsTests + { + [TestMethod] + public void ValidateResponse_ReturnsError_WhenMultipleIterationFalseAndOtherRowsPresent() + { + // Arrange + var form = new FormObject { FormId = "FORM1", MultipleIteration = false }; + form.OtherRows.Add(new RowObject { RowId = "1" }); + + // Act + ResponseValidationResult result = form.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "OtherRows must be empty when MultipleIteration is false."); + } + } + + [TestClass] + public class RowObjectResponseValidatorsTests + { + [TestMethod] + public void ValidateResponse_ReturnsError_WhenRowActionMissingWithFields() + { + // Arrange + var row = new RowObject { RowId = "1", RowAction = string.Empty }; + row.Fields.Add(new FieldObject { FieldNumber = "100" }); + + // Act + ResponseValidationResult result = row.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "RowAction is required when row contains fields."); + } + + [TestMethod] + public void ValidateResponse_ReturnsError_WhenRowActionInvalid() + { + // Arrange + var row = new RowObject { RowId = "1", RowAction = "INVALID" }; + + // Act + ResponseValidationResult result = row.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "RowAction must be ADD, EDIT, DELETE, or empty."); + } + } + + [TestClass] + public class FieldObjectResponseValidatorsTests + { + [TestMethod] + public void ValidateResponse_ReturnsError_WhenFieldNumberMissing() + { + // Arrange + var field = new FieldObject { FieldNumber = "" }; + + // Act + ResponseValidationResult result = field.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "FieldNumber is required."); + } + + [TestMethod] + public void ValidateResponse_ReturnsError_WhenFlagIsInvalid() + { + // Arrange + var field = new FieldObject { FieldNumber = "100", Enabled = "X" }; + + // Act + ResponseValidationResult result = field.ValidateResponse(); + + // Assert + Assert.IsFalse(result.IsValid); + CollectionAssert.Contains(result.Errors.ToList(), "Enabled must be \"0\" or \"1\" when set."); + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/FieldObjectResponseValidators.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/FieldObjectResponseValidators.cs new file mode 100644 index 00000000..94035bfc --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/FieldObjectResponseValidators.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; + +namespace RarelySimple.AvatarScriptLink.Objects.Validators +{ + /// + /// Provides response validation extensions for instances. + /// + public static class FieldObjectResponseValidators + { + /// + /// Validates a response FieldObject. + /// + /// The field object to validate. + /// The response validation result. + public static ResponseValidationResult ValidateResponse(this FieldObject? fieldObject) + { + var errors = new List(); + + if (fieldObject == null) + { + errors.Add("FieldObject is null."); + return new ResponseValidationResult(errors); + } + + if (string.IsNullOrWhiteSpace(fieldObject.FieldNumber)) + { + errors.Add("FieldNumber is required."); + } + + ValidateFlag(fieldObject.Enabled, "Enabled", errors); + ValidateFlag(fieldObject.Lock, "Lock", errors); + ValidateFlag(fieldObject.Required, "Required", errors); + + return new ResponseValidationResult(errors); + } + + private static void ValidateFlag(string value, string name, List errors) + { + if (!string.IsNullOrEmpty(value) && value != "0" && value != "1") + { + errors.Add($"{name} must be \"0\" or \"1\" when set."); + } + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/FormObjectResponseValidators.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/FormObjectResponseValidators.cs new file mode 100644 index 00000000..9a42ff8e --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/FormObjectResponseValidators.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; + +namespace RarelySimple.AvatarScriptLink.Objects.Validators +{ + /// + /// Provides response validation extensions for instances. + /// + public static class FormObjectResponseValidators + { + /// + /// Validates a response FormObject. + /// + /// The form object to validate. + /// The response validation result. + public static ResponseValidationResult ValidateResponse(this FormObject? formObject) + { + var errors = new List(); + + if (formObject == null) + { + errors.Add("FormObject is null."); + return new ResponseValidationResult(errors); + } + + if (string.IsNullOrWhiteSpace(formObject.FormId)) + { + errors.Add("FormId is required."); + } + + if (formObject.OtherRows == null) + { + errors.Add("OtherRows collection must not be null."); + return new ResponseValidationResult(errors); + } + + if (!formObject.MultipleIteration && formObject.OtherRows.Count > 0) + { + errors.Add("OtherRows must be empty when MultipleIteration is false."); + } + + if (formObject.CurrentRow != null) + { + var currentRowResult = formObject.CurrentRow.ValidateResponse(); + foreach (var error in currentRowResult.Errors) + { + errors.Add($"CurrentRow: {error}"); + } + } + + for (int i = 0; i < formObject.OtherRows.Count; i++) + { + var rowResult = formObject.OtherRows[i].ValidateResponse(); + foreach (var error in rowResult.Errors) + { + errors.Add($"OtherRows[{i}]: {error}"); + } + } + + return new ResponseValidationResult(errors); + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/OptionObjectResponseValidators.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/OptionObjectResponseValidators.cs new file mode 100644 index 00000000..a10766a3 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/OptionObjectResponseValidators.cs @@ -0,0 +1,198 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; + +namespace RarelySimple.AvatarScriptLink.Objects.Validators +{ + /// + /// Provides response validation extensions for OptionObject variants. + /// + public static class OptionObjectResponseValidators + { + /// + /// Validates a response OptionObject. + /// + /// The option object to validate. + /// The response validation result. + public static ResponseValidationResult ValidateResponse(this IOptionObject? optionObject) + { + var errors = new List(); + + if (optionObject == null) + { + errors.Add("OptionObject is null."); + return new ResponseValidationResult(errors); + } + + if (string.IsNullOrWhiteSpace(optionObject.EntityID)) + { + errors.Add("EntityID is required."); + } + + ValidateErrorCode(optionObject.ErrorCode, errors); + ValidateErrorMessage(optionObject.ErrorCode, optionObject.ErrorMesg ?? string.Empty, errors); + + return new ResponseValidationResult(errors); + } + + /// + /// Determines whether a response OptionObject is valid. + /// + /// The option object to validate. + /// True if valid, false otherwise. + public static bool IsValidResponse(this IOptionObject? optionObject) + { + return optionObject.ValidateResponse().IsValid; + } + + /// + /// Validates a response OptionObject including payload forms, rows, and fields. + /// + /// The option object to validate. + /// The response validation result. + public static ResponseValidationResult ValidateResponsePayload(this IOptionObject? optionObject) + { + var errors = new List(); + var baseResult = optionObject.ValidateResponse(); + errors.AddRange(baseResult.Errors); + + if (optionObject == null) + { + return new ResponseValidationResult(errors); + } + + if (optionObject.Forms == null) + { + errors.Add("Forms collection must not be null."); + return new ResponseValidationResult(errors); + } + + for (int i = 0; i < optionObject.Forms.Count; i++) + { + var form = optionObject.Forms[i]; + if (form == null) + { + errors.Add($"Forms[{i}] is null."); + continue; + } + + var formResult = form.ValidateResponse(); + foreach (var error in formResult.Errors) + { + errors.Add($"Forms[{i}]: {error}"); + } + } + + return new ResponseValidationResult(errors); + } + + /// + /// Determines whether a response OptionObject payload is valid. + /// + /// The option object to validate. + /// True if valid, false otherwise. + public static bool IsValidResponsePayload(this IOptionObject? optionObject) + { + return optionObject.ValidateResponsePayload().IsValid; + } + + private static void ValidateErrorCode(double errorCode, List errors) + { + if (double.IsNaN(errorCode) || double.IsInfinity(errorCode)) + { + errors.Add("ErrorCode must be a finite number between 0 and 6."); + return; + } + + if (errorCode < 0 || errorCode > 6) + { + errors.Add("ErrorCode must be between 0 and 6."); + return; + } + + double rounded = Math.Round(errorCode, 0, MidpointRounding.AwayFromZero); + if (Math.Abs(errorCode - rounded) > 1e-9) + { + errors.Add("ErrorCode must be an integer between 0 and 6."); + } + } + + private static void ValidateErrorMessage(double errorCode, string errorMessage, List errors) + { + int normalizedCode = NormalizeErrorCode(errorCode); + if (normalizedCode == -1) + { + return; + } + + if (normalizedCode == 0 && !string.IsNullOrEmpty(errorMessage)) + { + errors.Add("ErrorMesg must be empty when ErrorCode is 0."); + return; + } + + if (normalizedCode >= 1 && normalizedCode <= 4 && string.IsNullOrWhiteSpace(errorMessage)) + { + errors.Add("ErrorMesg is required when ErrorCode is between 1 and 4."); + return; + } + + if (normalizedCode == 5 && !IsValidUrl(errorMessage)) + { + errors.Add("ErrorMesg must be a valid absolute URL when ErrorCode is 5."); + return; + } + + if (normalizedCode == 6 && !IsValidOpenFormString(errorMessage)) + { + errors.Add("ErrorMesg must be a valid OpenForm string when ErrorCode is 6."); + } + } + + private static int NormalizeErrorCode(double errorCode) + { + if (double.IsNaN(errorCode) || double.IsInfinity(errorCode)) + { + return -1; + } + + int code = (int)Math.Round(errorCode, 0, MidpointRounding.AwayFromZero); + if (code < 0 || code > 6) + { + return -1; + } + + return code; + } + + private static bool IsValidUrl(string value) + { + return !string.IsNullOrWhiteSpace(value) && Uri.IsWellFormedUriString(value, UriKind.Absolute); + } + + private static bool IsValidOpenFormString(string value) + { + if (string.IsNullOrWhiteSpace(value)) + { + return false; + } + + return Regex.IsMatch(value, RegexPatterns.FullPattern, RegexOptions.None, TimeSpan.FromMilliseconds(100)); + } + + private static class RegexPatterns + { + private const string ModulePrefix = @"(\[(PM|CWS|MSO)\])?"; + private const string ModuleForm = @"[A-Z]+[0-9]+"; + private const string RadplusForm = @"RADplus_[A-Za-z]+[0-9]+"; + private const string Form = @"(?:" + ModuleForm + "|" + RadplusForm + ")"; + private const string PrefixedForm = @"(\s*)" + ModulePrefix + Form; + private const string FormList = PrefixedForm + @"((\s*)&(\s*)" + ModulePrefix + Form + ")*"; + private const string Message = @"((\s*)\|(\s*)([^\|\t\n\r])*)?"; + private const string PatientId = @"((\s*)\|(\s*)\d+)?"; + private const string EpisodeNumber = @"((\s*)\|(\s*)([1-9][0-9]*)+|(\s*)\|(\s*))?"; + public const string FullPattern = "^" + FormList + Message + PatientId + EpisodeNumber + "$"; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/README.md b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/README.md new file mode 100644 index 00000000..ecceb828 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/README.md @@ -0,0 +1,51 @@ +# RarelySimple.AvatarScriptLink.Objects.Validators + +Extension methods for validating ScriptLink response objects. + +## Usage + +```csharp +using RarelySimple.AvatarScriptLink.Objects; +using RarelySimple.AvatarScriptLink.Objects.Validators; + +var option = new OptionObject { EntityID = "PATID123", ErrorCode = 0, ErrorMesg = string.Empty }; +var result = option.ValidateResponse(); + +if (!result.IsValid) +{ + foreach (var error in result.Errors) + { + // handle validation errors + } +} + +// Validate response payload structure +var form = new FormObject { FormId = "FORM1", MultipleIteration = true }; +var row = new RowObject { RowId = "1", RowAction = RowObject.RowActions.Edit }; +row.Fields.Add(new FieldObject { FieldNumber = "100", FieldValue = "value" }); +form.CurrentRow = row; +option.Forms.Add(form); + +var payloadResult = option.ValidateResponsePayload(); +if (!payloadResult.IsValid) +{ + foreach (var error in payloadResult.Errors) + { + // handle payload validation errors + } +} +``` + +## Features + +- Strict response validation for OptionObject variants +- Clear error messages for invalid response state + +## Dependencies + +- **RarelySimple.AvatarScriptLink.Objects** - Core object definitions +- .NET Standard 2.0+ + +## License + +MIT diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/RarelySimple.AvatarScriptLink.Objects.Validators.csproj b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/RarelySimple.AvatarScriptLink.Objects.Validators.csproj new file mode 100644 index 00000000..f0d89bfb --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/RarelySimple.AvatarScriptLink.Objects.Validators.csproj @@ -0,0 +1,45 @@ + + + + netstandard2.0 + 8.0 + enable + false + Scott Olson Jr + Rarely Simple + MIT + https://github.com/rarelysimple/RarelySimple.AvatarScriptLink + https://scriptlink.rarelysimple.com/ + git + Copyright © 2026 Scott Olson Jr + RarelySimple.AvatarScriptLink.Objects.Validators provides response validation helpers for ScriptLink objects. + en-US + true + ../RarelySimple.AvatarScriptLink.snk + ../RarelySimple.AvatarScriptLink.ruleset + RarelySimple.AvatarScriptLink.Objects.Validators + README.md + true + 2.0.0 + $(Version) + $(Version) + v + preview.0 + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/ResponseValidationResult.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/ResponseValidationResult.cs new file mode 100644 index 00000000..c9d8608d --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/ResponseValidationResult.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; + +namespace RarelySimple.AvatarScriptLink.Objects.Validators +{ + /// + /// Represents the result of response validation. + /// + public sealed class ResponseValidationResult + { + private readonly List errors; + + /// + /// Initializes a new instance of the class. + /// + /// The validation errors. + public ResponseValidationResult(List errors) + { + this.errors = errors ?? new List(); + } + + /// + /// Gets a value indicating whether the response is valid. + /// + public bool IsValid => errors.Count == 0; + + /// + /// Gets the validation errors. + /// + public IReadOnlyList Errors => errors; + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/RowObjectResponseValidators.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/RowObjectResponseValidators.cs new file mode 100644 index 00000000..7608b77b --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects.Validators/RowObjectResponseValidators.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; + +namespace RarelySimple.AvatarScriptLink.Objects.Validators +{ + /// + /// Provides response validation extensions for instances. + /// + public static class RowObjectResponseValidators + { + /// + /// Validates a response RowObject. + /// + /// The row object to validate. + /// The response validation result. + public static ResponseValidationResult ValidateResponse(this RowObject? rowObject) + { + var errors = new List(); + + if (rowObject == null) + { + errors.Add("RowObject is null."); + return new ResponseValidationResult(errors); + } + + if (string.IsNullOrWhiteSpace(rowObject.RowId)) + { + errors.Add("RowId is required."); + } + + if (!IsValidRowAction(rowObject.RowAction)) + { + errors.Add("RowAction must be ADD, EDIT, DELETE, or empty."); + } + + if (rowObject.Fields == null) + { + errors.Add("Fields collection must not be null."); + return new ResponseValidationResult(errors); + } + + if (rowObject.Fields.Count > 0 && string.IsNullOrEmpty(rowObject.RowAction)) + { + errors.Add("RowAction is required when row contains fields."); + } + + for (int i = 0; i < rowObject.Fields.Count; i++) + { + var fieldResult = rowObject.Fields[i].ValidateResponse(); + foreach (var error in fieldResult.Errors) + { + errors.Add($"Fields[{i}]: {error}"); + } + } + + return new ResponseValidationResult(errors); + } + + private static bool IsValidRowAction(string value) + { + return string.IsNullOrEmpty(value) || + value == RowObject.RowActions.Add || + value == RowObject.RowActions.Edit || + value == RowObject.RowActions.Delete; + } + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/FieldObjectBase.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/FieldObjectBase.cs new file mode 100644 index 00000000..1863f66b --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/FieldObjectBase.cs @@ -0,0 +1,126 @@ +using RarelySimple.AvatarScriptLink.Objects.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Utilities; + +namespace RarelySimple.AvatarScriptLink.Objects.Abstracts +{ + public class FieldObjectBase : ObjectBase, IFieldObject + { + /// + /// Gets or sets the Enabled property of a . + /// + /// + /// This property stores the enabled status as a string due to myAvatar SOAP serialization requirements. + /// For a more convenient boolean interface, use the method or method. + /// + /// The value is a : "1" (Enabled) or "0" (Disabled). + public string Enabled { get; set; } + /// + /// Gets or sets the FieldNumber property of a . + /// + /// The value is a representing the field number. This is typically a value like 12345.6 or 12345.67. + public string FieldNumber { get; set; } + /// + /// Gets or sets the FieldValue property of a . + /// + /// The value is a containing the value entered (or to be entered) in the field. + public string FieldValue { get; set; } + /// + /// Gets or sets the Lock property of a . + /// + /// + /// This property stores the lock status as a string due to myAvatar SOAP serialization requirements. + /// For a more convenient boolean interface, use the method or method. + /// + /// The value is a : "1" (Locked) or "0" (Unlocked). + public string Lock { get; set; } + /// + /// Gets or sets the Required property of a . + /// + /// + /// This property stores the required status as a string due to myAvatar SOAP serialization requirements. + /// For a more convenient boolean interface, use the method or method. + /// + /// The value is a : "1" (Required) or "0" (Optional). + public string Required { get; set; } + + #region Constructors + + /// + /// Creates an empty . + /// + protected FieldObjectBase() + { + Enabled = string.Empty; + FieldNumber = string.Empty; + FieldValue = string.Empty; + Lock = string.Empty; + Required = string.Empty; + } + + #endregion + + #region Boolean Helper Methods + + /// + /// Gets a value indicating whether the field is enabled. + /// + /// True if the Enabled property is "1", false otherwise. + /// + /// This method converts the string-based Enabled property to a boolean value for easier use in code. + /// Use this method instead of checking Enabled == "1" directly. + /// + public bool IsEnabled() => BooleanConversion.ToBoolean(Enabled); + + /// + /// Gets a value indicating whether the field is locked. + /// + /// True if the Lock property is "1", false otherwise. + /// + /// This method converts the string-based Lock property to a boolean value for easier use in code. + /// Use this method instead of checking Lock == "1" directly. + /// + public bool IsLocked() => BooleanConversion.ToBoolean(Lock); + + /// + /// Gets a value indicating whether the field is required. + /// + /// True if the Required property is "1", false otherwise. + /// + /// This method converts the string-based Required property to a boolean value for easier use in code. + /// Use this method instead of checking Required == "1" directly. + /// + public bool IsRequired() => BooleanConversion.ToBoolean(Required); + + /// + /// Sets the Enabled property based on the provided boolean value. + /// + /// True sets Enabled to "1", false sets it to "0". + /// + /// This method provides a convenient way to set the Enabled property using a boolean value. + /// Use this method instead of setting Enabled = value ? "1" : "0" directly. + /// + public void SetEnabled(bool value) => Enabled = BooleanConversion.ToAvatarBoolean(value); + + /// + /// Sets the Lock property based on the provided boolean value. + /// + /// True sets Lock to "1", false sets it to "0". + /// + /// This method provides a convenient way to set the Lock property using a boolean value. + /// Use this method instead of setting Lock = value ? "1" : "0" directly. + /// + public void SetLocked(bool value) => Lock = BooleanConversion.ToAvatarBoolean(value); + + /// + /// Sets the Required property based on the provided boolean value. + /// + /// True sets Required to "1", false sets it to "0". + /// + /// This method provides a convenient way to set the Required property using a boolean value. + /// Use this method instead of setting Required = value ? "1" : "0" directly. + /// + public void SetRequired(bool value) => Required = BooleanConversion.ToAvatarBoolean(value); + + #endregion + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/FormObjectBase.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/FormObjectBase.cs similarity index 54% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/FormObjectBase.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/FormObjectBase.cs index d22bd75a..42844d1e 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/FormObjectBase.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/FormObjectBase.cs @@ -1,7 +1,7 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; using System.Collections.Generic; -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts +namespace RarelySimple.AvatarScriptLink.Objects.Abstracts { public class FormObjectBase : ObjectBase, IFormObject { @@ -37,5 +37,29 @@ protected FormObjectBase() } #endregion + + #region Collection Presence Helpers + + /// + /// Gets a value indicating whether the OtherRows collection contains any elements. + /// + /// True if OtherRows is not null and contains at least one row, false otherwise. + /// + /// This method safely checks if there are any additional rows in the form. + /// Use this method before iterating over OtherRows to avoid null reference exceptions. + /// + public bool HasOtherRows() => OtherRows != null && OtherRows.Count > 0; + + /// + /// Gets a value indicating whether the CurrentRow is set. + /// + /// True if CurrentRow is not null, false otherwise. + /// + /// This method safely checks if the form has a current row set. + /// Use this method before accessing CurrentRow properties to avoid null reference exceptions. + /// + public bool HasCurrentRow() => CurrentRow != null; + + #endregion } } diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/ObjectBase.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/ObjectBase.cs similarity index 84% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/ObjectBase.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/ObjectBase.cs index e3e64009..f7a9fe30 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/ObjectBase.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/ObjectBase.cs @@ -1,6 +1,6 @@ using System; -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts +namespace RarelySimple.AvatarScriptLink.Objects.Abstracts { public abstract class ObjectBase : ICloneable { diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/OptionObject2015Base.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/OptionObject2015Base.cs similarity index 86% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/OptionObject2015Base.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/OptionObject2015Base.cs index 6ba6117d..d53520f3 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/OptionObject2015Base.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/OptionObject2015Base.cs @@ -1,7 +1,7 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; using System.Collections.Generic; -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts +namespace RarelySimple.AvatarScriptLink.Objects.Abstracts { public class OptionObject2015Base : ObjectBase, IOptionObject2015 { @@ -87,5 +87,19 @@ protected OptionObject2015Base() } #endregion + + #region Collection Presence Helpers + + /// + /// Gets a value indicating whether the Forms collection contains any elements. + /// + /// True if Forms is not null and contains at least one form, false otherwise. + /// + /// This method safely checks if there are any forms in the OptionObject. + /// Use this method before iterating over Forms to avoid null reference exceptions. + /// + public bool HasForms() => Forms != null && Forms.Count > 0; + + #endregion } } diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/OptionObject2Base.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/OptionObject2Base.cs similarity index 85% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/OptionObject2Base.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/OptionObject2Base.cs index 58cfea28..96824253 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/OptionObject2Base.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/OptionObject2Base.cs @@ -1,7 +1,7 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; using System.Collections.Generic; -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts +namespace RarelySimple.AvatarScriptLink.Objects.Abstracts { public class OptionObject2Base : ObjectBase, IOptionObject2 { @@ -82,5 +82,19 @@ protected OptionObject2Base() } #endregion + + #region Collection Presence Helpers + + /// + /// Gets a value indicating whether the Forms collection contains any elements. + /// + /// True if Forms is not null and contains at least one form, false otherwise. + /// + /// This method safely checks if there are any forms in the OptionObject. + /// Use this method before iterating over Forms to avoid null reference exceptions. + /// + public bool HasForms() => Forms != null && Forms.Count > 0; + + #endregion } } diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/OptionObjectBase.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/OptionObjectBase.cs similarity index 82% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/OptionObjectBase.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/OptionObjectBase.cs index f12ec5c8..9aac2aac 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/OptionObjectBase.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/OptionObjectBase.cs @@ -1,7 +1,7 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; using System.Collections.Generic; -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts +namespace RarelySimple.AvatarScriptLink.Objects.Abstracts { public class OptionObjectBase : ObjectBase, IOptionObject { @@ -67,5 +67,19 @@ protected OptionObjectBase() } #endregion + + #region Collection Presence Helpers + + /// + /// Gets a value indicating whether the Forms collection contains any elements. + /// + /// True if Forms is not null and contains at least one form, false otherwise. + /// + /// This method safely checks if there are any forms in the OptionObject. + /// Use this method before iterating over Forms to avoid null reference exceptions. + /// + public bool HasForms() => Forms != null && Forms.Count > 0; + + #endregion } } diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/RowObjectBase.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/RowObjectBase.cs similarity index 68% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/RowObjectBase.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/RowObjectBase.cs index e32d561c..69c1a0ad 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/RowObjectBase.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Abstracts/RowObjectBase.cs @@ -1,7 +1,7 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; +using RarelySimple.AvatarScriptLink.Objects.Interfaces; using System.Collections.Generic; -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts +namespace RarelySimple.AvatarScriptLink.Objects.Abstracts { public class RowObjectBase : ObjectBase, IRowObject { @@ -38,5 +38,19 @@ protected RowObjectBase() } #endregion + + #region Collection Presence Helpers + + /// + /// Gets a value indicating whether the Fields collection contains any elements. + /// + /// True if Fields is not null and contains at least one field, false otherwise. + /// + /// This method safely checks if there are any fields in the row. + /// Use this method before iterating over Fields to avoid null reference exceptions. + /// + public bool HasFields() => Fields != null && Fields.Count > 0; + + #endregion } } diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/FieldObjectBase.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/FieldObjectBase.cs deleted file mode 100644 index 204c7ea7..00000000 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Abstracts/FieldObjectBase.cs +++ /dev/null @@ -1,49 +0,0 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces; - -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts -{ - public class FieldObjectBase : ObjectBase, IFieldObject - { - /// - /// Gets or sets the Enabled property of a . - /// - /// The value is a . 0 = Disabled. 1 = Enabled. - public string Enabled { get; set; } - /// - /// Gets or sets the FieldNumber property of a . - /// - /// The value is a representing the field number. This is typically a value like 12345.6 or 12345.67. - public string FieldNumber { get; set; } - /// - /// Gets or sets the FieldValue property of a . - /// - /// The value is a containing the value entered (or to be entered) in the field. - public string FieldValue { get; set; } - /// - /// Gets or sets the Lock property of a . - /// - /// The value is a . 0 = Unlocked. 1 = Locked. - public string Lock { get; set; } - /// - /// Gets or sets the Required property of a . - /// - /// The value is a . 0 = Not required. 1 = Required. - public string Required { get; set; } - - #region Constructors - - /// - /// Creates an empty . - /// - protected FieldObjectBase() - { - Enabled = string.Empty; - FieldNumber = string.Empty; - FieldValue = string.Empty; - Lock = string.Empty; - Required = string.Empty; - } - - #endregion - } -} diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/FieldObject.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/FieldObject.cs index e28354ca..2adb85de 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/FieldObject.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/FieldObject.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts; +using RarelySimple.AvatarScriptLink.Objects.Abstracts; using System; using System.Collections.Generic; using System.Linq; @@ -111,17 +111,29 @@ public static bool AreFieldsEqual(List list1, List lis #region Public Methods - public bool IsEnabled() + /// + /// Gets a value indicating whether the field is enabled. + /// + /// True if Enabled equals EnabledStatus.Enabled, false otherwise. + public new bool IsEnabled() { return Enabled == EnabledStatus.Enabled; } - public bool IsLocked() + /// + /// Gets a value indicating whether the field is locked. + /// + /// True if Lock equals LockStatus.Locked, false otherwise. + public new bool IsLocked() { return Lock == LockStatus.Locked; } - public bool IsRequired() + /// + /// Gets a value indicating whether the field is required. + /// + /// True if Required equals RequiredStatus.Required, false otherwise. + public new bool IsRequired() { return Required == RequiredStatus.Required; } diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/FormObject.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/FormObject.cs index 32a94092..f0d1046f 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/FormObject.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/FormObject.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts; +using RarelySimple.AvatarScriptLink.Objects.Abstracts; using System; using System.Collections.Generic; using System.Linq; diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IFieldObject.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IFieldObject.cs similarity index 77% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IFieldObject.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IFieldObject.cs index 5a6521f8..644cf142 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IFieldObject.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IFieldObject.cs @@ -1,4 +1,4 @@ -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces +namespace RarelySimple.AvatarScriptLink.Objects.Interfaces { public interface IFieldObject { diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IFormObject.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IFormObject.cs similarity index 79% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IFormObject.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IFormObject.cs index f16d0267..5fb00f85 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IFormObject.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IFormObject.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces +namespace RarelySimple.AvatarScriptLink.Objects.Interfaces { public interface IFormObject { diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IOptionObject.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IOptionObject.cs similarity index 87% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IOptionObject.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IOptionObject.cs index 52deced3..1f8722c2 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IOptionObject.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IOptionObject.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces +namespace RarelySimple.AvatarScriptLink.Objects.Interfaces { public interface IOptionObject { diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IOptionObject2.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IOptionObject2.cs similarity index 73% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IOptionObject2.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IOptionObject2.cs index b42917f0..b9ec9951 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IOptionObject2.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IOptionObject2.cs @@ -1,4 +1,4 @@ -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces +namespace RarelySimple.AvatarScriptLink.Objects.Interfaces { public interface IOptionObject2 : IOptionObject { diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IOptionObject2015.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IOptionObject2015.cs similarity index 61% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IOptionObject2015.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IOptionObject2015.cs index a69bb989..4a9fe3a1 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IOptionObject2015.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IOptionObject2015.cs @@ -1,4 +1,4 @@ -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces +namespace RarelySimple.AvatarScriptLink.Objects.Interfaces { public interface IOptionObject2015 : IOptionObject2 { diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IRowObject.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IRowObject.cs similarity index 78% rename from dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IRowObject.cs rename to dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IRowObject.cs index 9219b258..544b0392 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/Advanced/Interfaces/IRowObject.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Interfaces/IRowObject.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace RarelySimple.AvatarScriptLink.Objects.Advanced.Interfaces +namespace RarelySimple.AvatarScriptLink.Objects.Interfaces { public interface IRowObject { diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject.cs index 46c528fa..9dd171c9 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts; +using RarelySimple.AvatarScriptLink.Objects.Abstracts; using System; using System.Collections.Generic; using System.Linq; diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject2.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject2.cs index e8fdde70..67c82462 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject2.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject2.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts; +using RarelySimple.AvatarScriptLink.Objects.Abstracts; using System; using System.Collections.Generic; using System.Linq; diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject2015.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject2015.cs index 3217bbaa..79022466 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject2015.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/OptionObject2015.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts; +using RarelySimple.AvatarScriptLink.Objects.Abstracts; using System; using System.Collections.Generic; using System.Linq; diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/RowObject.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/RowObject.cs index bff5f8c8..acfed70d 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.Objects/RowObject.cs +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/RowObject.cs @@ -1,4 +1,4 @@ -using RarelySimple.AvatarScriptLink.Objects.Advanced.Abstracts; +using RarelySimple.AvatarScriptLink.Objects.Abstracts; using System; using System.Collections.Generic; using System.Linq; diff --git a/dotnet/RarelySimple.AvatarScriptLink.Objects/Utilities/BooleanConversion.cs b/dotnet/RarelySimple.AvatarScriptLink.Objects/Utilities/BooleanConversion.cs new file mode 100644 index 00000000..36d486b4 --- /dev/null +++ b/dotnet/RarelySimple.AvatarScriptLink.Objects/Utilities/BooleanConversion.cs @@ -0,0 +1,34 @@ +namespace RarelySimple.AvatarScriptLink.Objects.Utilities +{ + /// + /// Provides utilities for converting between boolean and string representations used in myAvatar. + /// + /// + /// myAvatar uses string values "0" and "1" to represent boolean states in field properties like Enabled, Locked, and Required. + /// This utility class provides centralized conversion logic to maintain consistency across the library. + /// + internal static class BooleanConversion + { + /// + /// Converts a myAvatar string representation ("0" or "1") to a boolean value. + /// + /// The string value to convert. "1" is true, anything else is false. + /// True if value is "1", false otherwise. + /// + /// This method is used to convert myAvatar's string-based boolean representations to C# boolean values. + /// Valid values: "1" (true), "0" (false), or empty string (false). + /// + public static bool ToBoolean(string value) => value == "1"; + + /// + /// Converts a boolean value to a myAvatar string representation ("0" or "1"). + /// + /// The boolean value to convert. + /// "1" if value is true, "0" if false. + /// + /// This method is used to convert C# boolean values to myAvatar's string-based boolean representations. + /// Returned values: "1" (true) or "0" (false). + /// + public static string ToAvatarBoolean(bool value) => value ? "1" : "0"; + } +} diff --git a/dotnet/RarelySimple.AvatarScriptLink.sln b/dotnet/RarelySimple.AvatarScriptLink.sln index 0102d965..b624b4ff 100644 --- a/dotnet/RarelySimple.AvatarScriptLink.sln +++ b/dotnet/RarelySimple.AvatarScriptLink.sln @@ -12,14 +12,28 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Objects", "RarelySimple.AvatarScriptLink.Objects\RarelySimple.AvatarScriptLink.Objects.csproj", "{3810083A-8A9C-4093-B9C1-3E9AD804BB36}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Objects.Builders", "RarelySimple.AvatarScriptLink.Objects.Builders\RarelySimple.AvatarScriptLink.Objects.Builders.csproj", "{B1C2D3E4-F5A6-4B7C-8D9E-0F1A2B3C4D5E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Objects.Builders.Tests", "RarelySimple.AvatarScriptLink.Objects.Builders.Tests\RarelySimple.AvatarScriptLink.Objects.Builders.Tests.csproj", "{C2D3E4F5-A6B7-4C8D-9E0F-1A2B3C4D5E6F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Objects.Helpers", "RarelySimple.AvatarScriptLink.Objects.Helpers\RarelySimple.AvatarScriptLink.Objects.Helpers.csproj", "{D3E4F5A6-B7C8-4D9E-0F1A-2B3C4D5E6F7A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Objects.Helpers.Tests", "RarelySimple.AvatarScriptLink.Objects.Helpers.Tests\RarelySimple.AvatarScriptLink.Objects.Helpers.Tests.csproj", "{E4F5A6B7-C8D9-4E0F-1A2B-3C4D5E6F7A8B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Objects.Converters", "RarelySimple.AvatarScriptLink.Objects.Converters\RarelySimple.AvatarScriptLink.Objects.Converters.csproj", "{6A3C2E41-8C1B-4D66-9E88-0B7F87E36F5A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Objects.Converters.Tests", "RarelySimple.AvatarScriptLink.Objects.Converters.Tests\RarelySimple.AvatarScriptLink.Objects.Converters.Tests.csproj", "{8F4E2B9C-6B2F-4D7A-A7C0-3B3F07F2D6B1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Objects.Validators", "RarelySimple.AvatarScriptLink.Objects.Validators\RarelySimple.AvatarScriptLink.Objects.Validators.csproj", "{6D9910E9-65AB-4E51-B63E-80C19C38E1A1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Objects.Validators.Tests", "RarelySimple.AvatarScriptLink.Objects.Validators.Tests\RarelySimple.AvatarScriptLink.Objects.Validators.Tests.csproj", "{5CC401C7-9C0A-4B25-B7CB-63A768AC1A1E}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Services", "RarelySimple.AvatarScriptLink.Services\RarelySimple.AvatarScriptLink.Services.csproj", "{DD4CB48E-3802-4132-B102-B23E1A495943}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Net", "RarelySimple.AvatarScriptLink.Net\RarelySimple.AvatarScriptLink.Net.csproj", "{C388F991-3F29-40F7-8759-56775F95C9A0}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Objects.Tests", "RarelySimple.AvatarScriptLink.Objects.Tests\RarelySimple.AvatarScriptLink.Objects.Tests.csproj", "{E0F2D37A-6C52-45E4-90B7-A60CF5C7B0FF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RarelySimple.AvatarScriptLink.Net.Tests", "RarelySimple.AvatarScriptLink.Net.Tests\RarelySimple.AvatarScriptLink.Net.Tests.csproj", "{FE75D359-668A-49EF-8175-B965952A41D3}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RarelySimple.AvatarScriptLink.Tests", "RarelySimple.AvatarScriptLink.Tests\RarelySimple.AvatarScriptLink.Tests.csproj", "{A5AE2AC4-41C2-4692-B4F1-A77C90B60377}" EndProject Global @@ -36,6 +50,38 @@ Global {3810083A-8A9C-4093-B9C1-3E9AD804BB36}.Debug|Any CPU.Build.0 = Debug|Any CPU {3810083A-8A9C-4093-B9C1-3E9AD804BB36}.Release|Any CPU.ActiveCfg = Release|Any CPU {3810083A-8A9C-4093-B9C1-3E9AD804BB36}.Release|Any CPU.Build.0 = Release|Any CPU + {B1C2D3E4-F5A6-4B7C-8D9E-0F1A2B3C4D5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B1C2D3E4-F5A6-4B7C-8D9E-0F1A2B3C4D5E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B1C2D3E4-F5A6-4B7C-8D9E-0F1A2B3C4D5E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B1C2D3E4-F5A6-4B7C-8D9E-0F1A2B3C4D5E}.Release|Any CPU.Build.0 = Release|Any CPU + {C2D3E4F5-A6B7-4C8D-9E0F-1A2B3C4D5E6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C2D3E4F5-A6B7-4C8D-9E0F-1A2B3C4D5E6F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2D3E4F5-A6B7-4C8D-9E0F-1A2B3C4D5E6F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C2D3E4F5-A6B7-4C8D-9E0F-1A2B3C4D5E6F}.Release|Any CPU.Build.0 = Release|Any CPU + {D3E4F5A6-B7C8-4D9E-0F1A-2B3C4D5E6F7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3E4F5A6-B7C8-4D9E-0F1A-2B3C4D5E6F7A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3E4F5A6-B7C8-4D9E-0F1A-2B3C4D5E6F7A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3E4F5A6-B7C8-4D9E-0F1A-2B3C4D5E6F7A}.Release|Any CPU.Build.0 = Release|Any CPU + {E4F5A6B7-C8D9-4E0F-1A2B-3C4D5E6F7A8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E4F5A6B7-C8D9-4E0F-1A2B-3C4D5E6F7A8B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E4F5A6B7-C8D9-4E0F-1A2B-3C4D5E6F7A8B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E4F5A6B7-C8D9-4E0F-1A2B-3C4D5E6F7A8B}.Release|Any CPU.Build.0 = Release|Any CPU + {6A3C2E41-8C1B-4D66-9E88-0B7F87E36F5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A3C2E41-8C1B-4D66-9E88-0B7F87E36F5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A3C2E41-8C1B-4D66-9E88-0B7F87E36F5A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A3C2E41-8C1B-4D66-9E88-0B7F87E36F5A}.Release|Any CPU.Build.0 = Release|Any CPU + {8F4E2B9C-6B2F-4D7A-A7C0-3B3F07F2D6B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F4E2B9C-6B2F-4D7A-A7C0-3B3F07F2D6B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8F4E2B9C-6B2F-4D7A-A7C0-3B3F07F2D6B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8F4E2B9C-6B2F-4D7A-A7C0-3B3F07F2D6B1}.Release|Any CPU.Build.0 = Release|Any CPU + {6D9910E9-65AB-4E51-B63E-80C19C38E1A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D9910E9-65AB-4E51-B63E-80C19C38E1A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D9910E9-65AB-4E51-B63E-80C19C38E1A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D9910E9-65AB-4E51-B63E-80C19C38E1A1}.Release|Any CPU.Build.0 = Release|Any CPU + {5CC401C7-9C0A-4B25-B7CB-63A768AC1A1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CC401C7-9C0A-4B25-B7CB-63A768AC1A1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CC401C7-9C0A-4B25-B7CB-63A768AC1A1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CC401C7-9C0A-4B25-B7CB-63A768AC1A1E}.Release|Any CPU.Build.0 = Release|Any CPU {DD4CB48E-3802-4132-B102-B23E1A495943}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DD4CB48E-3802-4132-B102-B23E1A495943}.Debug|Any CPU.Build.0 = Debug|Any CPU {DD4CB48E-3802-4132-B102-B23E1A495943}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -48,14 +94,6 @@ Global {E0F2D37A-6C52-45E4-90B7-A60CF5C7B0FF}.Debug|Any CPU.Build.0 = Debug|Any CPU {E0F2D37A-6C52-45E4-90B7-A60CF5C7B0FF}.Release|Any CPU.ActiveCfg = Release|Any CPU {E0F2D37A-6C52-45E4-90B7-A60CF5C7B0FF}.Release|Any CPU.Build.0 = Release|Any CPU - {715F8B31-520B-495D-9C80-4E3DEB37F347}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {715F8B31-520B-495D-9C80-4E3DEB37F347}.Debug|Any CPU.Build.0 = Debug|Any CPU - {715F8B31-520B-495D-9C80-4E3DEB37F347}.Release|Any CPU.ActiveCfg = Release|Any CPU - {715F8B31-520B-495D-9C80-4E3DEB37F347}.Release|Any CPU.Build.0 = Release|Any CPU - {FE75D359-668A-49EF-8175-B965952A41D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FE75D359-668A-49EF-8175-B965952A41D3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FE75D359-668A-49EF-8175-B965952A41D3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FE75D359-668A-49EF-8175-B965952A41D3}.Release|Any CPU.Build.0 = Release|Any CPU {A5AE2AC4-41C2-4692-B4F1-A77C90B60377}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A5AE2AC4-41C2-4692-B4F1-A77C90B60377}.Debug|Any CPU.Build.0 = Debug|Any CPU {A5AE2AC4-41C2-4692-B4F1-A77C90B60377}.Release|Any CPU.ActiveCfg = Release|Any CPU