public void Should_throw_exception_when_ThrowExceptions_and_report_upload_fails() { _listener.Stop(); var collectionDto = new ContextCollectionDTO("MyName", new Dictionary <string, string> { { "Key", "Val" } }); var report = new ErrorReportDTO("aaa", new ExceptionDTO(new Exception()), new[] { collectionDto }); var uri = new Uri($"http://localhost:{_listener.LocalPort}/coderr/"); var sut = new UploadToCoderr(uri, "api", "secret", () => false, () => true); Action actual = () => sut.UploadReport(report); actual.ShouldThrow <Exception>(); }
static void Main(string[] args) { JsonConvert.DefaultSettings = (() => { var settings = new JsonSerializerSettings(); settings.Converters.Add(new StringEnumConverter()); return(settings); }); AddUser(new UserData("root", "root", false)); HttpListener httpServer = new HttpListener(new ChannelTcpListenerConfiguration( () => new HttpMessageDecoder(), () => new HttpMessageEncoder() )); httpServer.ClientConnected += httpServer_ClientConnected; httpServer.MessageReceived = OnMessage; httpServer.Start(IPAddress.Any, 38012); //CLI MENU while (true) { Console.Out.WriteLine("========================================"); Console.Out.WriteLine("Menu:"); Console.Out.WriteLine("1) List users"); Console.Out.WriteLine("2) Add/Edit user"); Console.Out.WriteLine("3) Delete user"); Console.Out.WriteLine("9) Exit program"); Console.Out.Write("Choice: "); string picked = Console.In.ReadLine(); Console.Out.WriteLine("----------------------------------------"); switch (picked) { case "1": foreach (UserData userData in validUsers.Values) { Console.Out.WriteLine("Name: " + userData.name + ", ReadOnly: " + (userData.readOnly ? "Yes" : "No")); } break; case "2": UserData user = ConsoleReadUser(); validUsers[user.name] = user; break; case "3": Console.Out.Write("Username: "******"9": httpServer.Stop(); return; } } }
static void Main(string[] args) { JsonConvert.DefaultSettings = (() => { var settings = new JsonSerializerSettings(); settings.Converters.Add(new StringEnumConverter()); return settings; }); AddUser(new UserData("root", "root", false)); HttpListener httpServer = new HttpListener(new ChannelTcpListenerConfiguration( () => new HttpMessageDecoder(), () => new HttpMessageEncoder() )); httpServer.ClientConnected += httpServer_ClientConnected; httpServer.MessageReceived = OnMessage; httpServer.Start(IPAddress.Any, 38012); //CLI MENU while (true) { Console.Out.WriteLine("========================================"); Console.Out.WriteLine("Menu:"); Console.Out.WriteLine("1) List users"); Console.Out.WriteLine("2) Add/Edit user"); Console.Out.WriteLine("3) Delete user"); Console.Out.WriteLine("9) Exit program"); Console.Out.Write("Choice: "); string picked = Console.In.ReadLine(); Console.Out.WriteLine("----------------------------------------"); switch(picked) { case "1": foreach(UserData userData in validUsers.Values) Console.Out.WriteLine("Name: " + userData.name + ", ReadOnly: " + (userData.readOnly ? "Yes" : "No")); break; case "2": UserData user = ConsoleReadUser(); validUsers[user.name] = user; break; case "3": Console.Out.Write("Username: "******"9": httpServer.Stop(); return; } } }
/// <summary> /// Stop the server. /// </summary> public void Stop() { _listener.Stop(); _listener = null; }