public void ExecuteGeneratesDownload() { var fileName = "nameOfDaFile"; var label = "daLabel"; var stream = new MemoryStream(new byte[0]); var transfer = new RemotingFileTransfer(stream); var farmService = this.mocks.Create <IFarmService>(MockBehavior.Strict).Object; var action = new ProjectFileDownload(farmService); var cruiseRequest = this.mocks.Create <ICruiseRequest>(MockBehavior.Strict).Object; var request = this.mocks.Create <IRequest>(MockBehavior.Strict).Object; var projectSpec = this.mocks.Create <IProjectSpecifier>(MockBehavior.Strict).Object; Mock.Get(cruiseRequest).SetupGet(_cruiseRequest => _cruiseRequest.Request).Returns(request); Mock.Get(cruiseRequest).SetupGet(_cruiseRequest => _cruiseRequest.ProjectSpecifier).Returns(projectSpec); Mock.Get(cruiseRequest).Setup(_cruiseRequest => _cruiseRequest.RetrieveSessionToken()).Returns((string)null); Mock.Get(request).Setup(_request => _request.GetText("file")).Returns(fileName); Mock.Get(request).Setup(_request => _request.GetText("label")).Returns(label); Mock.Get(farmService).Setup(_farmService => _farmService.RetrieveFileTransfer(projectSpec, System.IO.Path.Combine(label, fileName), null)).Returns(transfer); var response = action.Execute(cruiseRequest); mocks.VerifyAll(); Assert.IsInstanceOf <FileTransferResponse>(response); var actual = response as FileTransferResponse; Assert.AreEqual(fileName, actual.FileName); Assert.AreSame(transfer, actual.FileTransfer); }
public void ExecuteGeneratesDownload() { var fileName = "nameOfDaFile"; var label = "daLabel"; var stream = new MemoryStream(new byte[0]); var transfer = new RemotingFileTransfer(stream); var farmService = this.mocks.StrictMock <IFarmService>(); var action = new ProjectFileDownload(farmService); var cruiseRequest = this.mocks.StrictMock <ICruiseRequest>(); var request = this.mocks.StrictMock <IRequest>(); var projectSpec = this.mocks.StrictMock <IProjectSpecifier>(); SetupResult.For(cruiseRequest.Request).Return(request); SetupResult.For(cruiseRequest.ProjectSpecifier).Return(projectSpec); SetupResult.For(cruiseRequest.RetrieveSessionToken()).Return(null); SetupResult.For(request.GetText("file")).Return(fileName); SetupResult.For(request.GetText("label")).Return(label); SetupResult.For(farmService.RetrieveFileTransfer(projectSpec, label + "\\" + fileName, null)).Return(transfer); mocks.ReplayAll(); var response = action.Execute(cruiseRequest); mocks.VerifyAll(); Assert.IsInstanceOf <FileTransferResponse>(response); var actual = response as FileTransferResponse; Assert.AreEqual(fileName, actual.FileName); Assert.AreSame(transfer, actual.FileTransfer); }