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

Code Coverage for DownloadFile Review 1St #12486

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
1cd54bf
Add NetwrokDownloadTests and WebListner
paul1956 Nov 14, 2024
bf912fe
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 15, 2024
1adf2be
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 19, 2024
af840f2
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 19, 2024
8f280c4
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 21, 2024
d1b4234
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 22, 2024
4e48605
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 23, 2024
1782915
Rename NetworkTests to DownloadTests
paul1956 Nov 24, 2024
10c1989
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 25, 2024
2d92096
Simplify dialog cancel
paul1956 Nov 26, 2024
4324b8b
Improve test coverage for Null or Empty network address
paul1956 Nov 26, 2024
ebdc88d
Dispose of HttpListener
paul1956 Nov 27, 2024
2718370
Fix formating
paul1956 Nov 28, 2024
175440a
Clean up formatting issues
paul1956 Nov 28, 2024
f1c6e65
Move download verifiers to separate file
paul1956 Nov 28, 2024
fa37a7b
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 28, 2024
fbd2c7c
Remove Imports Microsoft.VisualBasic.CompilerServices
paul1956 Nov 28, 2024
0baeb02
Fix error cause myy removal of Imports Microsoft.VisualBasic.Compiler…
paul1956 Nov 28, 2024
8977f10
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 6, 2024
7f51bcc
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 11, 2024
a9eb2f5
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 12, 2024
5b89c04
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 13, 2024
2b7303c
Fix behaviour cancel dialog behavior to match WebCleintDownload
paul1956 Dec 15, 2024
ffe7e35
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 15, 2024
db6bdf6
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 17, 2024
ccdf42b
Add UploadFile Tests
paul1956 Dec 17, 2024
7324bb1
Sort private variables
paul1956 Dec 17, 2024
65cbc86
Move WebListener.vb to TestUtilities Folder
paul1956 Dec 17, 2024
f3cc2d0
Formatting fixes
paul1956 Dec 17, 2024
cdab3aa
Fix formatting
paul1956 Dec 17, 2024
47f12cd
Correct messaages for ProgressDialog which calls wrong GetResourceStr…
paul1956 Dec 19, 2024
e3ce2e2
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 19, 2024
6a82523
Add more tests and check that files are properly uploaded with correc…
paul1956 Dec 19, 2024
2110608
Add char specifier to Inline single character strings
paul1956 Dec 19, 2024
a3ead0c
Fix some missing spaces
paul1956 Dec 19, 2024
41f8a19
Use PathSeparatorTestData
paul1956 Dec 20, 2024
73aa2cd
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 20, 2024
eb6ba5c
Fix order of functions
paul1956 Dec 20, 2024
a7b20cc
Minor formatting changes
paul1956 Dec 20, 2024
c633809
Update cooment for Cllipboard to restore changes lost in merge
paul1956 Dec 20, 2024
4f9d051
Cleanup NetworkUploadFile and consolidate is interactive
paul1956 Dec 20, 2024
354ccdf
Improve UploadFile and DownloadFile Tests
paul1956 Dec 20, 2024
468e669
Add SR strings from WebClient
paul1956 Dec 20, 2024
6e313e2
Fix error handling and add new strings for to replace WebClient
paul1956 Dec 20, 2024
b8de54b
Fix error handling
paul1956 Dec 20, 2024
70283e4
Improve WebListener
paul1956 Dec 22, 2024
0fa9cd3
Fix logic in WebListener return 500 for server errors
paul1956 Dec 22, 2024
a6413df
Sort new functions
paul1956 Dec 22, 2024
8449f48
Improve test server and test
paul1956 Dec 23, 2024
6e3b58e
Improve a couple of Skip comments
paul1956 Dec 23, 2024
d3e5523
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 23, 2024
ad1bab1
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 25, 2024
c67f9cf
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 2, 2025
758772a
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 6, 2025
ac82c9f
PR feedback
paul1956 Jan 8, 2025
e2ff073
PR Feedback Cleanup files in Separate PR
paul1956 Jan 8, 2025
5f956f4
Merge branch 'Cleanup-review-first' into Code-Coverage-DownloadFile-R…
paul1956 Jan 8, 2025
0b70c5d
Merge branch 'master' into Cleanup-review-first
paul1956 Jan 8, 2025
6f59c93
Merge branch 'Cleanup-review-first' into Code-Coverage-DownloadFile-R…
paul1956 Jan 8, 2025
a36b059
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 9, 2025
6509c30
Fix merge error
paul1956 Jan 9, 2025
395de61
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,22 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
Debug.Assert((Not String.IsNullOrWhiteSpace(destinationFileName)) _
AndAlso IO.Directory.Exists(path), $"Invalid {NameOf(path)}")

