internal SimpleHttpListener(params Uri[] prefixes) { Ensure.NotNull(prefixes, nameof(prefixes)); _listener = new HttpListener(); if (prefixes == null || prefixes.Length == 0) { _listener.Prefixes.Add("http://*:80/"); } else { Array.ForEach(prefixes, p => { _listener.Prefixes.Add(p.AbsoluteUri); }); } }
public void When_ensuring_directoryInfo_exists() { var nonExistingDirectoryPath = Path.GetRandomFileName(); var nonExistingDirInfo = new DirectoryInfo(nonExistingDirectoryPath); Should.Throw <DirectoryNotFoundException>(() => Ensure.Exists(nonExistingDirInfo)) .Message.ShouldBe($"Cannot find: '{nonExistingDirInfo.FullName}'"); nonExistingDirInfo.Create(); var existingDirInfo = nonExistingDirInfo; Should.NotThrow(() => Ensure.Exists(existingDirInfo)); Ensure.Exists(existingDirInfo).ShouldBe(existingDirInfo); try { existingDirInfo.Delete(); } catch { /* ignored */ } }
public void When_ensuring_fileInfo_exists() { var nonExistingFilePath = Path.GetRandomFileName(); var nonExistingFileInfo = new FileInfo(nonExistingFilePath); Should.Throw <FileNotFoundException>(() => Ensure.Exists(nonExistingFileInfo)) .Message.ShouldBe("The given file cannot be found."); nonExistingFileInfo.Create(); var existingFileInfo = nonExistingFileInfo; Should.NotThrow(() => Ensure.Exists(existingFileInfo)); Ensure.Exists(existingFileInfo).ShouldBe(existingFileInfo); try { existingFileInfo.Delete(); } catch { /* ignored */ } }