Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Dary0302
Copy link

No description provided.

@@ -1,27 +1,71 @@
using NUnit.Framework;
using System;

This comment was marked as resolved.

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.

public PrintingConfig<TOwner> OriginalConfig { get; }
public MemberInfo? PropertyName { get; }

public PropertyPrintingConfig(PrintingConfig<TOwner> config)

This comment was marked as resolved.


public PrintingConfig<TOwner> Using(Func<TPropType, string> serializeFunc)
{
if (string.IsNullOrEmpty(PropertyName?.Name))

This comment was marked as resolved.

return OriginalConfig;
}

public PrintingConfig<TOwner> TrimmedToLength(int length)

This comment was marked as resolved.

namespace ObjectPrinting.Tests;

[TestFixture]
public class ObjectPrinterAcceptanceTests

This comment was marked as resolved.

return serializer.DynamicInvoke(obj)?.ToString()!;
}

if (type.IsPrimitive || type == typeof(string) || type == typeof(Guid))

This comment was marked as resolved.

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил такой тест, он успешно исключает этот тип

continue;
}

if (propertyTrim.TryGetValue(propertyName, out var trimLength) && propertyValue is string stringValue)

This comment was marked as resolved.

Copy link
Author

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.

var propertyType = propertyInfo.PropertyType;
var propertyName = propertyInfo.Name;

if (propertySerializers.TryGetValue(propertyName, out var propertySerializer))

This comment was marked as resolved.

public void Exclude_ExcludeType()
{
const string unexpectedName = nameof(Person.Name);
const string unexpectedSurname = nameof(Person.Name);

This comment was marked as resolved.

[TestCase(0)]
[TestCase(1)]
[TestCase(2)]
public void TrimmedTo_TrimmingName(int length)
Copy link

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.

return PrintToString(obj, 1);
}

private string PrintToString(object? obj, int nestingLevel)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что на счет обработки циклических ссылок между объектами?
Не увидел тестов на такое поведение

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetMaxNestingLevel_WithDifferentNestingLevels, а как же этот тест?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetMaxNestingLevel_WithDifferentNestingLevels, а как же этот тест?

Тут ты рекурсию обрабатываешь вызовов, я говорю про случай циклических ссылок, когда объект указывает сам на себя

Copy link

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.");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants