Skip to content

Commit

Permalink
Im and export improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Jul 14, 2020
1 parent 17893ce commit 1a64d92
Show file tree
Hide file tree
Showing 23 changed files with 554 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -20,11 +19,11 @@

namespace Squidex.CLI.Tests
{
public class MapToSquidexTests
public class MapCSVToSquidexTests
{
private readonly CsvReader csvReader;

public MapToSquidexTests()
public MapCSVToSquidexTests()
{
var csv = new StringBuilder();

Expand Down Expand Up @@ -74,7 +73,7 @@ public void Should_read_string_to_invariant()

var expected = new DummyData
{
["text"] = new Dictionary<string, JToken>
["text"] = new JObject
{
["iv"] = "Hello World"
}
Expand All @@ -92,7 +91,7 @@ public void Should_read_boolean_to_invariant()

var expected = new DummyData
{
["boolean"] = new Dictionary<string, JToken>
["boolean"] = new JObject
{
["iv"] = true
}
Expand All @@ -110,7 +109,7 @@ public void Should_read_number_to_invariant()

var expected = new DummyData
{
["number"] = new Dictionary<string, JToken>
["number"] = new JObject
{
["iv"] = 1234
}
Expand All @@ -128,7 +127,7 @@ public void Should_read_string_to_localized()

var expected = new DummyData
{
["text"] = new Dictionary<string, JToken>
["text"] = new JObject
{
["de"] = "Hello World"
}
Expand All @@ -146,7 +145,7 @@ public void Should_read_array_to_invariant()

var expected = new DummyData
{
["array"] = new Dictionary<string, JToken>
["array"] = new JObject
{
["iv"] = new JArray("Squidex", "CLI")
}
Expand All @@ -164,7 +163,7 @@ public void Should_read_object_to_invariant()

var expected = new DummyData
{
["object"] = new Dictionary<string, JToken>
["object"] = new JObject
{
["iv"] = new JObject(new JProperty("Squidex", "CLI"))
}
Expand All @@ -182,7 +181,7 @@ public void Should_read_string_to_array()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JArray(null, "Hello World")
}
Expand All @@ -200,7 +199,7 @@ public void Should_read_multiple_values_to_array()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JArray(1234, "Hello World")
}
Expand All @@ -218,7 +217,7 @@ public void Should_read_string_to_nested_array()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JArray(null, new JArray("Hello World"))
}
Expand All @@ -236,7 +235,7 @@ public void Should_read_string_to_object()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JObject
{
Expand All @@ -257,7 +256,7 @@ public void Should_read_multiple_values_to_object()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JObject
{
Expand All @@ -279,7 +278,7 @@ public void Should_read_string_to_nested_object()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JObject
{
Expand All @@ -296,7 +295,10 @@ public void Should_read_string_to_nested_object()

private void EqualJson(DummyData expected, DummyData actual)
{
Assert.Equal(JsonConvert.SerializeObject(expected, Formatting.Indented), JsonConvert.SerializeObject(actual, Formatting.Indented));
var lhs = JsonConvert.SerializeObject(expected, Formatting.Indented);
var rhs = JsonConvert.SerializeObject(actual, Formatting.Indented);

Assert.Equal(lhs, rhs);
}
}
}
13 changes: 6 additions & 7 deletions cli/Squidex.CLI/Squidex.CLI.Tests/MapFromSquidexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// ==========================================================================

using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using Squidex.CLI.Commands;
Expand All @@ -27,32 +26,32 @@ public MapFromSquidexTests()
Created = DateTimeOffset.Now
};

content.Data["name"] = new Dictionary<string, JToken>
content.Data["name"] = new JObject
{
["iv"] = "Hello World"
};

content.Data["text"] = new Dictionary<string, JToken>
content.Data["text"] = new JObject
{
["iv"] = "Hello World"
};

content.Data["localizedText"] = new Dictionary<string, JToken>
content.Data["localizedText"] = new JObject
{
["en"] = "Hello World"
};

content.Data["multilineText"] = new Dictionary<string, JToken>
content.Data["multilineText"] = new JObject
{
["iv"] = "Hello\nWorld"
};

content.Data["user"] = new Dictionary<string, JToken>
content.Data["user"] = new JObject
{
["iv"] = new JObject(new JProperty("name", "Squidex"))
};

content.Data["products"] = new Dictionary<string, JToken>
content.Data["products"] = new JObject
{
["iv"] = new JArray("Squidex", "CLI")
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
Expand All @@ -17,11 +16,11 @@

namespace Squidex.CLI.Tests
{
public class MapJsonFileToSquidexTests
public class MapJsonToSquidexTests
{
private readonly JsonTextReader jsonReader;

public MapJsonFileToSquidexTests()
public MapJsonToSquidexTests()
{
var data = new[]
{
Expand All @@ -41,9 +40,9 @@ public MapJsonFileToSquidexTests()
}

[Fact]
public void Should_throw_exception_if_field_names_is_null()
public void Should_not_throw_exception_if_field_names_is_null()
{
Assert.Throws<SquidexException>(() => new Json2SquidexConverter(null));
_ = new Json2SquidexConverter(null);
}

[Fact]
Expand All @@ -61,7 +60,7 @@ public void Should_read_string_to_invariant()

var expected = new DummyData
{
["text"] = new Dictionary<string, JToken>
["text"] = new JObject
{
["iv"] = "Hello World"
}
Expand All @@ -79,7 +78,7 @@ public void Should_read_boolean_to_invariant()

var expected = new DummyData
{
["boolean"] = new Dictionary<string, JToken>
["boolean"] = new JObject
{
["iv"] = true
}
Expand All @@ -97,7 +96,7 @@ public void Should_read_number_to_invariant()

var expected = new DummyData
{
["number"] = new Dictionary<string, JToken>
["number"] = new JObject
{
["iv"] = 1234
}
Expand All @@ -115,7 +114,7 @@ public void Should_read_string_to_localized()

var expected = new DummyData
{
["text"] = new Dictionary<string, JToken>
["text"] = new JObject
{
["de"] = "Hello World"
}
Expand All @@ -133,7 +132,7 @@ public void Should_read_array_to_invariant()

var expected = new DummyData
{
["array"] = new Dictionary<string, JToken>
["array"] = new JObject
{
["iv"] = new JArray("Squidex", "CLI")
}
Expand All @@ -151,7 +150,7 @@ public void Should_read_object_to_invariant()

var expected = new DummyData
{
["obj"] = new Dictionary<string, JToken>
["obj"] = new JObject
{
["iv"] = new JObject(new JProperty("Squidex", "CLI"))
}
Expand All @@ -169,7 +168,7 @@ public void Should_read_string_to_array()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JArray(null, "Hello World")
}
Expand All @@ -187,7 +186,7 @@ public void Should_read_multiple_values_to_array()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JArray(1234, "Hello World")
}
Expand All @@ -205,7 +204,7 @@ public void Should_read_string_to_nested_array()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JArray(null, new JArray("Hello World"))
}
Expand All @@ -223,7 +222,7 @@ public void Should_read_string_to_object()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JObject
{
Expand All @@ -244,7 +243,7 @@ public void Should_read_multiple_values_to_object()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JObject
{
Expand All @@ -266,7 +265,7 @@ public void Should_read_string_to_nested_object()

var expected = new DummyData
{
["json"] = new Dictionary<string, JToken>
["json"] = new JObject
{
["iv"] = new JObject
{
Expand All @@ -281,9 +280,43 @@ public void Should_read_string_to_nested_object()
EqualJson(expected, actual);
}

[Fact]
public void Should_read_without_mapping()
{
var sut = new Json2SquidexConverter();

var actual = sut.ReadAll(jsonReader).First();

var expected = new DummyData
{
["text"] = new JObject
{
["iv"] = "Hello World"
},
["boolean"] = new JObject
{
["iv"] = true
},
["number"] = new JObject
{
["iv"] = 1234
},
["array"] = new JObject
{
["iv"] = new JArray("Squidex", "CLI")
},
["obj"] = new JObject(new JProperty("Squidex", "CLI"))
};

EqualJson(expected, actual);
}

private void EqualJson(DummyData expected, DummyData actual)
{
Assert.Equal(JsonConvert.SerializeObject(expected, Formatting.Indented), JsonConvert.SerializeObject(actual, Formatting.Indented));
var lhs = JsonConvert.SerializeObject(expected, Formatting.Indented);
var rhs = JsonConvert.SerializeObject(actual, Formatting.Indented);

Assert.Equal(lhs, rhs);
}
}
}
Loading

0 comments on commit 1a64d92

Please sign in to comment.