-
Notifications
You must be signed in to change notification settings - Fork 252
Сахабутдинов Ильфир #211
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
ILFirV-V
wants to merge
11
commits into
kontur-courses:master
Choose a base branch
from
ILFirV-V:request-branch
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
Сахабутдинов Ильфир #211
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
87fc4eb
Add. Решение 4 домашней работы
c690fba
Update. Рефакторинг кода
0a5c42b
Fix. Обновление тестов по полученным замечаниям
1adc983
Fix. Исправление небольших замечаний
08a843a
Update. Изменения тестов дял разделение логики сериализации и конфигу…
c8fe4bf
Fix. Разделение логики сериализации и конфигурации
9b8b71b
Fix. Разделение настроек культуры и сериализации
abc037e
Fix. Вернул необходимые проверки перед добавлением альтернативного сп…
c32e92a
Update. Выделение логики сериализации в отдельный класс
a80092e
Update. Изменение тестов перед изменением способа настроек сериализации
f37b491
Fix. Изменение способа конфигурирования перед сериализацией
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 |
|---|---|---|
| @@ -0,0 +1,282 @@ | ||
| using System.Globalization; | ||
| using ObjectPrinting.Extensions; | ||
| using ObjectPrinting.Tests.TestObjects; | ||
|
|
||
| namespace ObjectPrinting.Tests | ||
| { | ||
| [TestFixture] | ||
| public class ObjectPrinterAcceptanceTests | ||
| { | ||
| private static readonly VerifySettings settings = new(); | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| settings.UseDirectory("TestResults"); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task TestObjectPrinter_ExcludingTypes_CustomSerialization_Culture_Trimming() | ||
| { | ||
| var person = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
| person.TestObject = person; | ||
|
|
||
| var printer = ObjectPrinter.For<PrintingTestObject>() | ||
| .Excluding<Guid>() | ||
| .Printing<int>().Using(i => i.ToString("X")) | ||
| .Printing<double>().Using(CultureInfo.InvariantCulture) | ||
| .Printing(p => p.TestString).TrimmedToLength(10) | ||
| .Excluding(p => p.TestInt); | ||
|
|
||
| var printedString = printer.PrintToString(person); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task TestDefaultSerialization_ExtensionMethod() | ||
| { | ||
| var person = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
|
|
||
| var printedString = person.PrintToString(); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task TestConfiguredSerialization_ExtensionMethod() | ||
| { | ||
| var person = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
|
|
||
| var printedString = person.PrintToString(s => s.Excluding(p => p.TestString)); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintNull_Should_NullString() | ||
| { | ||
| var printedString = ObjectPrinter.For<PrintingTestObject>().PrintToString(null); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task ExcludingProperty_Should_IgnoresSpecifiedProperty() | ||
| { | ||
| var testObject = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .Excluding(o => o.TestInt) | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task ExcludingType_Should_IgnoresSpecifiedType() | ||
| { | ||
| var testObject = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .Excluding<string>() | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task UsingCustomSerialization_Should_AppliesCustomFunction() | ||
| { | ||
| var testObject = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .Printing(x => x.TestInt).Using(x => $"{x} years") | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task UsingCustomSerializationForType_Should_AppliesCustomFunctionToAllTypeProperties() | ||
| { | ||
| var testObject = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .Printing<int>().Using(x => $"{x} is int") | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task UsingCommonCulture_Should_UsesSpecifiedCulture() | ||
| { | ||
| const double testDouble = 1.5; | ||
| const float testFloat = 2.5f; | ||
| var culture = CultureInfo.GetCultureInfo("en-US"); | ||
| var testObject = new PrintingTestObject {TestDouble = testDouble, TestFloat = testFloat}; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .UsingCommonCulture(culture) | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task UsingCultureForType_Should_UsesSpecifiedCultureForSpecifiedType() | ||
| { | ||
| const double testDouble = 1.5; | ||
| const float testFloat = 2.5f; | ||
| var culture = CultureInfo.GetCultureInfo("en-Us"); | ||
| var testObject = new PrintingTestObject {TestDouble = testDouble, TestFloat = testFloat}; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .Printing<double>().Using(culture) | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task TrimmingStringLength_Should_TrimsToStringLength() | ||
| { | ||
| var testObject = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .Printing(o => o.TestString).TrimmedToLength(1) | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("Alex", 4, TestName = "LenEqualsStringLength")] | ||
| [TestCase("Alex", 5, TestName = "LenMoreStringLength")] | ||
| public Task TrimmingStringLength_Should_NotTrims(string testString, int maxLength) | ||
| { | ||
| var testObject = new PrintingTestObject {TestString = testString, TestInt = 19}; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .Printing(o => o.TestString).TrimmedToLength(maxLength) | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintCircularReference_Should_PrintsMessage() | ||
| { | ||
| var testObject = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
| testObject.TestObject = testObject; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintNonCircularReference_Should_PrintsNormally() | ||
| { | ||
| var firstTestObject = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
| var secondTestObject = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
| firstTestObject.TestObject = secondTestObject; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .PrintToString(firstTestObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintArray_Should_AllItems() | ||
| { | ||
| var testObject = new PrintingTestObject | ||
| { | ||
| TestString = "Alex", | ||
| TestInt = 19, | ||
| TestArray = ["Item1", "Item2", "Item3"] | ||
| }; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintList_Should_AllItems() | ||
| { | ||
| var testList = new List<object> {"ListItem1", "ListItem2", "ListItem3"}; | ||
| var testObject = new PrintingTestObject | ||
| { | ||
| TestString = "Alex", | ||
| TestInt = 19, | ||
| TestList = testList | ||
| }; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintDictionary_Should_AllItemsWithKeys() | ||
| { | ||
| var testDictionary = new Dictionary<string, object> | ||
| { | ||
| {"Key1", 1}, | ||
| {"Key2", 2}, | ||
| {"Key3", 3} | ||
| }; | ||
| var testObject = new PrintingTestObject | ||
| { | ||
| TestString = "Alex", | ||
| TestInt = 19, | ||
| TestDictionary = testDictionary | ||
| }; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>() | ||
| .PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task TestPrimitiveTypes() | ||
| { | ||
| var testObject = new PrimitiveTypesTestObject | ||
| { | ||
| BoolValue = true, | ||
| ByteValue = 255, | ||
| ShortValue = 32767, | ||
| IntValue = 2147483647, | ||
| LongValue = 9223372036854775807, | ||
| DecimalValue = 123.45m, | ||
| DoubleValue = 123.45, | ||
| FloatValue = 123.45f, | ||
| CharValue = 'A', | ||
| }; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrimitiveTypesTestObject>().PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
|
|
||
| [Test] | ||
| public Task PrintCircularReference_Should_HandleMultipleReferences() | ||
| { | ||
| var testObject = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
| var otherObject = new PrintingTestObject {TestString = "Alex", TestInt = 19}; | ||
| testObject.TestObject = otherObject; | ||
| otherObject.TestObject = testObject; | ||
|
|
||
| var printedString = ObjectPrinter.For<PrintingTestObject>().PrintToString(testObject); | ||
|
|
||
| return Verify(printedString, settings); | ||
| } | ||
| } | ||
| } | ||
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,31 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
| <IsTestProject>true</IsTestProject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> | ||
| <PackageReference Include="NUnit" Version="4.2.2" /> | ||
| <PackageReference Include="NUnit.Analyzers" Version="4.4.0"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="4.6.0" /> | ||
| <PackageReference Include="Verify.NUnit" Version="28.4.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Using Include="NUnit.Framework"/> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\ObjectPrinting\ObjectPrinting.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
14 changes: 14 additions & 0 deletions
14
ObjectPrinting.Tests/TestObjects/PrimitiveTypesTestObject.cs
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,14 @@ | ||
| namespace ObjectPrinting.Tests.TestObjects; | ||
|
|
||
| public class PrimitiveTypesTestObject | ||
| { | ||
| public bool BoolValue { get; set; } | ||
| public byte ByteValue { get; set; } | ||
| public short ShortValue { get; set; } | ||
| public int IntValue { get; set; } | ||
| public double DoubleValue { get; set; } | ||
| public double FloatValue { get; set; } | ||
| public long LongValue { get; set; } | ||
| public decimal DecimalValue { get; set; } | ||
| public char CharValue { 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,14 @@ | ||
| namespace ObjectPrinting.Tests.TestObjects; | ||
|
|
||
| public class PrintingTestObject | ||
| { | ||
| public Guid TestId { get; set; } | ||
| public string TestString { get; set; } | ||
| public double TestDouble { get; set; } | ||
| public float TestFloat { get; set; } | ||
| public int TestInt { get; set; } | ||
| public object TestObject { get; set; } | ||
| public Dictionary<string, object> TestDictionary { get; set; } | ||
| public List<object> TestList { get; set; } | ||
| public object[] TestArray { get; set; } | ||
| } |
9 changes: 9 additions & 0 deletions
9
...jectPrinterAcceptanceTests.ExcludingProperty_Should_IgnoresSpecifiedProperty.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 @@ | ||
| PrintingTestObject | ||
| TestId = 00000000-0000-0000-0000-000000000000 | ||
| TestString = Alex | ||
| TestDouble = 0 | ||
| TestFloat = 0 | ||
| TestObject = null | ||
| TestDictionary = null | ||
| TestList = null | ||
| TestArray = null |
9 changes: 9 additions & 0 deletions
9
...sults/ObjectPrinterAcceptanceTests.ExcludingType_Should_IgnoresSpecifiedType.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 @@ | ||
| PrintingTestObject | ||
| TestId = 00000000-0000-0000-0000-000000000000 | ||
| TestDouble = 0 | ||
| TestFloat = 0 | ||
| TestInt = 19 | ||
| TestObject = null | ||
| TestDictionary = null | ||
| TestList = null | ||
| TestArray = null |
15 changes: 15 additions & 0 deletions
15
...ng.Tests/TestResults/ObjectPrinterAcceptanceTests.PrintArray_Should_AllItems.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,15 @@ | ||
| PrintingTestObject | ||
| TestId = 00000000-0000-0000-0000-000000000000 | ||
| TestString = Alex | ||
| TestDouble = 0 | ||
| TestFloat = 0 | ||
| TestInt = 19 | ||
| TestObject = null | ||
| TestDictionary = null | ||
| TestList = null | ||
| TestArray = | ||
| [ | ||
| Item1 | ||
| Item2 | ||
| Item3 | ||
| ] |
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.
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.
Переписал с использованием Verify.NUnit, добавил тестов