' If we have a dialog we need to set up an async download
If _progressDialog IsNot Nothing Then
_webClient.DownloadFileAsync(address, destinationFileName)
'returns when the download sequence is over, whether due to success, error, or being canceled
_progressDialog.ShowProgressDialog()
Else
_webClient.DownloadFile(address, destinationFileName)
End If
Try

' If we have a dialog we need to set up an async download
If _progressDialog IsNot Nothing Then
_webClient.DownloadFileAsync(address, destinationFileName)
'returns when the download sequence is over, whether due to success, error, or being canceled
_progressDialog.ShowProgressDialog()
Else
_webClient.DownloadFile(address, destinationFileName)
End If
Catch ex As WebException
If ex.Message.Contains("401") Then
Copy link
Member

Choose a reason for hiding this comment

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

It's usually good to keep the original exception for context. Why do we have to introduce our own messages? Can we set the original exception as the inner one?

Copy link
Member

Choose a reason for hiding this comment

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

THe same comment applies to the Upload method.

Copy link
Contributor Author

@paul1956 paul1956 Jan 8, 2025

Choose a reason for hiding this comment

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

My WebServerListner is implemented with HTTPClient, the existing code expects WebClient Errors. This code translates the errors, so they are compatible with existing code. When WebClient and WebClientCopy go away and upload and download use HTTPClient the same translation will happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WinForms only handle 2 specific Exceptions Timeout, Unauthorized plus a generic WebException.
When I run the existing code using WebClient I can get almost complete coverage of DownloadFile and UploadFile and the generic exception is never used. With HttpClient I handle the generic exception and use it for testing.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, we shouldn't add new exceptions for testing purposes only. New exceptions is a breaking change and we need an apparent benefit gained from making such a change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's usually good to keep the original exception for context. Why do we have to introduce our own messages? Can we set the original exception as the inner one?

@Tanya-Solyanik
We are reproducing WebClient Exceptions, HttpClient returns HttpErrors. From what I can tell WinForms only cares about 3 WebClient Exceptions (Timeout, Unauthorized and a generic catch all which is not used by WinForms today).

I have no visibility into all the errors that WebClient can possibly throw but WinForms works consistently with know and unknown errors.

The goal is no breaking exception changes.

Throw New WebException(SR.net_webstatus_Unauthorized)
End If
Throw New WebException(SR.net_webstatus_Timeout)
End Try

'Now that we are back on the main thread, throw the exception we encountered if the user didn't cancel.
If _exceptionEncounteredDuringFileTransfer IsNot Nothing Then
Expand All @@ -186,17 +194,26 @@ Namespace Microsoft.VisualBasic.MyServices.Internal
Debug.Assert(address IsNot Nothing, $"No {NameOf(address)}")
Debug.Assert((Not String.IsNullOrWhiteSpace(sourceFileName)) _
AndAlso IO.File.Exists(sourceFileName), "Invalid file")

' If we have a dialog we need to set up an async download
If _progressDialog IsNot Nothing Then
_webClient.UploadFileAsync(address, sourceFileName)

' Returns when the download sequence is over,
' whether due to success, error, or being canceled
_progressDialog.ShowProgressDialog()
Else
_webClient.UploadFile(address, sourceFileName)
End If
Try
' If we have a dialog we need to set up an async download
If _progressDialog IsNot Nothing Then
_webClient.UploadFileAsync(address, sourceFileName)

' Returns when the download sequence is over,
' whether due to success, error, or being canceled
_progressDialog.ShowProgressDialog()
Else
_webClient.UploadFile(address, sourceFileName)
End If
Catch ex As WebException
If ex.Message.Contains("401") Then
Throw New WebException(SR.net_webstatus_Unauthorized)
End If
If ex.Message.Contains("500") Then
Throw
End If
Throw New WebException(SR.net_webstatus_Timeout)
End Try

' Now that we are back on the main thread, throw the exception we
' encountered if the user didn't cancel.
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,10 @@
<data name="EnvVarNotFound_Name" xml:space="preserve">
<value>Environment variable is not defined: '{0}'.</value>
</data>
<data name="net_webstatus_Timeout" xml:space="preserve">
<value>The network operation has timed out.</value>
</data>
<data name="net_webstatus_Unauthorized" xml:space="preserve">
<value>The network operation is unauthorized.</value>
</data>
</root>
10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.cs.xlf

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

10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.de.xlf

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

10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.es.xlf

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

10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.fr.xlf

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

10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.it.xlf

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

10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.ja.xlf

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

10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.ko.xlf

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

10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.pl.xlf

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

10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.pt-BR.xlf

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

10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.ru.xlf

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

10 changes: 10 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/Resources/xlf/SR.tr.xlf

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

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

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

Loading