Hi to all..
Great day!
I would like to ask on How to Unit Test File Download in MVC 5 VB.NET ASP.NET using MOQ.
I searched already over the internet, but still didn't see any sample code.
Thank you in advance for your kind help.
Here's my repository code that need a unit testing (file download)
Public Function StatusAndLocking_GetFileByProjectAttachmentID(ID As Integer) _
As ProjectViewModel.StatusAndLockingEntity Implements IProjectRepository.StatusAndLocking_GetFileByProjectAttachmentID
Dim result As New ProjectViewModel.StatusAndLockingEntity
Dim anonymousIndex As IQueryable(Of Object) = Nothing
Using db As New SPIMS_Entities()
db.Database.Connection.ConnectionString = EFManager.GetConnectionString
Dim query = From paf In db.ProjectAttachmentFile
Join p In db.Project On paf.ProjectID Equals p.ID
Join pf In db.ProjectProfile On p.ProjectProfileID Equals pf.ID
Select
IDAlias = paf.ID, pf.Name, pf.GIMSNumber, AttachmentNameAlias = paf.Name, paf.SystemFile
anonymousIndex = query.Where(Function(p) p.IDAlias = ID).AsQueryable
result = MapToProjectViewModelEntity(anonymousIndex)
End Using
Return result
End Function
Here's my Controller code:
Function GetFileByProjectAttachmentID(ByVal id As Integer) As FileContentResult
Dim _repoProject As New ProjectRepository
Dim _projectAttachment As New ProjectViewModel.StatusAndLockingEntity
_projectAttachment = _repoProject.StatusAndLocking_GetFileByProjectAttachmentID(id)
Dim fileData As Byte() = _projectAttachment.SystemFile
Dim fileName As String = _projectAttachment.AttachmentName
Return File(fileData, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)
End Function