Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 7bb0d68

Browse files
committed
Deprecate JsConfig.With() and convert all test to use JsConfig.With(new Config{})
1 parent d7829b0 commit 7bb0d68

16 files changed

+58
-54
lines changed

src/ServiceStack.Text/JsConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ public static JsConfigScope CreateScope(string config, JsConfigScope scope = nul
212212

213213
public static UTF8Encoding UTF8Encoding { get; set; } = new UTF8Encoding(false);
214214

215+
public static JsConfigScope With(Config config) => (JsConfigScope)new JsConfigScope().Populate(config);
216+
217+
[Obsolete("Use JsConfig.With(new Config { })")]
215218
public static JsConfigScope With(
216219
bool? convertObjectTypesIntoStringDictionary = null,
217220
bool? tryToParsePrimitiveTypeValues = null,

tests/ServiceStack.Text.Tests/AdhocModelTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public void Can_exclude_properties_scoped()
363363
Assert.That(dto.ToJsv(), Is.EqualTo("{Key:Value}"));
364364
}
365365

366-
using (JsConfig.With(excludePropertyReferences: new[] { "Exclude.Id" }))
366+
using (JsConfig.With(new Config { ExcludePropertyReferences = new[] { "Exclude.Id" }}))
367367
{
368368
Assert.That(dto.ToJson(), Is.EqualTo("{\"Key\":\"Value\"}"));
369369
Assert.That(dto.ToJsv(), Is.EqualTo("{Key:Value}"));

tests/ServiceStack.Text.Tests/AutoMappingBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void Does_Convert_BenchSource()
172172
var to = from.ConvertTo<BenchDestination>(); //warmup
173173
to = from.ConvertTo<BenchDestination>();
174174

175-
using (JsConfig.With(includePublicFields: true))
175+
using (JsConfig.With(new Config { IncludePublicFields = true }))
176176
{
177177
to.PrintDump();
178178
from.PrintDump();

tests/ServiceStack.Text.Tests/CyclicalDependencyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class person
163163
[Test]
164164
public void Can_limit_cyclical_dependencies()
165165
{
166-
using (JsConfig.With(maxDepth: 4))
166+
using (JsConfig.With(new Config { MaxDepth = 4 }))
167167
{
168168
var p = new person();
169169
p.teacher = new person { name = "sam", teacher = p };

tests/ServiceStack.Text.Tests/DateTimeOffsetAndTimeSpanTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void Can_serialize_TimeSpan_field()
6464
[Test]
6565
public void Can_serialize_TimeSpan_field_with_StandardTimeSpanFormat()
6666
{
67-
using (JsConfig.With(timeSpanHandler:TimeSpanHandler.StandardFormat))
67+
using (JsConfig.With(new Config { TimeSpanHandler = TimeSpanHandler.StandardFormat }))
6868
{
6969
var period = TimeSpan.FromSeconds(70);
7070

@@ -77,7 +77,7 @@ public void Can_serialize_TimeSpan_field_with_StandardTimeSpanFormat()
7777
[Test]
7878
public void Can_serialize_NullableTimeSpan_field_with_StandardTimeSpanFormat()
7979
{
80-
using (JsConfig.With(timeSpanHandler: TimeSpanHandler.StandardFormat))
80+
using (JsConfig.With(new Config { TimeSpanHandler = TimeSpanHandler.StandardFormat }))
8181
{
8282
var period = TimeSpan.FromSeconds(70);
8383

@@ -90,7 +90,7 @@ public void Can_serialize_NullableTimeSpan_field_with_StandardTimeSpanFormat()
9090
[Test]
9191
public void Can_serialize_NullTimeSpan_field_with_StandardTimeSpanFormat()
9292
{
93-
using (JsConfig.With(timeSpanHandler: TimeSpanHandler.StandardFormat))
93+
using (JsConfig.With(new Config { TimeSpanHandler = TimeSpanHandler.StandardFormat }))
9494
{
9595
var model = new NullableSampleModel { Id = 1 };
9696
var json = JsonSerializer.SerializeToString(model);

tests/ServiceStack.Text.Tests/EnumTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void Can_serialize_different_enum_styles()
152152
Assert.That("DoubleWord".FromJson<EnumStyles>(), Is.EqualTo(EnumStyles.DoubleWord));
153153
Assert.That("Underscore_Words".FromJson<EnumStyles>(), Is.EqualTo(EnumStyles.Underscore_Words));
154154

155-
using (JsConfig.With(emitLowercaseUnderscoreNames: true))
155+
using (JsConfig.With(new Config { EmitLowercaseUnderscoreNames = true}))
156156
{
157157
Assert.That("Double_Word".FromJson<EnumStyles>(), Is.EqualTo(EnumStyles.DoubleWord));
158158
Assert.That("Underscore_Words".FromJson<EnumStyles>(), Is.EqualTo(EnumStyles.Underscore_Words));
@@ -180,7 +180,7 @@ public void Can_deserialize_null_Nullable_Enum()
180180
[Test]
181181
public void Does_write_EnumValues_when_ExcludeDefaultValues()
182182
{
183-
using (JsConfig.With(excludeDefaultValues:true))
183+
using (JsConfig.With(new Config { ExcludeDefaultValues = true }))
184184
{
185185
Assert.That(new ClassWithEnums
186186
{
@@ -193,7 +193,7 @@ public void Does_write_EnumValues_when_ExcludeDefaultValues()
193193
}.ToJson(), Is.EqualTo("{\"FlagsEnum\":0,\"NoFlagsEnum\":\"Zero\"}"));
194194
}
195195

196-
using (JsConfig.With(excludeDefaultValues:true, includeDefaultEnums:false))
196+
using (JsConfig.With(new Config { ExcludeDefaultValues = true, IncludeDefaultEnums = false }))
197197
{
198198
Assert.That(new ClassWithEnums
199199
{

tests/ServiceStack.Text.Tests/JsConfigTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void Does_use_specific_configuration()
5858
[Test]
5959
public void Can_override_default_configuration()
6060
{
61-
using (JsConfig.With(emitLowercaseUnderscoreNames: false))
61+
using (JsConfig.With(new Config { EmitLowercaseUnderscoreNames = false }))
6262
{
6363
Assert.That(new Foo { FooBar = "value" }.ToJson(), Is.EqualTo("{\"FooBar\":\"value\"}"));
6464
}
@@ -71,16 +71,14 @@ public class SerializEmitLowerCaseUnderscoreNamesTests
7171
[Test]
7272
public void TestJsonDataWithJsConfigScope()
7373
{
74-
using (JsConfig.With(emitLowercaseUnderscoreNames: true,
75-
propertyConvention: PropertyConvention.Lenient))
74+
using (JsConfig.With(new Config { EmitLowercaseUnderscoreNames = true, PropertyConvention = PropertyConvention.Lenient}))
7675
AssertObjectJson();
7776
}
7877

7978
[Test]
8079
public void TestCloneObjectWithJsConfigScope()
8180
{
82-
using (JsConfig.With(emitLowercaseUnderscoreNames: true,
83-
propertyConvention: PropertyConvention.Lenient))
81+
using (JsConfig.With(new Config { EmitLowercaseUnderscoreNames = true, PropertyConvention = PropertyConvention.Lenient}))
8482
AssertObject();
8583
}
8684

tests/ServiceStack.Text.Tests/JsonTests/AnonymousDeserializationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void Deserialize_dynamic_json()
5353
string dob = dyn.DateOfBirth;
5454
"DynamicJson: {0}, {1}, {2}".Print(id, name, dob);
5555

56-
using (JsConfig.With(convertObjectTypesIntoStringDictionary: true))
56+
using (JsConfig.With(new Config { ConvertObjectTypesIntoStringDictionary = true }))
5757
{
5858
"Object Dictionary".Print();
5959
var map = (Dictionary<string, object>)json.FromJson<object>();

tests/ServiceStack.Text.Tests/JsonTests/BasicJsonTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ public void Can_include_null_values_for_adhoc_types()
582582

583583
JsConfig<Foo>.RawSerializeFn = obj =>
584584
{
585-
using (JsConfig.With(includeNullValues: true))
585+
using (JsConfig.With(new Config { IncludeNullValues = true }))
586586
return obj.ToJson();
587587
};
588588

@@ -596,7 +596,7 @@ public void Can_run_FromJson_within_RawDeserializeFn()
596596
{
597597
JsConfig<Foo>.RawDeserializeFn = json =>
598598
{
599-
using (JsConfig.With(includeNullValues: true))
599+
using (JsConfig.With(new Config { IncludeNullValues = true }))
600600
return json.FromJson<Foo>();
601601
};
602602

@@ -608,7 +608,7 @@ public void Can_run_FromJson_within_RawDeserializeFn()
608608
[Test]
609609
public void Does_include_null_values_in_lists()
610610
{
611-
using (JsConfig.With(includeNullValues: true))
611+
using (JsConfig.With(new Config { IncludeNullValues = true }))
612612
{
613613
var dto = new List<DateTime?>
614614
{

tests/ServiceStack.Text.Tests/JsonTests/ContractByInterfaceTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ContractByInterfaceTests
1313
[Test]
1414
public void Prefer_interfaces_should_work_on_top_level_object_using_extension_method()
1515
{
16-
using (JsConfig.With(preferInterfaces:true))
16+
using (JsConfig.With(new Config { PreferInterfaces = true }))
1717
{
1818
var json = new Concrete("boo", 1).ToJson();
1919

@@ -24,7 +24,7 @@ public void Prefer_interfaces_should_work_on_top_level_object_using_extension_me
2424
[Test]
2525
public void Should_be_able_to_serialise_based_on_an_interface()
2626
{
27-
using (JsConfig.With(preferInterfaces: true))
27+
using (JsConfig.With(new Config { PreferInterfaces = true }))
2828
{
2929
IContract myConcrete = new Concrete("boo", 1);
3030
var json = JsonSerializer.SerializeToString(myConcrete, typeof(IContract));
@@ -37,7 +37,7 @@ public void Should_be_able_to_serialise_based_on_an_interface()
3737
[Test]
3838
public void Should_not_use_interface_type_if_concrete_specified()
3939
{
40-
using (JsConfig.With(preferInterfaces: false))
40+
using (JsConfig.With(new Config { PreferInterfaces = false }))
4141
{
4242
IContract myConcrete = new Concrete("boo", 1);
4343
var json = JsonSerializer.SerializeToString(myConcrete, typeof(IContract));
@@ -50,7 +50,7 @@ public void Should_not_use_interface_type_if_concrete_specified()
5050
[Test]
5151
public void Should_be_able_to_deserialise_based_on_an_interface_with_no_concrete()
5252
{
53-
using (JsConfig.With(preferInterfaces: true))
53+
using (JsConfig.With(new Config { PreferInterfaces = true }))
5454
{
5555
var json = new Concrete("boo", 42).ToJson();
5656

0 commit comments

Comments
 (0)