예제 #1
0
 public void GivenACollectionOfSerializedBlogEntries_WhenTheCollectionIsRetrieved_ThenAllTheEntriesAreRetrieved()
 {
     MemoryStream stream1 = new MemoryStream();
     MemoryStream stream2 = new MemoryStream();
     var entry = new Post();
     var json = entry.SerializeToString();
     var data = Encoding.UTF8.GetBytes(json);
     stream1.Write(data, 0, data.Length);
     stream2.Write(data, 0, data.Length);
     var fileInfo1 = new Mock<IFileInfo>();
     fileInfo1.Setup(f => f.Open(FileMode.Open)).Returns(stream1);
     var fileInfo2 = new Mock<IFileInfo>();
     fileInfo2.Setup(f => f.Open(FileMode.Open)).Returns(stream2);
     var fileInfos = new List<IFileInfo> { fileInfo1.Object, fileInfo2.Object, };
     _directoryInfo.Setup(d => d.EnumerateFiles(It.IsAny<string>(), It.IsAny<string>())).Returns(fileInfos);
     var repository = new PostRepository(Path, _fileInfoFactory.Object, _directoryInfo.Object);
     var entities = repository.Entities;
     entities.Should().HaveCount(2);
 }
예제 #2
0
        public void WhenEntitiesAreRetrievedFromTheRepository_ThenAllEntitiesAreReturned()
        {
            var streams = new MemoryStream[] { new MemoryStream(), new MemoryStream(), new MemoryStream()};
            foreach (var stream in streams)
            {
                var p = new Post();
                var json = p.SerializeToString();
                var bytes = Encoding.UTF8.GetBytes(json);
                stream.Write(bytes, 0, bytes.Length);
            }
            _fileInfo.Setup(f => f.Open(FileMode.Open)).Returns(streams[0]);
            var fileInfo1 = new Mock<IFileInfo>();
            fileInfo1.Setup(f => f.Open(FileMode.Open)).Returns(streams[1]);
            var fileInfo2 = new Mock<IFileInfo>();
            fileInfo2.Setup(f => f.Open(FileMode.Open)).Returns(streams[2]);

            _directoryInfo.Setup(d => d.EnumerateFiles(It.IsAny<string>(), It.IsAny<string>()))
                          .Returns(new List<IFileInfo> { _fileInfo.Object, fileInfo1.Object, fileInfo2.Object });
            _fileInfoFactory.Setup(f => f.CreateFileInfo(It.IsAny<string>())).Returns(_fileInfo.Object);
            var posts = _repository.Entities;

            posts.Count().Should().Be(3);
            _repository.Dispose();
        }