-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Squidex/squidex-samples
# Conflicts: # csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Squidex.ClientLibrary.csproj
- Loading branch information
Showing
17 changed files
with
2,004 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
cli/Squidex.CLI/Squidex.CLI.Tests/MapFromSquidexTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
// ========================================================================== | ||
// Squidex Headless CMS | ||
// ========================================================================== | ||
// Copyright (c) Squidex UG (haftungsbeschraenkt) | ||
// All rights reserved. Licensed under the MIT license. | ||
// ========================================================================== | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Newtonsoft.Json.Linq; | ||
using Squidex.CLI.Commands; | ||
using Squidex.CLI.Commands.Implementation; | ||
using Squidex.ClientLibrary; | ||
using Xunit; | ||
|
||
namespace Squidex.CLI.Tests | ||
{ | ||
public class MapFromSquidexTests | ||
{ | ||
private readonly DummyEntity content; | ||
|
||
public MapFromSquidexTests() | ||
{ | ||
content = new DummyEntity | ||
{ | ||
DataDraft = new DummyData | ||
{ | ||
["name"] = new Dictionary<string, JToken> | ||
{ | ||
["iv"] = "Hello World" | ||
} | ||
}, | ||
Created = DateTimeOffset.Now | ||
}; | ||
|
||
content.Data["text"] = new Dictionary<string, JToken> | ||
{ | ||
["iv"] = "Hello World" | ||
}; | ||
|
||
content.Data["localizedText"] = new Dictionary<string, JToken> | ||
{ | ||
["en"] = "Hello World" | ||
}; | ||
|
||
content.Data["multilineText"] = new Dictionary<string, JToken> | ||
{ | ||
["iv"] = "Hello\nWorld" | ||
}; | ||
|
||
content.Data["user"] = new Dictionary<string, JToken> | ||
{ | ||
["iv"] = new JObject(new JProperty("name", "Squidex")) | ||
}; | ||
|
||
content.Data["products"] = new Dictionary<string, JToken> | ||
{ | ||
["iv"] = new JArray("Squidex", "CLI") | ||
}; | ||
} | ||
|
||
[Fact] | ||
public void Should_throw_exception_if_field_names_is_null() | ||
{ | ||
Assert.Throws<SquidexException>(() => new Squidex2CsvConverter(null)); | ||
} | ||
|
||
[Fact] | ||
public void Should_throw_exception_if_field_names_is_empty() | ||
{ | ||
Assert.Throws<SquidexException>(() => new Squidex2CsvConverter(string.Empty)); | ||
} | ||
|
||
[Fact] | ||
public void Should_use_direct_field_names() | ||
{ | ||
var sut = new Squidex2CsvConverter("created,lastModified,data.name.iv"); | ||
|
||
Assert.Equal(new[] { "created", "lastModified", "data.name.iv" }, sut.FieldNames); | ||
} | ||
|
||
[Fact] | ||
public void Should_use_alias_field_names() | ||
{ | ||
var sut = new Squidex2CsvConverter("created,name=data.name.iv"); | ||
|
||
Assert.Equal(new[] { "created", "name" }, sut.FieldNames); | ||
} | ||
|
||
[Fact] | ||
public void Should_extract_value_from_property() | ||
{ | ||
var sut = new Squidex2CsvConverter("created"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { content.Created }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_return_invalid_if_property_not_found() | ||
{ | ||
var sut = new Squidex2CsvConverter("invalid"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "<INVALID>" }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_extract_value_from_invariant_data_draft() | ||
{ | ||
var sut = new Squidex2CsvConverter("dataDraft.name"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "Hello World" }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_extract_value_from_invariant_data() | ||
{ | ||
var sut = new Squidex2CsvConverter("data.text"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "Hello World" }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_extract_value_from_localized_data() | ||
{ | ||
var sut = new Squidex2CsvConverter("data.localizedText.en"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "Hello World" }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_extract_value_from_invariant_data_and_escape() | ||
{ | ||
var sut = new Squidex2CsvConverter("data.multilineText"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "Hello\\nWorld" }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_return_invalid_if_field_not_found() | ||
{ | ||
var sut = new Squidex2CsvConverter("data.invalid"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "<INVALID>" }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_extract_value_from_nested_object() | ||
{ | ||
var sut = new Squidex2CsvConverter("data.user.iv.name"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "Squidex" }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_return_invalid_if_property_in_nested_object_not_found() | ||
{ | ||
var sut = new Squidex2CsvConverter("data.invalid"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "<INVALID>" }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_extract_value_from_nested_array() | ||
{ | ||
var sut = new Squidex2CsvConverter("data.products.iv.1"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "CLI" }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_return_invalid_if_index_out_of_range() | ||
{ | ||
var sut = new Squidex2CsvConverter("data.products.iv.3"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "<INVALID>" }, values); | ||
} | ||
|
||
[Fact] | ||
public void Should_extract_value_as_json() | ||
{ | ||
var sut = new Squidex2CsvConverter("data.products"); | ||
|
||
var values = sut.GetValues(content).ToArray(); | ||
|
||
Assert.Equal(new object[] { "[\"Squidex\",\"CLI\"]" }, values); | ||
} | ||
} | ||
} |
Oops, something went wrong.