-
-
Notifications
You must be signed in to change notification settings - Fork 979
Expand file tree
/
Copy pathServiceFactoryTest_CreateSftpFileReader_FileSizeIsZero.cs
More file actions
101 lines (87 loc) · 3.46 KB
/
ServiceFactoryTest_CreateSftpFileReader_FileSizeIsZero.cs
File metadata and controls
101 lines (87 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Renci.SshNet.Abstractions;
using Renci.SshNet.Sftp;
using Renci.SshNet.Tests.Common;
namespace Renci.SshNet.Tests.Classes
{
[TestClass]
public class ServiceFactoryTest_CreateSftpFileReader_FileSizeIsZero
{
private ServiceFactory _serviceFactory;
private Mock<ISftpSession> _sftpSessionMock;
private Mock<ISftpFileReader> _sftpFileReaderMock;
private uint _bufferSize;
private string _fileName;
private SftpOpenAsyncResult _openAsyncResult;
private byte[] _handle;
private SFtpStatAsyncResult _statAsyncResult;
private uint _chunkSize;
private long _fileSize;
private SftpFileAttributes _fileAttributes;
private ISftpFileReader _actual;
private void SetupData()
{
var random = new Random();
_bufferSize = (uint)random.Next(1, int.MaxValue);
_openAsyncResult = new SftpOpenAsyncResult(null, null);
_handle = CryptoAbstraction.GenerateRandom(random.Next(1, 10));
_statAsyncResult = new SFtpStatAsyncResult(null, null);
_fileName = random.Next().ToString();
_chunkSize = (uint)random.Next(1, int.MaxValue);
_fileSize = 0L;
_fileAttributes = new SftpFileAttributesBuilder().WithSize(_fileSize).Build();
}
private void CreateMocks()
{
_sftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);
_sftpFileReaderMock = new Mock<ISftpFileReader>(MockBehavior.Strict);
}
private void SetupMocks()
{
var seq = new MockSequence();
_sftpSessionMock.InSequence(seq)
.Setup(p => p.BeginOpen(_fileName, Flags.Read, null, null))
.Returns(_openAsyncResult);
_sftpSessionMock.InSequence(seq)
.Setup(p => p.EndOpen(_openAsyncResult))
.Returns(_handle);
_sftpSessionMock.InSequence(seq)
.Setup(p => p.BeginLStat(_fileName, null, null))
.Returns(_statAsyncResult);
_sftpSessionMock.InSequence(seq)
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
.Returns(_chunkSize);
_sftpSessionMock.InSequence(seq)
.Setup(p => p.EndLStat(_statAsyncResult))
.Returns(_fileAttributes);
_sftpSessionMock.InSequence(seq)
.Setup(p => p.CreateFileReader(_handle, _sftpSessionMock.Object, _chunkSize, 1, _fileSize, 0))
.Returns(_sftpFileReaderMock.Object);
}
private void Arrange()
{
SetupData();
CreateMocks();
SetupMocks();
_serviceFactory = new ServiceFactory();
}
[TestInitialize]
public void Initialize()
{
Arrange();
Act();
}
private void Act()
{
_actual = _serviceFactory.CreateSftpFileReader(_fileName, _sftpSessionMock.Object, _bufferSize);
}
[TestMethod]
public void CreateSftpFileReaderShouldReturnCreatedInstance()
{
Assert.IsNotNull(_actual);
Assert.AreSame(_sftpFileReaderMock.Object, _actual);
}
}
}