Skip to content

Commit

Permalink
Fix timeout message to reflect that 0 is not allowed (#3279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Aug 2, 2024
1 parent c683317 commit 71a7f31
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 45 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Adapter/MSTest.TestAdapter/Resources/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Error: {1}</value>
<value>Method {0}.{1} has wrong signature. The method must be static, public, does not return a value and should take a single parameter of type TestContext. Additionally, if you are using async-await in method then return-type must be 'Task' or 'ValueTask'.</value>
</data>
<data name="UTA_ErrorInvalidTimeout" xml:space="preserve">
<value>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</value>
<value>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</value>
</data>
<data name="UTA_ErrorPredefinedTestProperty" xml:space="preserve">
<value>UTA023: {0}: Cannot define predefined property {2} on method {1}.</value>
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Chyba: {1}</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: {0}.{1} má neplatný atribut Timeout. Timeout musí být platné celé číslo a nesmí být menší než 0.</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: {0}.{1} má neplatný atribut Timeout. Timeout musí být platné celé číslo a nesmí být menší než 0.</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Fehler: {1}</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: "{0}.{1}" weist ein ungültiges Attribut "Timeout" auf. Das Timeout muss ein gültiger ganzzahliger Wert sein und darf nicht kleiner als 0 sein.</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: "{0}.{1}" weist ein ungültiges Attribut "Timeout" auf. Das Timeout muss ein gültiger ganzzahliger Wert sein und darf nicht kleiner als 0 sein.</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Error: {1}</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: atributo tiempo espera {0}.{1} no válido. Valor tiempo de espera debe ser entero válido y no menor que 0.</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: atributo tiempo espera {0}.{1} no válido. Valor tiempo de espera debe ser entero válido y no menor que 0.</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Erreur : {1}</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054 : {0}.{1} possède un attribut Timeout non valide. Timeout doit être une valeur entière valide, qui ne doit pas être inférieure à 0.</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054 : {0}.{1} possède un attribut Timeout non valide. Timeout doit être une valeur entière valide, qui ne doit pas être inférieure à 0.</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Errore: {1}</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: l'attributo Timeout di {0}.{1} non è valido. Il timeout deve essere un valore intero valido non minore di 0.</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: l'attributo Timeout di {0}.{1} non è valido. Il timeout deve essere un valore intero valido non minore di 0.</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ Error: {1}</source>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: {0}.{1} は無効な Timeout 属性を含んでいます。タイムアウトは有効な整数値でなければなりません。0 よりも小さい値にすることはできません。</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: {0}.{1} は無効な Timeout 属性を含んでいます。タイムアウトは有効な整数値でなければなりません。0 よりも小さい値にすることはできません。</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Error: {1}</source>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: {0}.{1}에 잘못된 Timeout 특성이 있습니다. Timeout은 유효한 정수 값이어야 하며 0보다 작을 수 없습니다.</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: {0}.{1}에 잘못된 Timeout 특성이 있습니다. Timeout은 유효한 정수 값이어야 하며 0보다 작을 수 없습니다.</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Błąd: {1}</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: {0}.{1} ma nieprawidłowy atrybut Timeout. Limit czasu musi być prawidłową liczbą całkowitą i nie może być mniejszy niż 0.</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: {0}.{1} ma nieprawidłowy atrybut Timeout. Limit czasu musi być prawidłową liczbą całkowitą i nie może być mniejszy niż 0.</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Erro: {1}</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: {0}.{1} tem atributo Timeout inválido. O tempo limite deve ser um valor inteiro válido e não pode ser menor que 0.</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: {0}.{1} tem atributo Timeout inválido. O tempo limite deve ser um valor inteiro válido e não pode ser menor que 0.</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Error: {1}</source>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: {0}.{1} имеет недопустимый атрибут Timeout. Время ожидания должно быть допустимым целым числом и не может быть меньше 0.</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: {0}.{1} имеет недопустимый атрибут Timeout. Время ожидания должно быть допустимым целым числом и не может быть меньше 0.</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Hata: {1}</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: {0}.{1} geçersiz Timeout özniteliğine sahip. Zaman aşımı geçerli bir tamsayı değer olmalıdır ve 0'dan küçük olamaz.</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: {0}.{1} geçersiz Timeout özniteliğine sahip. Zaman aşımı geçerli bir tamsayı değer olmalıdır ve 0'dan küçük olamaz.</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Error: {1}</source>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: {0}.{1} 具有无效的 Timeout 特性。超时值必须是有效的整数值而且不能小于 0。</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: {0}.{1} 具有无效的 Timeout 特性。超时值必须是有效的整数值而且不能小于 0。</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ Error: {1}</source>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorInvalidTimeout">
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.</source>
<target state="translated">UTA054: {0}.{1} 中具有無效的 Timeout 屬性。逾時值必須是有效的整數值,而且不可小於 0。</target>
<note></note>
<source>UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.</source>
<target state="needs-review-translation">UTA054: {0}.{1} 中具有無效的 Timeout 屬性。逾時值必須是有效的整數值,而且不可小於 0。</target>
<note />
</trans-unit>
<trans-unit id="UTA_ErrorPredefinedTestProperty">
<source>UTA023: {0}: Cannot define predefined property {2} on method {1}.</source>
Expand Down
43 changes: 39 additions & 4 deletions test/UnitTests/MSTestAdapter.UnitTests/Execution/TypeCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,10 @@ public void GetTestMethodInfoShouldReturnTestMethodInfoWithTimeout()
Verify(testMethodInfo.TestMethodOptions.Executor is not null);
}

