public void TestParseFile_ReturnsValues() { const string input = @"{ ""file"": [ ""test1.html"", ""test2.html"" ], ""template"": [""templates/**.html""], ""content"": [""**.html""] } "; var fileSystem = new InMemoryFileSystem(new[] { "test1.html", "test2.html", "templates/tmpl1.html", "templates/tmpl2.html", "content.html" }); var result = Project.FromFile(input, fileSystem); Assert.NotNull(result); var items = result.GetItems(); Assert.NotNull(items); var list = items.ToList(); Assert.Equal(9, list.Count); AssertFileItem(list[0], "file", "test1.html"); AssertFileItem(list[1], "file", "test2.html"); AssertFileItem(list[2], "template", "templates/tmpl1.html"); AssertFileItem(list[3], "template", "templates/tmpl2.html"); AssertFileItem(list[4], "content", "test1.html"); }
public void TestParseFile_AcceptsArrayOrSingleItem() { const string input = @"{ ""file"": [ ""test1.html"", ""test2.html"" ], ""singleFile"": ""templates/tmpl1.html"" } "; var fileSystem = new InMemoryFileSystem(new[] { "test1.html", "test2.html", "templates/tmpl1.html", "templates/tmpl2.html", "content.html" }); var result = Project.FromFile(input, fileSystem); Assert.NotNull(result); var items = result.GetItems(); Assert.NotNull(items); var list = items.ToList(); Assert.Equal(3, list.Count); AssertFileItem(list[0], "file", "test1.html"); AssertFileItem(list[1], "file", "test2.html"); AssertFileItem(list[2], "singleFile", "templates/tmpl1.html"); }
public void AttributesVmfs() { DiscFileSystem fs = new InMemoryFileSystem(); using (Disk disk = Disk.Initialize(fs, "a.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.VmfsSparse)) { Stream s = disk.Content; Assert.IsTrue(s.CanRead); Assert.IsTrue(s.CanWrite); Assert.IsTrue(s.CanSeek); } }
protected void given_file_system(string currentDirectory) { FileSystem = new InMemoryFileSystem { CurrentDirectory = currentDirectory }; ServiceLocator.RegisterService<IFileSystem>(FileSystem); Environment = new InMemoryEnvironment(FileSystem.GetDirectory(currentDirectory), FileSystem.GetDirectory(DefaultInstallationPaths.ConfigurationDirectory)); ServiceLocator.RegisterService<IEnvironment>(Environment); }
protected void given_file_system(string currentDirectory, params InMemoryDirectory[] directories) { FileSystem = new InMemoryFileSystem(directories) { CurrentDirectory = currentDirectory }; WrapServices.RegisterService<IFileSystem>(FileSystem); Environment = new InMemoryEnvironment(FileSystem.GetDirectory(currentDirectory), FileSystem.GetDirectory(InstallationPaths.ConfigurationDirectory)); WrapServices.RegisterService<IEnvironment>(Environment); }
public void ShouldSaveRecentEventsFeedToCurrentDirectory() { RecentEventsFeed recentEventsFeed = new RecentEventsFeedBuilder().WithNumberOfEntries(RecentEventsFeed.Quota - 1).WithId(11).Build(); InMemoryFileSystem fileSystem = new InMemoryFileSystem(); Assert.AreEqual(0, fileSystem.FileCount(fileSystem.CurrentDirectory)); ITask start = new SavingRecentEventsFeed(recentEventsFeed); start.Execute(fileSystem, new EventBufferBuilder().Build(), new FeedBuilder(SampleLinks.Instance), (args => { })); Assert.AreEqual(1, fileSystem.FileCount(fileSystem.CurrentDirectory)); }
public void ShouldSaveArchivedVersionOfRecentEventsFeedToArchiveDirectory() { InMemoryFileSystem fileSystem = new InMemoryFileSystem(); Assert.False(fileSystem.FileExists(fileSystem.ArchiveDirectory, new FileName("11.atom"))); IEnumerable<Event> events = new [] { new EventBuilder().Build()}; RecentEventsFeed recentEventsFeed = new RecentEventsFeedBuilder().WithNumberOfEntries(RecentEventsFeed.Quota).WithId(11).Build(); ITask start = new ArchivingRecentEventsFeed(recentEventsFeed, events); start.Execute(fileSystem, new EventBufferBuilder().Build(), new FeedBuilder(SampleLinks.Instance), (args => { })); Assert.True(fileSystem.FileExists(fileSystem.ArchiveDirectory, new FileName("11.atom"))); }
public void InitializeDifferencingRelPath() { DiscFileSystem fs = new InMemoryFileSystem(); DiskImageFile baseFile = DiskImageFile.Initialize(fs, @"\dir\subdir\base.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.MonolithicSparse); using (Disk disk = Disk.InitializeDifferencing(fs, @"\dir\diff.vmdk", DiskCreateType.MonolithicSparse, @"subdir\base.vmdk")) { Assert.IsNotNull(disk); Assert.That(disk.Geometry.Capacity > 15.8 * 1024L * 1024 * 1024 && disk.Geometry.Capacity < 16 * 1024L * 1024 * 1024); Assert.That(disk.Content.Length == 16 * 1024L * 1024 * 1024); Assert.AreEqual(2, new List<VirtualDiskLayer>(disk.Layers).Count); } Assert.Greater(fs.GetFileLength(@"\dir\diff.vmdk"), 2 * 1024 * 1024); Assert.Less(fs.GetFileLength(@"\dir\diff.vmdk"), 4 * 1024 * 1024); }
public void DisposeTest() { Stream contentStream; DiscFileSystem fs = new InMemoryFileSystem(); using (Disk disk = Disk.Initialize(fs, "a.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.TwoGbMaxExtentSparse)) { contentStream = disk.Content; } try { contentStream.Position = 0; Assert.Fail(); } catch(ObjectDisposedException) { } }
public void ShouldSaveFeedToCurrentDirectory() { InMemoryFileSystem fileSystem = new InMemoryFileSystem(); RecentEventsFeed recentEventsFeed = new RecentEventsFeedBuilder().WithId(2).WithPreviousId(1).WithUris(SampleLinks.Instance).Build(); Assert.AreEqual(0, fileSystem.FileCount(fileSystem.CurrentDirectory)); recentEventsFeed.Save(fileSystem); Assert.AreEqual(1, fileSystem.FileCount(fileSystem.CurrentDirectory)); SyndicationFeed feed = recentEventsFeed.GetSyndicationFeed(); SyndicationFeed rehydratedFeed = SyndicationFeed.Load(fileSystem.CurrentDirectory.GetXmlReader(recentEventsFeed.GetFeedMapping().GetFileName())); Assert.AreEqual(feed.Id, rehydratedFeed.Id); Assert.AreEqual(feed.Items.Count(), rehydratedFeed.Items.Count()); Assert.AreEqual(feed.GetSelfLink().GetAbsoluteUri(), rehydratedFeed.GetSelfLink().GetAbsoluteUri()); Assert.AreEqual(feed.GetViaLink().GetAbsoluteUri(), rehydratedFeed.GetViaLink().GetAbsoluteUri()); Assert.AreEqual(feed.GetPrevArchiveLink().GetAbsoluteUri(), rehydratedFeed.GetPrevArchiveLink().GetAbsoluteUri()); }
public void IfRecentEventsFeedExistsOnFileSystemTransitionsToUpdatingRecentEventsFeed() { int eventCount = 2; IFileSystem fileSystem = new InMemoryFileSystem(); SyndicationFeed feed = SyndicationFeeds.Current(); using (XmlWriter writer = fileSystem.CurrentDirectory.GetXmlWriter(FileName.TempFileName())) { feed.SaveAsAtom10(writer); } EventBuffer buffer = new EventBufferBuilder().WithNumberOfEvents(eventCount).Build(); ITask start = new IdentifyingRecentEventsFeed(buffer.Take(QueryingEvents.BatchSize)); ITask end = start.Execute(fileSystem, buffer, new FeedBuilder(SampleLinks.Instance), (args => { })); Assert.IsInstanceOf(typeof (UpdatingRecentEventsFeed), end); Assert.AreEqual(feed.Id, end.GetRecentEventsFeed().GetSyndicationFeed().Id); Assert.AreEqual(2, end.GetEvents().Count()); }
public void IfFeedFillsExactlyToQuotaShouldNotBeArchived() { FileName tempFileName = null; FeedBuilder feedBuilder = new FeedBuilder(SampleLinks.Instance); InMemoryFileSystem fileSystem = new InMemoryFileSystem(); EventBuffer buffer = new EventBuffer(); Repeat.Times(3).Action(() => buffer.Add(new EventBuilder().Build())); FakeTimer timer = new FakeTimer(); FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance)); feedWriter.FeedMappingsChanged += ((o, args) => tempFileName = new FileName(args.RecentEventsFeedStoreId)); timer.Fire(); Assert.AreEqual(1, fileSystem.FileCount(fileSystem.CurrentDirectory)); Assert.AreEqual(0, fileSystem.FileCount(fileSystem.ArchiveDirectory)); RecentEventsFeed rehydratedFeed = feedBuilder.LoadRecentEventsFeed(fileSystem, tempFileName); Assert.AreEqual(3, rehydratedFeed.GetSyndicationFeed().Items.Count()); }
public void ShouldSaveFeedToArchiveDirectory() { InMemoryFileSystem fileSystem = new InMemoryFileSystem(); RecentEventsFeed recentEvents = new RecentEventsFeedBuilder().WithId(2).WithPreviousId(1).WithNumberOfEntries(5).Build(); ArchiveFeed archive = recentEvents.CreateArchiveFeed(recentEvents.CreateNextFeed()); Assert.AreEqual(0, fileSystem.FileCount(fileSystem.ArchiveDirectory)); archive.Save(fileSystem); Assert.AreEqual(1, fileSystem.FileCount(fileSystem.ArchiveDirectory)); SyndicationFeed feed = archive.GetSyndicationFeed(); FileName archiveFileName = recentEvents.GetFeedMapping().WithArchiveFileName().FileName; SyndicationFeed rehydrated = SyndicationFeed.Load(fileSystem.ArchiveDirectory.GetXmlReader(archiveFileName)); Assert.AreEqual(feed.Id, rehydrated.Id); Assert.AreEqual(feed.Items.Count(), rehydrated.Items.Count()); Assert.AreEqual(feed.GetSelfLink().GetAbsoluteUri(), rehydrated.GetSelfLink().GetAbsoluteUri()); Assert.AreEqual(feed.GetPrevArchiveLink().GetAbsoluteUri(), rehydrated.GetPrevArchiveLink().GetAbsoluteUri()); Assert.AreEqual(feed.GetNextArchiveLink().GetAbsoluteUri(), rehydrated.GetNextArchiveLink().GetAbsoluteUri()); }
public void InitializeDynamic() { DiscFileSystem fs = new InMemoryFileSystem(); using (Disk disk = Disk.Initialize(fs, "a.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.MonolithicSparse)) { Assert.IsNotNull(disk); Assert.That(disk.Geometry.Capacity > 15.8 * 1024L * 1024 * 1024 && disk.Geometry.Capacity <= 16 * 1024L * 1024 * 1024); Assert.That(disk.Content.Length == 16 * 1024L * 1024 * 1024); } Assert.Greater(fs.GetFileLength("a.vmdk"), 2 * 1024 * 1024); Assert.Less(fs.GetFileLength("a.vmdk"), 4 * 1024 * 1024); using (Disk disk = new Disk(fs, "a.vmdk", FileAccess.Read)) { Assert.That(disk.Geometry.Capacity > 15.8 * 1024L * 1024 * 1024 && disk.Geometry.Capacity <= 16 * 1024L * 1024 * 1024); Assert.That(disk.Content.Length == 16 * 1024L * 1024 * 1024); List<DiskImageFile> links = new List<DiskImageFile>(disk.Links); List<string> paths = new List<string>(links[0].ExtentPaths); Assert.AreEqual(1, paths.Count); Assert.AreEqual("a.vmdk", paths[0]); } }
public IncludeProcessorFacts() { _fileSystem = new InMemoryFileSystem(); }
public void WhenTriggeredRepeatedlyShouldContinueToAddEventsToExistingFeed() { FileName tempFileName = null; FeedBuilder feedBuilder = new FeedBuilder(SampleLinks.Instance); InMemoryFileSystem fileSystem = new InMemoryFileSystem(); EventBuffer buffer = new EventBuffer(); buffer.Add(new EventBuilder().Build()); FakeTimer timer = new FakeTimer(); FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance)); feedWriter.FeedMappingsChanged += ((o, args) => tempFileName = new FileName(args.RecentEventsFeedStoreId)); timer.Fire(); RecentEventsFeed rehydratedFeed = feedBuilder.LoadRecentEventsFeed(fileSystem, tempFileName); Assert.AreEqual(1, rehydratedFeed.GetSyndicationFeed().Items.Count()); Assert.AreEqual("?page=1", rehydratedFeed.GetSyndicationFeed().GetViaLink().Uri.Query); buffer.Add(new EventBuilder().Build()); timer.Fire(); RecentEventsFeed secondRehydratedFeed = feedBuilder.LoadRecentEventsFeed(fileSystem, tempFileName); Assert.AreEqual(2, secondRehydratedFeed.GetSyndicationFeed().Items.Count()); Assert.AreEqual("?page=1", secondRehydratedFeed.GetSyndicationFeed().GetViaLink().Uri.Query); }
public void WhenThereAreNoOutstandingEventsShouldNotWriteFeedOrRaiseEvent() { int eventCount = 0; InMemoryFileSystem fileSystem = new InMemoryFileSystem(); EventBuffer buffer = new EventBuffer(); FakeTimer timer = new FakeTimer(); FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance)); feedWriter.FeedMappingsChanged += ((o, args) => eventCount++); timer.Fire(); Assert.AreEqual(0, eventCount); Assert.AreEqual(0, fileSystem.FileCount(fileSystem.CurrentDirectory)); }
public void TestParseFileWithDuplicatedItem_IgnoresSecond() { const string input = @"{ ""file"": [ ""test2.html"", ""*.html"" ] } "; var fileSystem = new InMemoryFileSystem(new[] { "test1.html", "test2.html", "test3.html", "test4.html" }); var result = Project.FromFile(input, fileSystem); var resultList = result.GetItems().ToList(); Assert.Equal(4, resultList.Count); Assert.Equal("test2.html", resultList[0].Identifier.Identifier); }
public void TestModifyFile_InvokesProcessor() { const string input = @"{ ""file"": [ ""test1.html"", ""test2.html"" ], ""template"": [""templates/**.html""], ""content"": [""**.html""] } "; var fileSystem = new InMemoryFileSystem(new[] { "test1.html", "test2.html", "templates/tmpl1.html", "templates/tmpl2.html" }); const string filePath = "templates/tmpl3.html"; const string filePath2 = "content.html"; var result = Project.FromFile(input, fileSystem); var processor = new Mock<IProjectObserver>(MockBehavior.Strict); processor.Setup(f => f.NotifyItemAdded(result, It.Is<FileProjectItem>(i => i.FileInfo.FilePath.ToString() == filePath && i.Identifier.Kind == "template"))); processor.Setup(f => f.NotifyItemAdded(result, It.Is<FileProjectItem>(i => i.FileInfo.FilePath.ToString() == filePath && i.Identifier.Kind == "content"))); processor.Setup(f => f.NotifyItemAdded(result, It.Is<FileProjectItem>(i => i.FileInfo.FilePath.ToString() == filePath2 && i.Identifier.Kind == "content"))); processor.Setup(f => f.NotifyItemRemoved(result, It.Is<FileProjectItem>(i => i.FileInfo.FilePath.ToString() == filePath2 && i.Identifier.Kind == "content"))); result.AddObserver(processor.Object); fileSystem.Add(filePath); // Not included file fileSystem.Add("templates/test.json"); fileSystem.Add(filePath2); fileSystem.RemoveFile(PathInfo.Create(filePath2)); processor.VerifyAll(); }
public void TestChangeOnFile_InvokesProcessor(int index, string filePath) { const string input = @"{ ""file"": [ ""test1.html"", ""test2.html"" ], ""template"": [""templates/**.html""] } "; var fileSystem = new InMemoryFileSystem(new[] { "test1.html", "test2.html", "templates/tmpl1.html", "templates/tmpl2.html" }); var result = Project.FromFile(input, fileSystem); var item = result.GetItems().ToList()[index]; var processor = new Mock<IProjectObserver>(MockBehavior.Strict); processor.Setup(f => f.NotifyItemChanged(result, item)); result.AddObserver(processor.Object); fileSystem.Touch(filePath); processor.VerifyAll(); }
public InMemoryDirectoryInfoFacts() { this.fileSystem = new InMemoryFileSystem(); }
public DirectoryFacts() { this.testee = new InMemoryFileSystem(); }
public file_search_context() { FileSystem = new InMemoryFileSystem(); }
public void Setup() { _filesystem = new InMemoryFileSystem(); }
public visual_studio() { FileSystem = new InMemoryFileSystem(); SlnDir = FileSystem.CreateTempDirectory(); }
public folder() { file_system = new InMemoryFileSystem(); repository_directory = file_system.CreateTempDirectory(); source_repository = new InMemoryRepository("somewhere"); }
public void VirtualizeDirectory(string path) { FileSystem = new InMemoryFileSystem(path, FileSystem); }
public void can_add_folders_to_fs() { var fs = new InMemoryFileSystem().CreateChildDir(@"C:\mordor"); fs.Directories.ShouldHaveCountOf(1); }
public InMemoryTemporaryDirectory(InMemoryFileSystem fs, string path) : base(fs, path) { }
public in_memory_file_system() { FileSystem = new InMemoryFileSystem(); }
public void Extents() { // Fragile - this is the grain size in bytes of the VMDK file, so dependant on algorithm that // determines grain size for new VMDKs... const int unit = 128 * 512; DiscFileSystem fs = new InMemoryFileSystem(); using (Disk disk = Disk.Initialize(fs, "a.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.TwoGbMaxExtentSparse)) { disk.Content.Position = 20 * unit; disk.Content.Write(new byte[4 * unit], 0, 4 * unit); // Starts before first extent, ends before end of extent List<StreamExtent> extents = new List<StreamExtent>(disk.Content.GetExtentsInRange(0, 21 * unit)); Assert.AreEqual(1, extents.Count); Assert.AreEqual(20 * unit, extents[0].Start); Assert.AreEqual(1 * unit, extents[0].Length); // Limit to disk content length extents = new List<StreamExtent>(disk.Content.GetExtentsInRange(21 * unit, 20 * unit)); Assert.AreEqual(1, extents.Count); Assert.AreEqual(21 * unit, extents[0].Start); Assert.AreEqual(3 * unit, extents[0].Length); // Out of range extents = new List<StreamExtent>(disk.Content.GetExtentsInRange(25 * unit, 4 * unit)); Assert.AreEqual(0, extents.Count); // Non-unit multiples extents = new List<StreamExtent>(disk.Content.GetExtentsInRange(21 * unit + 10, 20 * unit)); Assert.AreEqual(1, extents.Count); Assert.AreEqual(21 * unit + 10, extents[0].Start); Assert.AreEqual(3 * unit - 10, extents[0].Length); } }
public template_processor() { FileSystem = new InMemoryFileSystem(); }
public void ReadNotPresentVmfs() { DiscFileSystem fs = new InMemoryFileSystem(); using (Disk disk = Disk.Initialize(fs, "a.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.VmfsSparse)) { byte[] buffer = new byte[100]; disk.Content.Seek(2 * 1024 * 1024, SeekOrigin.Current); disk.Content.Read(buffer, 0, buffer.Length); for (int i = 0; i < 100; ++i) { if (buffer[i] != 0) { Assert.Fail(); } } } }
public void WhenNumberOfEventsExceedsQuotaShouldArchiveFeedAndBeginAnotherOne() { FileName tempFileName = null; FeedBuilder feedBuilder = new FeedBuilder(SampleLinks.Instance); InMemoryFileSystem fileSystem = new InMemoryFileSystem(); EventBuffer buffer = new EventBuffer(); EventBuilder eventBuilder = new EventBuilder(); Repeat.Times(RecentEventsFeed.Quota + 1).Action(() => buffer.Add(eventBuilder.Build())); FakeTimer timer = new FakeTimer(); FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance)); feedWriter.FeedMappingsChanged += ((o, args) => tempFileName = new FileName(args.RecentEventsFeedStoreId)); timer.Fire(); Assert.AreEqual(1, fileSystem.FileCount(fileSystem.CurrentDirectory)); Assert.AreEqual(1, fileSystem.FileCount(fileSystem.ArchiveDirectory)); ArchiveFeed archivedFeed = LoadArchiveFeed(fileSystem, new FileName("1")); Assert.AreEqual(10, archivedFeed.GetNumberOfEntries()); Assert.AreEqual("?page=1", archivedFeed.GetSyndicationFeed().GetSelfLink().Uri.Query); Assert.AreEqual("?page=2", archivedFeed.GetSyndicationFeed().GetNextArchiveLink().Uri.Query); RecentEventsFeed recentEventsFeed = feedBuilder.LoadRecentEventsFeed(fileSystem, tempFileName); Assert.AreEqual(1, recentEventsFeed.GetSyndicationFeed().Items.Count()); Assert.AreEqual("?page=2", recentEventsFeed.GetSyndicationFeed().GetViaLink().Uri.Query); }
public void ReadWriteLargeVmfs() { DiscFileSystem fs = new InMemoryFileSystem(); using (Disk disk = Disk.Initialize(fs, "a.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.VmfsSparse)) { byte[] content = new byte[3 * 1024 * 1024]; for (int i = 0; i < content.Length / 4; ++i) { content[i * 4 + 0] = (byte)((i >> 24) & 0xFF); content[i * 4 + 1] = (byte)((i >> 16) & 0xFF); content[i * 4 + 2] = (byte)((i >> 8) & 0xFF); content[i * 4 + 3] = (byte)(i & 0xFF); } Stream s = disk.Content; s.Position = 10; s.Write(content, 0, content.Length); byte[] buffer = new byte[content.Length]; s.Position = 10; s.Read(buffer, 0, buffer.Length); for (int i = 0; i < content.Length; ++i) { if (buffer[i] != content[i]) { Assert.Fail(); } } } }
public void WhenThereAreNoOutstandingEventsShouldRetainTheCurrentTempFileName() { InMemoryFileSystem fileSystem = new InMemoryFileSystem(); EventBuffer buffer = new EventBuffer(); FakeTimer timer = new FakeTimer(); FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance)); Repeat.Times(1).Action(() => buffer.Add(new EventBuilder().Build())); timer.Fire(); Repeat.Times(0).Action(() => buffer.Add(new EventBuilder().Build())); timer.Fire(); Repeat.Times(1).Action(() => buffer.Add(new EventBuilder().Build())); timer.Fire(); Assert.AreEqual(2, fileSystem.FileCount(fileSystem.CurrentDirectory)); }
public void ReadWriteSmallVmfs() { DiscFileSystem fs = new InMemoryFileSystem(); using (Disk disk = Disk.Initialize(fs, "a.vmdk", 16 * 1024L * 1024 * 1024, DiskCreateType.VmfsSparse)) { byte[] content = new byte[100]; for (int i = 0; i < content.Length; ++i) { content[i] = (byte)i; } Stream s = disk.Content; s.Write(content, 10, 40); Assert.AreEqual(40, s.Position); s.Write(content, 50, 50); Assert.AreEqual(90, s.Position); s.Position = 0; byte[] buffer = new byte[100]; s.Read(buffer, 10, 60); Assert.AreEqual(60, s.Position); for (int i = 0; i < 10; ++i) { Assert.AreEqual(0, buffer[i]); } for (int i = 10; i < 60; ++i) { Assert.AreEqual(i, buffer[i]); } } // Check the data persisted using (Disk disk = new Disk(fs, "a.vmdk", FileAccess.Read)) { Stream s = disk.Content; byte[] buffer = new byte[100]; s.Read(buffer, 10, 20); Assert.AreEqual(20, s.Position); for (int i = 0; i < 10; ++i) { Assert.AreEqual(0, buffer[i]); } for (int i = 10; i < 20; ++i) { Assert.AreEqual(i, buffer[i]); } } }
public void WhenTriggeredShouldAddBatchOfEventsToCurrentFeed() { FileName tempFileName = null; InMemoryFileSystem fileSystem = new InMemoryFileSystem(); EventBuffer buffer = new EventBuffer(); EventBuilder eventBuilder = new EventBuilder(); Repeat.Times(2).Action(() => buffer.Add(eventBuilder.Build())); FakeTimer timer = new FakeTimer(); FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance)); feedWriter.FeedMappingsChanged += ((o, args) => tempFileName = new FileName(args.RecentEventsFeedStoreId)); timer.Fire(); Assert.AreEqual(1, fileSystem.FileCount(fileSystem.CurrentDirectory)); RecentEventsFeed rehydratedFeed = new FeedBuilder(SampleLinks.Instance).LoadRecentEventsFeed(fileSystem, tempFileName); Assert.AreEqual(2, rehydratedFeed.GetNumberOfEntries()); }
/// <summary> /// Helper method to set the <see cref="Config.FileSystem"/> /// property with a new instance of <see cref="InMemoryFileSystem"/> /// </summary> public Config UseInMemoryFileSystem() { FileSystem = new InMemoryFileSystem(); return(this); }
public void ShouldRaiseEventEachTimeATempFileIsSavedToCurrentDirectory() { int eventCount = 0; InMemoryFileSystem fileSystem = new InMemoryFileSystem(); EventBuffer buffer = new EventBufferBuilder().Build(); EventBuilder eventBuilder = new EventBuilder(); FakeTimer timer = new FakeTimer(); FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance)); feedWriter.FeedMappingsChanged += ((o, args) => eventCount++); //Current will contain 1 - 1st version of 1 will be saved to current Repeat.Times(1).Action(() => buffer.Add(eventBuilder.Build())); timer.Fire(); //Current will contain full feed - 2nd version of 1 will be saved to current Repeat.Times(RecentEventsFeed.Quota - 1).Action(() => buffer.Add(eventBuilder.Build())); timer.Fire(); //Feed will be archived 3 times - 1st version of 4 will be saved to current Repeat.Times((RecentEventsFeed.Quota * 3) - 1).Action(() => buffer.Add(eventBuilder.Build())); timer.Fire(); Assert.AreEqual(3, eventCount); Assert.AreEqual(3, fileSystem.FileCount(fileSystem.CurrentDirectory)); Assert.AreEqual(3, fileSystem.FileCount(fileSystem.ArchiveDirectory)); Assert.IsTrue(fileSystem.FileExists(fileSystem.ArchiveDirectory, new FileName("1"))); Assert.IsTrue(fileSystem.FileExists(fileSystem.ArchiveDirectory, new FileName("2"))); Assert.IsTrue(fileSystem.FileExists(fileSystem.ArchiveDirectory, new FileName("3"))); }
public exporter() { FileSystem = new InMemoryFileSystem(); TempDirectory = FileSystem.CreateTempDirectory(); }
protected override void InitializeFileSystem(ICollection mountPoint, IPrincipal principal, InMemoryFileSystem fileSystem) { // Create the mount point var testMountPoint = fileSystem.RootCollection.CreateCollection("test"); // Create the mount point file system var testMountPointFileSystemFactory = _serviceProvider.GetRequiredService <InMemoryFileSystemFactory>(); var testMountPointFileSystem = Assert.IsType <InMemoryFileSystem>(testMountPointFileSystemFactory.CreateFileSystem(testMountPoint, principal)); // Populate content of mount point file system testMountPointFileSystem.RootCollection.CreateDocument("test.txt").Data = new MemoryStream(Encoding.UTF8.GetBytes("Hello!")); // Add mount point fileSystem.Mount(testMountPoint.Path, testMountPointFileSystem); // Make the root file system read-only fileSystem.IsReadOnly = true; }