-
Notifications
You must be signed in to change notification settings - Fork 260
Головнев Максим #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maximka200
wants to merge
13
commits into
kontur-courses:master
Choose a base branch
from
maximka200:objectPrinting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Головнев Максим #244
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b74451d
- сделал основную структуру
maximka200 07e7c2e
- написал тесты
maximka200 d387ab0
- дописал тестов
maximka200 f526a1d
Stop tracking fluent-api.sln and ignore it
maximka200 a8cce4f
Stop tracking fluent-api.sln.DotSettings and ignore it
maximka200 1f9c262
- изменил gitignore
maximka200 2b19625
- реализовал паттерн стратегия для ObjectPrinter.cs
maximka200 74fc126
- переписал DefaultObjectStrategy, сделал более читаемым
maximka200 4df660b
- поправил тест кейсы
maximka200 010eed5
- вернул fluent-api.sln
maximka200 0c335d3
добавил fluent-api.sln в .gitignore
maximka200 71f8cca
- переписал тесты с использованием Verify
maximka200 c39a8c9
- еще тесты
maximka200 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -236,3 +236,5 @@ _Pvt_Extensions | |
| .fake/ | ||
|
|
||
| .idea/ | ||
|
|
||
| fluent-api.sln | ||
This file contains hidden or 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,148 @@ | ||
| using ObjectPrinterTests.Entities; | ||
| using ObjectPrinting; | ||
| using ObjectPrinting.Extensions; | ||
|
|
||
| namespace ObjectPrinterTests; | ||
|
|
||
| [TestFixture] | ||
| public class CollectionPrintingSnapshotTests | ||
| { | ||
| private static readonly VerifySettings SnapshotSettings; | ||
|
|
||
| static CollectionPrintingSnapshotTests() | ||
| { | ||
| SnapshotSettings = new VerifySettings(); | ||
| SnapshotSettings.UseDirectory("ExpectedResults"); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task IntArray_Snapshot() | ||
| { | ||
| var config = new PrintingConfig<int[]>(); | ||
| var value = new[] { 1, 2, 3 }; | ||
|
|
||
| var actual = config.PrintToString(value); | ||
|
|
||
| return Verify(actual, SnapshotSettings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintToString_StringList_ShouldHandleCorrect() | ||
| { | ||
| var config = new PrintingConfig<List<string>>(); | ||
| var value = new List<string> { "one", "two" }; | ||
|
|
||
| var actual = config.PrintToString(value); | ||
|
|
||
| return Verify(actual, SnapshotSettings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintToString_Dictionary_ShouldHandleCorrect() | ||
| { | ||
| var config = new PrintingConfig<Dictionary<string, int>>(); | ||
| var value = new Dictionary<string, int> | ||
| { | ||
| ["a"] = 1, | ||
| ["b"] = 2 | ||
| }; | ||
|
|
||
| var actual = config.PrintToString(value); | ||
|
|
||
| return Verify(actual, SnapshotSettings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintToString_ShouldHandleClassWithCollections_Correctly() | ||
| { | ||
| var config = new PrintingConfig<Person>(); | ||
| var person = new Person | ||
| { | ||
| Name = "John", | ||
| Scores = [10, 20], | ||
| Tags = ["dev", "qa"], | ||
| Addresses = new Dictionary<string, Address> | ||
| { | ||
| ["home"] = new() { City = "Chelyabinsk" }, | ||
| ["work"] = new() { City = "Sverdlovsk" } | ||
| } | ||
| }; | ||
|
|
||
| var actual = config.PrintToString(person); | ||
|
|
||
| return Verify(actual, SnapshotSettings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintToString_ShouldHandleListOfLists_Correctly() | ||
| { | ||
| var config = new PrintingConfig<List<List<int>>>(); | ||
| var value = new List<List<int>> | ||
| { | ||
| new() { 1, 2 }, | ||
| new() { 3 } | ||
| }; | ||
|
|
||
| var actual = config.PrintToString(value); | ||
|
|
||
| return Verify(actual, SnapshotSettings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintToString_ShouldHandleDictionaryWithListValues_Correctly() | ||
| { | ||
| var config = new PrintingConfig<Dictionary<string, List<int>>>(); | ||
| var value = new Dictionary<string, List<int>> | ||
| { | ||
| ["first"] = [1, 2], | ||
| ["second"] = [3] | ||
| }; | ||
|
|
||
| var actual = config.PrintToString(value); | ||
|
|
||
| return Verify(actual, SnapshotSettings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintToString_ShouldHandleDictionaryWithNull_Correctly() | ||
| { | ||
| var config = new PrintingConfig<Dictionary<string, List<int>>>(); | ||
| var value = new Dictionary<string, List<int>?> | ||
| { | ||
| ["first"] = null, | ||
| ["second"] = null | ||
| }; | ||
|
|
||
| var actual = config.PrintToString(value); | ||
|
|
||
| return Verify(actual, SnapshotSettings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintToString_ShouldHandleListWithNull_Correctly() | ||
| { | ||
| var config = new PrintingConfig<Dictionary<string, List<int>>>(); | ||
| var value = new List<string?>() | ||
| { | ||
| null, | ||
| null, | ||
| null | ||
| }; | ||
|
|
||
| var actual = config.PrintToString(value); | ||
|
|
||
| return Verify(actual, SnapshotSettings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintToString_ShouldHandleListCycle_Correctly() | ||
| { | ||
| var config = new PrintingConfig<List<object>>(); | ||
| var value = new List<object>(); | ||
| value.Add(value); | ||
|
|
||
| var actual = config.PrintToString(value); | ||
|
|
||
| return Verify(actual, SnapshotSettings); | ||
| } | ||
| } | ||
This file contains hidden or 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,9 @@ | ||
| namespace ObjectPrinterTests.Entities; | ||
|
|
||
| public class A | ||
| { | ||
| public string Name { get; set; } | ||
| public int Number { get; set; } | ||
| public double Price { get; set; } | ||
| public Guid Id { get; set; } | ||
| } |
This file contains hidden or 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,7 @@ | ||
| namespace ObjectPrinterTests.Entities; | ||
|
|
||
| public class Address | ||
| { | ||
| public string City { get; set; } = ""; | ||
| public string Street { get; set; } = ""; | ||
| } |
This file contains hidden or 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,7 @@ | ||
| namespace ObjectPrinterTests.Entities; | ||
|
|
||
| public class B | ||
| { | ||
| public A Data { get; set; } | ||
| public B Parent { get; set; } | ||
| } |
This file contains hidden or 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,9 @@ | ||
| namespace ObjectPrinterTests.Entities; | ||
|
|
||
| public class Person | ||
| { | ||
| public string Name { get; set; } = ""; | ||
| public int[] Scores { get; set; } = []; | ||
| public List<string> Tags { get; set; } = []; | ||
| public Dictionary<string, Address> Addresses { get; set; } = new(); | ||
| } |
5 changes: 5 additions & 0 deletions
5
...interTests/ExpectedResults/CollectionPrintingSnapshotTests.IntArray_Snapshot.verified.txt
This file contains hidden or 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,5 @@ | ||
| Int32[] [ | ||
| 1 | ||
| 2 | ||
| 3 | ||
| ] |
4 changes: 4 additions & 0 deletions
4
...CollectionPrintingSnapshotTests.PrintToString_Dictionary_ShouldHandleCorrect.verified.txt
This file contains hidden or 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,4 @@ | ||
| Dictionary<String, Int32> { | ||
| [a] = 1 | ||
| [b] = 2 | ||
| } |
20 changes: 20 additions & 0 deletions
20
...intingSnapshotTests.PrintToString_ShouldHandleClassWithCollections_Correctly.verified.txt
This file contains hidden or 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,20 @@ | ||
| Person: | ||
| Name = John | ||
| Scores = Int32[] [ | ||
| 10 | ||
| 20 | ||
| ] | ||
| Tags = List<String> [ | ||
| dev | ||
| qa | ||
| ] | ||
| Addresses = Dictionary<String, Address> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Хорошо бы переделать на языконезависимый JSON-подобный формат. Типы данных не должны быть явно прописаны, т.к. названия типов это детали C#. |
||
| [home] = Address: | ||
| City = Chelyabinsk | ||
| Street = | ||
|
|
||
| [work] = Address: | ||
| City = Sverdlovsk | ||
| Street = <cyclic reference> | ||
|
|
||
| } | ||
9 changes: 9 additions & 0 deletions
9
...ngSnapshotTests.PrintToString_ShouldHandleDictionaryWithListValues_Correctly.verified.txt
This file contains hidden or 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,9 @@ | ||
| Dictionary<String, List<Int32>> { | ||
| [first] = List<Int32> [ | ||
| 1 | ||
| 2 | ||
| ] | ||
| [second] = List<Int32> [ | ||
| 3 | ||
| ] | ||
| } |
4 changes: 4 additions & 0 deletions
4
...PrintingSnapshotTests.PrintToString_ShouldHandleDictionaryWithNull_Correctly.verified.txt
This file contains hidden or 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,4 @@ | ||
| Dictionary<String, List<Int32>> { | ||
| [first] = null | ||
| [second] = null | ||
| } |
3 changes: 3 additions & 0 deletions
3
...ollectionPrintingSnapshotTests.PrintToString_ShouldHandleListCycle_Correctly.verified.txt
This file contains hidden or 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,3 @@ | ||
| List<Object> [ | ||
| <cyclic reference> | ||
| ] |
9 changes: 9 additions & 0 deletions
9
...lectionPrintingSnapshotTests.PrintToString_ShouldHandleListOfLists_Correctly.verified.txt
This file contains hidden or 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,9 @@ | ||
| List<List<Int32>> [ | ||
| List<Int32> [ | ||
| 1 | ||
| 2 | ||
| ] | ||
| List<Int32> [ | ||
| 3 | ||
| ] | ||
| ] |
5 changes: 5 additions & 0 deletions
5
...ectionPrintingSnapshotTests.PrintToString_ShouldHandleListWithNull_Correctly.verified.txt
This file contains hidden or 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,5 @@ | ||
| List<String> [ | ||
| null | ||
| null | ||
| null | ||
| ] |
4 changes: 4 additions & 0 deletions
4
...CollectionPrintingSnapshotTests.PrintToString_StringList_ShouldHandleCorrect.verified.txt
This file contains hidden or 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,4 @@ | ||
| List<String> [ | ||
| one | ||
| two | ||
| ] |
5 changes: 5 additions & 0 deletions
5
...tedResults/ObjectPrinterTests.PrintToString_ShouldApplyCultureInfo_Correctly.verified.txt
This file contains hidden or 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,5 @@ | ||
| A: | ||
| Name = null | ||
| Number = 0 | ||
| Price = 1234,56 | ||
| Id = 00000000-0000-0000-0000-000000000000 |
5 changes: 5 additions & 0 deletions
5
...interTests.PrintToString_ShouldApplyCustomSerializationForProperty_Correctly.verified.txt
This file contains hidden or 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,5 @@ | ||
| A: | ||
| Name = NAME=Alex | ||
| Number = 0 | ||
| Price = 0 | ||
| Id = 00000000-0000-0000-0000-000000000000 |
4 changes: 4 additions & 0 deletions
4
...lts/ObjectPrinterTests.PrintToString_ShouldExcludeSpecificProperty_Correctly.verified.txt
This file contains hidden or 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,4 @@ | ||
| A: | ||
| Name = Alex | ||
| Price = 0 | ||
| Id = 00000000-0000-0000-0000-000000000000 |
4 changes: 4 additions & 0 deletions
4
...ExpectedResults/ObjectPrinterTests.PrintToString_ShouldExcludeType_Correctly.verified.txt
This file contains hidden or 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,4 @@ | ||
| A: | ||
| Name = Alex | ||
| Number = 0 | ||
| Price = 0 |
11 changes: 11 additions & 0 deletions
11
...ults/ObjectPrinterTests.PrintToString_ShouldHandleCyclicReferences_Correctly.verified.txt
This file contains hidden or 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,11 @@ | ||
| B: | ||
| Data = A: | ||
| Name = Child | ||
| Number = 0 | ||
| Price = 0 | ||
| Id = 00000000-0000-0000-0000-000000000000 | ||
|
|
||
| Parent = B: | ||
| Data = null | ||
| Parent = <cyclic reference> | ||
|
|
1 change: 1 addition & 0 deletions
1
...tedResults/ObjectPrinterTests.PrintToString_ShouldHandleNullObject_Correctly.verified.txt
This file contains hidden or 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 @@ | ||
| null |
5 changes: 5 additions & 0 deletions
5
.../ExpectedResults/ObjectPrinterTests.PrintToString_ShouldTrimString_Correctly.verified.txt
This file contains hidden or 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,5 @@ | ||
| A: | ||
| Name = Alex | ||
| Number = 0 | ||
| Price = 0 | ||
| Id = 00000000-0000-0000-0000-000000000000 |
5 changes: 5 additions & 0 deletions
5
...ults/ObjectPrinterTests.PrintToString_ShouldUseCustomSerialization_Correctly.verified.txt
This file contains hidden or 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,5 @@ | ||
| A: | ||
| Name = null | ||
| Number = INT(42) | ||
| Price = 0 | ||
| Id = 00000000-0000-0000-0000-000000000000 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Стоит добавить тесты для граничных случаев (null-элементов, null-коллекций и т.д.)