-
Notifications
You must be signed in to change notification settings - Fork 245
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
Дмитрий Леонтьев #221
base: master
Are you sure you want to change the base?
Дмитрий Леонтьев #221
Conversation
@@ -1,27 +1,71 @@ | |||
using NUnit.Framework; | |||
using System; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
ObjectPrinting/PrintingConfig.cs
Outdated
public class PrintingConfig<TOwner> | ||
public int MaxNestingLevel { get; set; } = 5; | ||
private readonly HashSet<Type> excludeTypes = new(ReferenceEqualityComparer.Instance); | ||
private readonly HashSet<string> excludeProperties = []; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
public PrintingConfig<TOwner> OriginalConfig { get; } | ||
public MemberInfo? PropertyName { get; } | ||
|
||
public PropertyPrintingConfig(PrintingConfig<TOwner> config) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
||
public PrintingConfig<TOwner> Using(Func<TPropType, string> serializeFunc) | ||
{ | ||
if (string.IsNullOrEmpty(PropertyName?.Name)) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
return OriginalConfig; | ||
} | ||
|
||
public PrintingConfig<TOwner> TrimmedToLength(int length) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
namespace ObjectPrinting.Tests; | ||
|
||
[TestFixture] | ||
public class ObjectPrinterAcceptanceTests |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
return serializer.DynamicInvoke(obj)?.ToString()!; | ||
} | ||
|
||
if (type.IsPrimitive || type == typeof(string) || type == typeof(Guid)) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
А мы их выше обработаем, нет?
if (serializersToType.TryGetValue(type, out var serializer)) { return serializer.DynamicInvoke(obj)?.ToString()!; }
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
Добавил такой тест, он успешно исключает этот тип
ObjectPrinting/PrintingConfig.cs
Outdated
continue; | ||
} | ||
|
||
if (propertyTrim.TryGetValue(propertyName, out var trimLength) && propertyValue is string stringValue) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
Тогда вопрос, а в каком порядке нужно будет обрабатывать значение?
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
ObjectPrinting/PrintingConfig.cs
Outdated
var propertyType = propertyInfo.PropertyType; | ||
var propertyName = propertyInfo.Name; | ||
|
||
if (propertySerializers.TryGetValue(propertyName, out var propertySerializer)) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
public void Exclude_ExcludeType() | ||
{ | ||
const string unexpectedName = nameof(Person.Name); | ||
const string unexpectedSurname = nameof(Person.Name); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
[TestCase(0)] | ||
[TestCase(1)] | ||
[TestCase(2)] | ||
public void TrimmedTo_TrimmingName(int length) |
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.
(optional) Еще так можно [Values(0, 1, 2)] int length
FluentActions.Invoking(() => ObjectPrinter.For<Person>() | ||
.SetMaxNestingLevel(levelNesting)) | ||
.Should().Throw<ArgumentException>() | ||
.WithMessage("Max nesting level must be greater than or equal to 0."); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
return PrintToString(obj, 1); | ||
} | ||
|
||
private string PrintToString(object? obj, int nestingLevel) |
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.
SetMaxNestingLevel_WithDifferentNestingLevels, а как же этот тест?
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.
SetMaxNestingLevel_WithDifferentNestingLevels, а как же этот тест?
Тут ты рекурсию обрабатываешь вызовов, я говорю про случай циклических ссылок, когда объект указывает сам на себя
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.
Нашел баг. Пишем что циклическая ссылка, если это не циклическая ссылка))
Пример теста который сейчас не проходит:
var result = ObjectPrinter.For<List<Person>>()
.PrintToString([firstPerson, firstPerson]);
result.Should().NotContain("It is not possible to print an object with a circular reference.");
…ultiple serializations for the same type
No description provided.