Skip to content

Commit

Permalink
Fixed serializer on property transfered to server but without setter.
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Dec 27, 2016
1 parent 4f7a589 commit a1e7e92
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
29 changes: 24 additions & 5 deletions src/DotVVM.Framework.Tests.Owin/DefaultViewModelSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public void Serializer_Valid_ExistingValueNotReplaced()
Assert.AreEqual(123, viewModel.Property.GetPrivateField());
}

private string SerializeViewModel(object viewModel)


private string SerializeViewModel(object viewModel)
{
context.ViewModel = viewModel;
serializer.SendDiff = false;
Expand Down Expand Up @@ -320,11 +322,28 @@ public void DefaultViewModelSerializer_EnumInCollection()
Assert.AreEqual(oldViewModel.Children[2].Property1, newViewModel.Children[2].Property1);
}

[TestMethod]
public void Serializer_Valid_BindBothOnGetOnlyProperty()
{
var json = SerializeViewModel(new GetOnlyPropertyViewModel { Property = 42 });

/// <summary>
/// Wraps the serialized view model to an object that comes from the client.
/// </summary>
private static string WrapSerializedViewModel(string result)
var viewModel = new GetOnlyPropertyViewModel();
PopulateViewModel(viewModel, json);
Assert.AreEqual(43, viewModel.PropertyPlusOne);
}

public class GetOnlyPropertyViewModel
{
public int Property { get; set; }
[Bind(Direction.Both)]
public int PropertyPlusOne => Property + 1;
}


/// <summary>
/// Wraps the serialized view model to an object that comes from the client.
/// </summary>
private static string WrapSerializedViewModel(string result)
{
return string.Format("{{'currentPath':[],'command':'','controlUniqueId':'','viewModel':{0},'validationTargetPath':'','updatedControls':{{}}}}".Replace("'", "\""), result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Action<JObject, JsonSerializer, object, EncryptedValuesReader> CreateRead
block.Add(Expression.Assign(value, Expression.Convert(valueParam, Type)));

// go through all properties that should be read
foreach (var property in Properties.Where(p => p.TransferToServer))
foreach (var property in Properties.Where(p => p.TransferToServer && p.PropertyInfo.SetMethod != null))
{
if (property.ViewModelProtection == ProtectMode.EncryptData || property.ViewModelProtection == ProtectMode.SignData)
{
Expand Down Expand Up @@ -235,7 +235,7 @@ public Action<JsonWriter, object, JsonSerializer, EncryptedValuesWriter, bool> C
{
var endPropertyLabel = Expression.Label("end_property_" + property.Name);
var options = new Dictionary<string, object>();
if (property.TransferToClient)
if (property.TransferToClient && property.PropertyInfo.GetMethod != null)
{
if (property.TransferFirstRequest != property.TransferAfterPostback)
{
Expand Down

0 comments on commit a1e7e92

Please sign in to comment.