-
Notifications
You must be signed in to change notification settings - Fork 32
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
Рушкова Ольга #25
base: master
Are you sure you want to change the base?
Рушкова Ольга #25
Conversation
|
||
actualTsar.Should() | ||
.BeEquivalentTo(expectedTsar, options => options | ||
.Excluding(ctx => ctx.Path.EndsWith("Id"))); |
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.
А если добавим PetId, то тесты не будут это учитывать
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.
А если введем сущность "Родитель номер два" с помощью класса SecondParent, у которого так же будет Id?)
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.
В FluentAssertions точно есть то, что тебе поможет
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.
А если введем сущность "Родитель номер два" с помощью класса SecondParent, у которого так же будет Id?)
+
act | ||
.Should().Throw<ArgumentException>() | ||
.WithMessage("precision must be a non-negative number less or equal than precision"); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_ReturnsTrue_WhenPrecisionAndScaleMoreThanValueIntAndFracParts() | ||
{ | ||
var value = "0.0"; | ||
var validator = new NumberValidator(17, 2, true); | ||
|
||
IsValidNumber_ReturnsTrue(value, validator); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_ReturnsTrue_WhenValueIsIntegerAndHasLessDigitsThanPrecision() | ||
{ | ||
var value = "0"; | ||
var validator = new NumberValidator(17, 2, true); | ||
|
||
IsValidNumber_ReturnsTrue(value, validator); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_ReturnsTrue_WhenLengthIntPartAndFracPartEqualToPrecision_IncludingNumberSign() | ||
{ | ||
var value = "+1.23"; | ||
var validator = new NumberValidator(4, 2, true); | ||
|
||
IsValidNumber_ReturnsTrue(value, validator); | ||
} | ||
|
||
private void IsValidNumber_ReturnsTrue(string value, NumberValidator validator) | ||
{ | ||
var isValid = validator.IsValidNumber(value); | ||
|
||
isValid | ||
.Should().BeTrue(); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_ReturnsFalse_WhenNumberLengthMoreThanPrecision_IncludingSignForPositiveNumber() | ||
{ | ||
var value = "+1.23"; | ||
var validator = new NumberValidator(3, 2, true); | ||
|
||
IsValidNumber_ReturnsFalse(value, validator); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_ReturnsFalse_WhenNumberLengthMoreThanPrecision_IncludingSignForNegativeNumber() | ||
{ | ||
var value = "-1.23"; | ||
var validator = new NumberValidator(3, 2); | ||
|
||
IsValidNumber_ReturnsFalse(value, validator); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_ReturnsFalse_WhenValueFracPartMoreThanScale() | ||
{ | ||
var value = "0.000"; | ||
var validator = new NumberValidator(17, 2, true); | ||
|
||
IsValidNumber_ReturnsFalse(value, validator); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_ReturnsFalse_WhenValueContainsNonDigitSymbols() | ||
{ | ||
var value = "a.sd"; | ||
var validator = new NumberValidator(3, 2, true); | ||
|
||
IsValidNumber_ReturnsFalse(value, validator); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_ReturnsFalse_WhenValueSymbolsCountMoreThanPrecision() | ||
{ | ||
var value = "00.00"; | ||
var validator = new NumberValidator(3, 2, true); | ||
|
||
IsValidNumber_ReturnsFalse(value, validator); | ||
} | ||
|
||
[Test] | ||
public void IsValidNumber_ReturnsFalse_WhenValueNegative_WithOnlyPositiveNumberValidator() | ||
{ | ||
var value = "-0.00"; | ||
var validator = new NumberValidator(4, 2, true); | ||
|
||
IsValidNumber_ReturnsFalse(value, validator); | ||
} | ||
|
||
private void IsValidNumber_ReturnsFalse(string value, NumberValidator validator) | ||
{ | ||
var isValid = validator.IsValidNumber(value); | ||
|
||
isValid | ||
.Should().BeFalse(); |
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.
В задании в том числе надо своих тестов нагенерить.
У тебя принимается строка на вход, поэтому там куча всего может быть. Подумай какие еще тестовые данные мы не учли
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.
У тебя до сих пор тесты выглядят слишком похоже, за исключением аргументов и результата. Action во всех одинаковый. Предлагаю через TestCase'ы проверить положительные результаты, отрицательные результаты. А тесты с сепаратором, например, норм оставить как есть
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.
+
} | ||
|
||
[Test] | ||
public void NumberValidator_WhenPrecisionIsNegative_Fails() |
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.
Обычно прям и пишут типа NumberValidator_Throw_WhenPrecisionIsNegative
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.
+
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.
Тесты в рамках одного класса даже в разном формате именования
Не совсем поняла. Но я переименовала все тесты в формате ЧтоТестируется_ОжидаемыйРезультат_ПриКакихУсловиях
|
||
act | ||
.Should().Throw<ArgumentException>() | ||
.WithMessage("precision must be a positive number"); |
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.
+
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.
Тут я имел в виду, что Если ты хочешь тестировать сообщение, то вынести его в константу
Но вариант с "непроверкой" сообщения тоже норм
[TestCase("0.0", 17, 2, true, TestName = "IsValidNumber_ReturnsTrue_WhenPrecisionAndScaleMoreThanValueIntAndFracParts")] | ||
[TestCase("0,0", 3, 2, true, TestName = "IsValidNumber_ReturnsTrue_WhenSeparatorIsComma")] | ||
[TestCase("0", 17, 2, true, TestName = " IsValidNumber_ReturnsTrue_WhenValueIsIntegerAndHasLessDigitsThanPrecision")] | ||
[TestCase("12345", 5, 2, true, TestName = "IsValidNumber_ReturnsTrue_WhenValueIsIntegerAndDigitCountEqualsPrecision")] | ||
[TestCase("+1.23", 4, 2, true, TestName = "IsValidNumber_ReturnsTrue_WhenLengthIntPartAndFracPartEqualToPrecision_IncludingNumberSign")] | ||
[TestCase("-1.23", 5, 2, TestName = "IsValidNumber_ReturnsTrue_WhenValueIsNegativeAndValidatorNotOnlyPositive")] |
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.
IsValidNumber_ReturnsTrue_ можно даже убрать. У тебя будет глобально название IsValidNumber_ReturnsTrue, а дочернее название теста, например, WhenPrecisionAndScaleMoreThanValueIntAndFracParts
У меня в райдере это в виде дерева отображается.
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.
+
actualTsar.Should() | ||
.BeEquivalentTo(expectedTsar, options => options.Excluding(ctx => ComparePerson(ctx))); |
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.
В этом случае опять все ломается, если мы вводим поле PetId
//.Using<Person>(ctx => ctx.Subject | ||
// .Should().BeEquivalentTo(ctx.Expectation, opt => opt.Excluding(x => x.Id))).WhenTypeIs<Person>());s |
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 parentInfo = ctx.GetType() | ||
?.GetField("member", BindingFlags.NonPublic | BindingFlags.Instance) | ||
?.GetValue(ctx) as Field; |
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.
ctx.DeclaringType
?.GetField("member", BindingFlags.NonPublic | BindingFlags.Instance) | ||
?.GetValue(ctx) as Field; | ||
|
||
return parentInfo?.ParentType == typeof(Person) && ctx.Path.EndsWith("Id"); |
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.
ctx.Name == "Id"
No description provided.