Skip to content

Commit b65765f

Browse files
committed
Add another test for UpdatableExtensionBehavior FK type
1 parent 2b1c62d commit b65765f

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

tests/Serenity.Net.Tests/services/requesthandlers/integratedfeatures/updatableextension/UpdatableExtensionBehavior_ForeignThisKey_Test.cs

+38-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ namespace Serenity.Services;
33
public partial class UpdatableExtensionBehavior_ForeignThisKey_Test
44
{
55
[Fact]
6-
public void ForeignKeyField_CanBeUsedAs_ThisKey()
6+
public void ForeignKeyField_CanBeUsedAs_ThisKey_WithManualIdAssigned()
77
{
8-
var context = new MockRequestContext()
9-
{
10-
Behaviors = new NullBehaviorProvider(),
11-
Permissions = new NullPermissions()
12-
};
138
bool saveDetailCalled = false;
149
var handlerFactory = new MockHandlerFactory((rowType, intfType) =>
1510
{
@@ -53,6 +48,43 @@ public void ForeignKeyField_CanBeUsedAs_ThisKey()
5348
Assert.True(saveDetailCalled);
5449
}
5550

51+
[Fact]
52+
public void ForeignKeyField_CanBeUsedAs_ThisKey_WithoutDetailId()
53+
{
54+
bool saveDetailCalled = false;
55+
var handlerFactory = new MockHandlerFactory((rowType, intfType) =>
56+
{
57+
Assert.Equal(typeof(DetailRow), rowType);
58+
Assert.Equal(typeof(ISaveRequestProcessor), intfType);
59+
return new MockSaveHandler<DetailRow>(x =>
60+
{
61+
Assert.Equal(SaveRequestType.Create, x.RequestType);
62+
Assert.Null(x.Request?.EntityId);
63+
var detail = Assert.IsType<DetailRow>(x.Request.Entity);
64+
Assert.Null(detail.Id);
65+
Assert.Equal("TestDetail", detail.Text);
66+
saveDetailCalled = true;
67+
x.Response.EntityId = 1357;
68+
});
69+
});
70+
var row = new MainRow()
71+
{
72+
DetailText = "TestDetail"
73+
};
74+
var connection = new MockDbConnection();
75+
var handler = new MockSaveHandler<MainRow>()
76+
{
77+
Connection = connection,
78+
Row = row
79+
};
80+
var behavior = new UpdatableExtensionBehavior(handlerFactory);
81+
Assert.True(behavior.ActivateFor(row));
82+
behavior.OnBeforeSave(handler);
83+
behavior.OnAfterSave(handler);
84+
Assert.True(saveDetailCalled);
85+
Assert.Equal(1357, row.DetailId);
86+
}
87+
5688
[TableName("Mains")]
5789
[UpdatableExtension("d", typeof(DetailRow), ThisKey = "DetailId")]
5890
public class MainRow : Row<MainRow.RowFields>, IIdRow

0 commit comments

Comments
 (0)