public void GetTestMethodInfoShouldThrowWhenTimeoutIsIncorrect()
public void GetTestMethodInfoShouldThrowWhenTimeoutIsNegative()
{
Type type = typeof(DummyTestClassWithTestMethods);
MethodInfo methodInfo = type.GetMethod("TestMethodWithIncorrectTimeout");
MethodInfo methodInfo = type.GetMethod("TestMethodWithNegativeTimeout");
var testMethod = new TestMethod(methodInfo.Name, type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(rh => rh.IsNonDerivedAttributeDefined<UTF.TimeoutAttribute>(methodInfo, false))
Expand All @@ -939,7 +939,36 @@ void A() => _typeCache.GetTestMethodInfo(
string expectedMessage =
string.Format(
CultureInfo.InvariantCulture,
"UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be a valid integer value and cannot be less than 0.",
"UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.",
testMethod.FullClassName,
testMethod.Name);

Verify(expectedMessage == exception.Message);
}

public void GetTestMethodInfoShouldThrowWhenTimeoutIsZero()
{
Type type = typeof(DummyTestClassWithTestMethods);
MethodInfo methodInfo = type.GetMethod("TestMethodWithTimeoutOfZero");
var testMethod = new TestMethod(methodInfo.Name, type.FullName, "A", isAsync: false);

_mockReflectHelper.Setup(rh => rh.IsNonDerivedAttributeDefined<UTF.TimeoutAttribute>(methodInfo, false))
.Returns(true);

void A() => _typeCache.GetTestMethodInfo(
testMethod,
new TestContextImplementation(testMethod, new ThreadSafeStringWriter(null, "test"), new Dictionary<string, object>()),
false);

Exception exception = VerifyThrows(A);

Verify(exception is not null);
Verify(exception is TypeInspectionException);

string expectedMessage =
string.Format(
CultureInfo.InvariantCulture,
"UTA054: {0}.{1} has invalid Timeout attribute. The timeout must be an integer value greater than 0.",
testMethod.FullClassName,
testMethod.Name);

Expand Down Expand Up @@ -1413,7 +1442,13 @@ public void TestMethodWithTimeout()

[UTF.TestMethod]
[UTF.Timeout(-10)]
public void TestMethodWithIncorrectTimeout()
public void TestMethodWithNegativeTimeout()
{
}

[UTF.TestMethod]
[UTF.Timeout(0)]
public void TestMethodWithTimeoutOfZero()
{
}

Expand Down

0 comments on commit 71a7f31

Please sign in to comment.