Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,16 @@ codeunit 9987 "Word Template"
end;

/// <summary>
/// Add unrelated table.
/// Adds an unrelated table entry for the specified <paramref name="WordTemplateCode"/>.
/// </summary>
/// <param name="WordTemplateCode">The code of an existing parent Word template.</param>
/// <param name="PrefixCode">The code of the unrelated table to add.</param>
/// <param name="UnrelatedTableId">The ID of the unrelated table to add.</param>
/// <param name="RecordSystemId">The system id of the record to add.</param>
/// <returns>True if the unrelated table was added, false otherwise.</returns>
/// <returns>True if the unrelated table was added; otherwise, false.</returns>
procedure AddUnrelatedTable(WordTemplateCode: Code[30]; PrefixCode: Code[5]; UnrelatedTableId: Integer; RecordSystemId: Guid): Boolean
begin
WordTemplateImpl.AddUnrelatedTable(WordTemplateCode, PrefixCode, UnrelatedTableId, RecordSystemId);
exit(WordTemplateImpl.AddUnrelatedTable(WordTemplateCode, PrefixCode, UnrelatedTableId, RecordSystemId));
end;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,9 @@ codeunit 9988 "Word Template Impl."
WordTemplatesRelatedTable.SetRange("Related Table Code", TableCode);

if not WordTemplatesRelatedTable.IsEmpty() then begin
Message(RelatedTableCodeAlreadyUsedMsg);
if GuiAllowed() then
Message(RelatedTableCodeAlreadyUsedMsg);

exit(false);
end;

Expand All @@ -921,9 +923,12 @@ codeunit 9988 "Word Template Impl."
WordTemplatesRelatedTable.SetRange("Related Table ID", TableId);

if not WordTemplatesRelatedTable.IsEmpty() then begin
Message(RelatedTableIdAlreadyUsedMsg);
if GuiAllowed() then
Message(RelatedTableIdAlreadyUsedMsg);

exit(false);
end;

exit(true);
end;

Expand All @@ -937,6 +942,7 @@ codeunit 9988 "Word Template Impl."
exit(false);

WordTemplatesRelatedTable.Init();
WordTemplatesRelatedTable.Code := WordTemplateCode;
WordTemplatesRelatedTable."Source Record ID" := RecordSystemId;
WordTemplatesRelatedTable."Related Table ID" := UnrelatedTableId;
WordTemplatesRelatedTable."Related Table Code" := PrefixCode;
Expand Down
6 changes: 6 additions & 0 deletions src/System Application/Test/Word Templates/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"publisher": "Microsoft",
"version": "27.0.0.0"
},
{
"id": "e7320ebb-08b3-4406-b1ec-b4927d3e280b",
"name": "Any",
"publisher": "Microsoft",
"version": "27.0.0.0"
},
{
"id": "e31ad830-3d46-472e-afeb-1d3d35247943",
"name": "BLOB Storage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,101 @@ codeunit 130443 "Word Templates Test"
PermissionsMock: Codeunit "Permissions Mock";
Assert: Codeunit "Library Assert";

[Test]
[TransactionModel(TransactionModel::AutoRollback)]
procedure AddUnrelatedTableCreatesRecord()
var
WordTemplatesRelatedTable: Record "Word Templates Related Table";
Any: Codeunit Any;
WordTemplate: Codeunit "Word Template";
PrefixCode: Code[5];
TemplateCode: Code[30];
RelatedTableSystemId: Guid;
begin
// [SCENARIO 3105] Calling AddUnrelatedTable creates a related table record correctly

// [GIVEN] A Word Template Code
TemplateCode := CopyStr(Any.AlphabeticText(10), 1, MaxStrLen(TemplateCode));

// [GIVEN] A prefix code for the unrelated table
PrefixCode := CopyStr(Any.AlphabeticText(5), 1, MaxStrLen(PrefixCode));

// [GIVEN] A SystemId for the unrelated table record
RelatedTableSystemId := CreateGuid();

// [WHEN] AddUnrelatedTable is called for a specific table and record
WordTemplate.AddUnrelatedTable(TemplateCode, PrefixCode, Database::"Word Templates Table", RelatedTableSystemId);

// [THEN] The related table record is created
WordTemplatesRelatedTable.Get(TemplateCode, Database::"Word Templates Table");

// [THEN] The values match the provided parameters
Assert.AreEqual(PrefixCode, WordTemplatesRelatedTable."Related Table Code", WordTemplatesRelatedTable.FieldName("Related Table Code"));
Assert.AreEqual(RelatedTableSystemId, WordTemplatesRelatedTable."Source Record ID", WordTemplatesRelatedTable.FieldName("Source Record ID"));
end;

[Test]
[TransactionModel(TransactionModel::AutoRollback)]
procedure AddUnrelatedTableReturnsTrueIfCreated()
var
WordTemplatesRelatedTable: Record "Word Templates Related Table";
Any: Codeunit Any;
WordTemplate: Codeunit "Word Template";
Result: Boolean;
PrefixCode: Code[5];
TemplateCode: Code[30];
begin
// [SCENARIO 3105] Calling AddUnrelatedTable returns true if the record is created

// [GIVEN] No related table records exist
if not WordTemplatesRelatedTable.IsEmpty() then
WordTemplatesRelatedTable.DeleteAll(false);

// [WHEN] AddUnrelatedTable is called with arbitrary table and record id
TemplateCode := CopyStr(Any.AlphabeticText(10), 1, MaxStrLen(TemplateCode));
PrefixCode := CopyStr(Any.AlphabeticText(5), 1, MaxStrLen(PrefixCode));
Result := WordTemplate.AddUnrelatedTable(TemplateCode, PrefixCode, Any.IntegerInRange(1, 100), CreateGuid());

// [THEN] The method result is true
Assert.IsTrue(Result, 'Unexpected method return value.');
end;

[Test]
[HandlerFunctions('MessageHandler')]
[TransactionModel(TransactionModel::AutoRollback)]
procedure AddUnrelatedTableReturnsFalseIfNotCreated()
var
Any: Codeunit Any;
WordTemplate: Codeunit "Word Template";
Result: Boolean;
PrefixCode: Code[5];
TemplateCode: Code[30];
RelatedTableSystemId: Guid;
begin
// [SCENARIO 3105] Calling AddUnrelatedTable returns false if related table already exists

// [GIVEN] A Word Template Code
TemplateCode := CopyStr(Any.AlphabeticText(10), 1, MaxStrLen(TemplateCode));

// [GIVEN] A prefix code for the unrelated table
PrefixCode := CopyStr(Any.AlphabeticText(5), 1, MaxStrLen(PrefixCode));

// [GIVEN] A SystemId for the unrelated table record
RelatedTableSystemId := CreateGuid();

// [GIVEN] The related table already exists
WordTemplate.AddUnrelatedTable(TemplateCode, PrefixCode, Database::"Word Templates Table", RelatedTableSystemId);

// [WHEN] AddUnrelatedTable is called for the same table and record
Result := WordTemplate.AddUnrelatedTable(TemplateCode, PrefixCode, Database::"Word Templates Table", RelatedTableSystemId);

// [THEN] The user is informed that the (un)related table already exists
// Verified by MessageHandler

// [THEN] The method result is false
Assert.IsFalse(Result, 'Unexpected method return value.');
end;

[Test]
procedure TestCreateDocument()
var
Expand Down Expand Up @@ -253,4 +348,9 @@ codeunit 130443 "Word Templates Test"
begin
Reply := false;
end;

[MessageHandler]
procedure MessageHandler(Message: Text[1024])
begin
end;
}
Loading