public async Task DepositCargoAsync_ReturnsDeposit() { var deposit = new Deposit() { Good = GoodTypes.Fuel, Quantity = 100 }; var structure = new Structure(); var expectedShipId = "1a2b"; var expectedStructureId = "3c4d"; var builder = new TestBuilder() .WithMethod(Method.POST) .WithResource($"game/structures/{expectedStructureId}/deposit") .WithPayload("deposit", deposit) .WithPayload("structure", structure) .WithParameter("shipId", expectedShipId) .WithParameter("good", deposit.Good) .WithParameter("quantity", deposit.Quantity.ToString()); var client = builder.Build(); var result = await client.DepositCargoAsync(expectedStructureId, expectedShipId, deposit.Good, deposit.Quantity); builder.MockRestClient.Verify(); Assert.IsNotNull(result); Assert.IsNotNull(result.Structure); }
public static void StartServices() { _accessPointService = Run <BusServiceControl>( Service.AccessPoint.Program.ConfigureService, cfg => cfg.SetServiceName("Test.Service.AccessPoint")); _ldapService = Run <BusServiceControl>( Service.LDAP.Program.ConfigureService, cfg => cfg.SetServiceName("Test.Service.LDAP")); _clientService = Run <ClientServiceControl>( Client.Program.ConfigureService, cfg => cfg.SetServiceName("Test.Service.Client")); _notificationService = Run <NotificationServiceControl>( ConfigireNotificationService, cfg => cfg.SetServiceName("Test.Service.Notification")); var builder = new TestBuilder(new WindowsHostEnvironment(new HostConfiguratorImpl()), new WindowsHostSettings()); _host = (TestHost)builder.Build( new TestServiceBuilder( _accessPointService, _ldapService, _notificationService, _clientService)); _host.Run(); }
public async Task SellGoodAsync_ReturnsOrder() { var order = new Order() { Good = GoodTypes.Fuel, Quantity = 100 }; var expectedShipId = "1a2b"; var expectedCredits = 10000; var builder = new TestBuilder() .WithMethod(Method.POST) .WithResource("users/username/sell-orders") .WithPayload("order", order) .WithPayload("credits", expectedCredits) .WithParameter("shipId", expectedShipId) .WithParameter("good", order.Good) .WithParameter("quantity", order.Quantity.ToString()); var client = builder.Build(); var result = await client.SellGoodAsync(expectedShipId, order.Good, order.Quantity); builder.MockRestClient.Verify(); Assert.IsNotNull(result); Assert.AreEqual(expectedCredits, result.Credits); }
public void Builders_DatBuilder_BuildDocuments_ExDisownedParents() { List <string[]> newRecords = new List <string[]>(); records.ForEach(r => { string[] record = new string[r.Length]; r.CopyTo(record, 0); newRecords.Add(record); }); newRecords[3] = new string[] { "DOC000004", "", "", "VOL001", "3", "", "c", "BUCKLE", "m" }; builder.HasHeader = true; builder.KeyColumnName = "DOCID"; builder.ParentColumnName = "BEGATT"; builder.ChildColumnName = "ATTCHIDS"; builder.ChildSeparator = ";"; List <Document> documents = builder.Build(newRecords); DocumentCollection docs = new DocumentCollection(documents); }
/// <summary> /// Starts the server. /// </summary> public void Start() { // build the service host _serviceControl = Container.Resolve <ProgramControl>(); var builder = new TestBuilder(new WindowsHostEnvironment(new HostConfiguratorImpl()), new WindowsHostSettings()); _serviceHost = (TestHost)builder.Build(new TestServiceBuilder(_serviceControl)); // run the host _serviceHost.Run(); }
public async Task GetUserAsync_ReturnsUser() { var builder = new TestBuilder() .WithResource($"users/username") .WithPayload("user", new User()); var client = builder.Build(); var result = await client.GetUserAsync(); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task ScrapShipAsync_Returns() { var expectedShipId = "1a2b"; var builder = new TestBuilder() .WithMethod(Method.DELETE) .WithResource($"users/username/ships/{expectedShipId}") .WithPayload("success", new SuccessResponse()); var client = builder.Build(); await client.ScrapShipAsync(expectedShipId); builder.MockRestClient.Verify(); }
public async Task GetStatusAsync_ReturnsStatus() { var status = "spacetraders is currently online and available to play"; var builder = new TestBuilder() .WithResource("game/status") .WithPayload("status", status); var client = builder.Build(); var result = await client.GetStatusAsync(); builder.MockRestClient.Verify(); Assert.AreEqual(status, result); }
public void CanExecuteEmptyTestFile() { var testBuilder = new TestBuilder(); var parser = new Parser(testBuilder); var lexer = new Lexer(parser); lexer.Lex(""); var testRunner = new TestRunner(); var response = testRunner.Execute(testBuilder.Build()); response.TestsRun.Should().Be(0); }
public async Task GetAvailableShipsAsync_ReturnsShips() { var ships = new List<Ship>() { new Ship() }; var builder = new TestBuilder() .WithResource("game/ships") .WithPayload("ships", ships); var client = builder.Build(); var result = await client.GetAvailableShipsAsync(); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task GetFlightPlanAsync_ReturnsFlightPlan() { var flightPlan = new FlightPlan() { Id = "1a2b" }; var builder = new TestBuilder() .WithResource($"users/username/flight-plans/{flightPlan.Id}") .WithPayload("flightplan", flightPlan); var client = builder.Build(); var result = await client.GetFlightPlanAsync(flightPlan.Id); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task TakeOutLoanAsync_ReturnsUser() { var expectedLoanType = LoanTypes.Startup; var builder = new TestBuilder() .WithMethod(Method.POST) .WithResource("users/username/loans") .WithPayload("user", new User()) .WithParameter("type", expectedLoanType); var client = builder.Build(); var result = await client.TakeOutLoanAsync(expectedLoanType); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task GetStructureAsync_ReturnsStructure() { var structure = new Structure() { Id = "1a2b" }; var builder = new TestBuilder() .WithResource($"game/structures/{structure.Id}") .WithPayload("structure", structure); var client = builder.Build(); var result = await client.GetStructureAsync(structure.Id); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task GetLoansAsync_ReturnsLoans() { var loans = new List<Loan>() { new Loan() }; var builder = new TestBuilder() .WithResource("users/username/loans") .WithPayload("loans", loans); var client = builder.Build(); var result = await client.GetLoansAsync(); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task GetFlightPlansAsync_ReturnsFlightPlans() { var expectedSystemSymbol = "OE"; var flightPlans = new List<PublicFlightPlan>() { new PublicFlightPlan() }; var builder = new TestBuilder() .WithResource($"game/systems/{expectedSystemSymbol}/flight-plans") .WithPayload("flightPlans", flightPlans); var client = builder.Build(); var result = await client.GetFlightPlansAsync(expectedSystemSymbol); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task GetSystemsAsync_ReturnsSystems() { var systems = new List<StarSystem>() { new StarSystem() }; var builder = new TestBuilder() .WithResource($"game/systems") .WithPayload("systems", systems); var client = builder.Build(); var result = await client.GetSystemsAsync(); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task GetShipAsync_ReturnsShip() { var ship = new Ship() { Id = "1a2b" }; var builder = new TestBuilder() .WithResource($"users/username/ships/{ship.Id}") .WithPayload("user", new User()); var client = builder.Build(); var result = await client.GetShipAsync(ship.Id); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task GetSystemLocationsAsync_ReturnsLocations() { var expectedSystemSymbol = "OE"; var locations = new List<Location>() { new Location() }; var builder = new TestBuilder() .WithResource($"game/systems/{expectedSystemSymbol}/locations") .WithPayload("locations", locations); var client = builder.Build(); var result = await client.GetSystemLocations(expectedSystemSymbol); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task PurchaseShipAsync_ReturnsUser() { var expectedLocation = "OE"; var expectedType = "OE-1"; var builder = new TestBuilder() .WithMethod(Method.POST) .WithResource("users/username/ships") .WithPayload("user", new User()) .WithParameter("location", expectedLocation) .WithParameter("type", expectedType); var client = builder.Build(); var result = await client.PurchaseShipAsync(expectedLocation, expectedType); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task WarpShipAsync_ReturnsFlightPlan() { var flightPlan = new FlightPlan() { ShipId = "1a2b" }; var builder = new TestBuilder() .WithMethod(Method.POST) .WithResource($"users/username/warp-jump") .WithPayload("flightplan", flightPlan) .WithParameter("shipId", flightPlan.ShipId); var client = builder.Build(); var result = await client.WarpShipAsync(flightPlan.ShipId); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public void CanExecuteSingleStepTestFile() { var testBuilder = new TestBuilder(); var parser = new Parser(testBuilder); var lexer = new Lexer(parser); lexer.Lex("Given Craig has a pie"); var testRunner = new TestRunner(); var called = false; testRunner.DefineGivenStep("Craig has a pie", () => { called = true; }); var response = testRunner.Execute(testBuilder.Build()); response.TestsRun.Should().Be(1); called.Should().BeTrue(); }
public async Task GetAvailableShipsAsync_WithClassFilter_ReturnsShips() { var expectedShipClass = "MK-1"; var ships = new List<Ship>() { new Ship() }; var builder = new TestBuilder() .WithResource("game/ships") .WithPayload("ships", ships) .WithParameter("class", expectedShipClass); var client = builder.Build(); var result = await client.GetAvailableShipsAsync(expectedShipClass); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task GetMarketplaceAsync_ReturnsMarketLocation() { var location = new MarketLocation() { Symbol = "OE", Marketplace = new List<Good>() { new Good() } }; var builder = new TestBuilder() .WithResource($"game/locations/{location.Symbol}/marketplace") .WithPayload("location", location); var client = builder.Build(); var result = await client.GetMarketplaceAsync(location.Symbol); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
public async Task GetLocationAsync_ReturnsLocation() { var location = new Location() { Symbol = "OE-PM-TR" }; var expectedShips = 10; var builder = new TestBuilder() .WithResource($"game/locations/{location.Symbol}") .WithPayload("location", location) .WithPayload("dockedShips", expectedShips); var client = builder.Build(); var result = await client.GetLocationAsync(location.Symbol); builder.MockRestClient.Verify(); Assert.IsNotNull(result); Assert.AreEqual(expectedShips, result.DockedShips); }
public async Task GetLocationShipsAsync_ReturnsShips() { var location = new LocationDetail() { Symbol = "OE", Ships = new List<ShipPlate>() { new ShipPlate() } }; var builder = new TestBuilder() .WithResource($"game/locations/{location.Symbol}/ships") .WithPayload("location", location); var client = builder.Build(); var result = await client.GetLocationShipsAsync(location.Symbol); builder.MockRestClient.Verify(); Assert.IsNotNull(result); Assert.AreEqual(location.Ships.Count(), result.DockedShips); }
public object GetInstances() { ITaskBuilder builder = new TestBuilder(); var testsDB = Struct.dbConnection.GetInstance().GetTests(); List <Test> instances = new List <Test>(); if (testsDB.Any()) { foreach (var test in testsDB) { builder.SetObject(test); builder.Build(); instances.Add((Test)builder.GetObject()); if (instances.Count == 10) { break; /// } } } return(instances); }
public async Task SubmitFlightPlanAsync_ReturnsFlightPlan() { var flightPlan = new FlightPlan() { Id = "1a2b", ShipId = "3c4e", Departure = "AB", Destination = "CD" }; var builder = new TestBuilder() .WithMethod(Method.POST) .WithResource($"users/username/flight-plans") .WithPayload("flightplan", flightPlan) .WithParameter("shipId", flightPlan.ShipId) .WithParameter("destination", flightPlan.Destination); var client = builder.Build(); var result = await client.SubmitFightPlanAsync(flightPlan.ShipId, flightPlan.Destination); builder.MockRestClient.Verify(); Assert.IsNotNull(result); }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); WindowsPrincipal pricipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); bool hasAdministrativeRight = pricipal.IsInRole(WindowsBuiltInRole.Administrator); if (!hasAdministrativeRight) { string parameter = string.Concat(args); RunElevated(asm.Location, parameter); Process.GetCurrentProcess().Kill(); } Console.WriteLine("[+] Checking initial configuration..."); Int16 levels = 3; Int16.TryParse(ConfigurationManager.AppSettings["levels"], out levels); Int16 connCount = 30; Int16.TryParse(ConfigurationManager.AppSettings["count"], out connCount); Int16 duration = 300; Int16.TryParse(ConfigurationManager.AppSettings["duration"], out duration); if (duration < 180) { duration = 180; } if (duration > 3600) { duration = 3600; } ClientType type = ClientType.VU; try { switch (ConfigurationManager.AppSettings["type"].ToLower()) { case "sbu": type = ClientType.SBU; break; default: type = ClientType.VU; break; } } catch { } Uri site = null; try { site = new Uri(ConfigurationManager.AppSettings["uri"]); } catch (Exception ex) { Console.WriteLine("URI not valid"); return; } Dictionary <String, String> headers = new Dictionary <string, string>(); if (!String.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["Cookie"])) { try { CookieContainer tmp = new CookieContainer(); tmp.SetCookies(site, ConfigurationManager.AppSettings["Cookie"]); headers.Add("Cookie", ConfigurationManager.AppSettings["Cookie"]); } catch (Exception ex) { Console.WriteLine("Error parsing cookie"); return; } } try { if (!String.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["User-Agent"])) { headers.Add("User-Agent", ConfigurationManager.AppSettings["User-Agent"]); } } catch (Exception ex) { Console.WriteLine("Error parsing User-Agent"); return; } Console.WriteLine("[+] Checking zabbix agents..."); Console.WriteLine("[+] Checking date and time from NTP servers..."); try { DateTime ntpdate = NTP.GetNetworkUTCTime(); Console.WriteLine(" NTP UTC data: " + ntpdate.ToString(Thread.CurrentThread.CurrentCulture)); TimeSpan ts = ntpdate - DateTime.UtcNow; if (Math.Abs(ts.TotalSeconds) > 60) { Console.WriteLine(" Updating local time"); Console.WriteLine(" Old time: " + DateTime.Now.ToString(Thread.CurrentThread.CurrentCulture)); NTP.SetSystemTime(ntpdate); Console.WriteLine(" New time: " + DateTime.Now.ToString(Thread.CurrentThread.CurrentCulture)); } else { Console.WriteLine(" Local time is up to date"); } } catch (Exception ex) { Console.WriteLine("[!] Error updating local time: " + ex.Message); } List <ZabbixConfig> zbxConfig = new List <ZabbixConfig>(); ZabbixConfigSection ZabbixManagers = (ZabbixConfigSection)ConfigurationManager.GetSection("zabbixMonitors"); if (ZabbixManagers != null) { foreach (ZabbixConfigElement zbxHost in ZabbixManagers.ZabbixConfigElements) { //Realiza teste de conex'ao em cada um dos zabbix listados try { Console.Write("[*] Zabbix agent on " + zbxHost.Host + ":" + zbxHost.Port); using (Zabbix zbx = new Zabbix(zbxHost.Host, zbxHost.Port)) { String tst = zbx.GetItem("system.hostname"); } zbxConfig.Add(new ZabbixConfig(zbxHost.Name, zbxHost.Host, zbxHost.Port)); Console.WriteLine("\t\tOK"); } catch { Console.WriteLine("\t\tError"); Console.WriteLine("Error Getting information from Zabbix " + zbxHost.Name + " (" + zbxHost.Host + ":" + zbxHost.Port + ")"); return; } } } Profile prof = null; /* * if (args.Length > 4) * { * try * { * FileInfo profileFile = new FileInfo(args[4]); * if (profileFile.Extension == ".prof") * { * prof = new Profile(); * prof.LoadProfile(profileFile.FullName); * * if ((prof.BaseUri == null) || (prof.Uris.Count == 0)) * prof = null; * } * } * catch(Exception ex) { * prof = null; * } * }*/ IPEndPoint proxy = null;// new IPEndPoint(IPAddress.Parse("10.0.10.1"), 80); if (!String.IsNullOrEmpty((string)ConfigurationManager.AppSettings["proxy"])) { Uri tProxy = null; try { tProxy = new Uri(ConfigurationManager.AppSettings["proxy"]); proxy = new IPEndPoint(IPAddress.Parse(tProxy.Host), tProxy.Port); } catch (Exception ex) { Console.WriteLine("Proxy not valid. Proxy should be an IP URI. Ex: http://10.10.10.10:3389"); return; } } Int32 sleepTime = 0; try { Int32.TryParse((string)ConfigurationManager.AppSettings["sleeptime"], out sleepTime); } catch { } TestBuilder builder = new TestBuilder(); /* * if (prof != null) * builder.Fetch(prof); * else * builder.Fetch( * site, * proxy, * 1); */ // Console.WriteLine("[+] Building test environment..."); builder.Fetch( site, proxy, levels, headers); TestEnvironment env = builder.Build(proxy, type, 5); env.HTTPHeaders = headers; env.ZabbixMonitors = zbxConfig; env.SleepTime = sleepTime; env.VirtualUsers = connCount; env.ConnectionString = new DbConnectionString(ConfigurationManager.ConnectionStrings["LoadTest"]); env.Start(); Console.WriteLine("[+] Starting test..."); Console.WriteLine("[+] System started (" + (prof != null ? "prof" : "scan") + ")!"); Console.WriteLine("[+] Total test duration: " + duration + " seconds"); Console.WriteLine("[!] Press CTRL + C to finish the teste and generate report"); _running = true; _tmpEnd = new Timer(new TimerCallback(tmpEnd), null, duration * 1000, duration * 1000); Console.CancelKeyPress += new ConsoleCancelEventHandler(myHandler); Console.WriteLine(""); DateTime dStart = DateTime.Now; while (_running) { System.Threading.Thread.Sleep(500); TimeSpan ts = DateTime.Now - dStart; Console.Write("\r"); Console.Write("Test Duration: {0}", ts.ToString(@"hh\:mm\:ss")); } ClearCurrentConsoleLine(); Console.WriteLine(""); env.Stop(); /* * TestEnvironment env = new TestEnvironment(); * env.LoadConfig("temp.env");*/ //Gera o relatório Console.WriteLine("[+] Building report..."); env.BuildReports(); //env.DropDatabase(); }
private void DoWork(object sender, DoWorkEventArgs e) { if (!testCreatingWorker.CancellationPending) { List <Assembly> keys = dllToData.Keys.Select(item => item).ToList(); Parallel.ForEach(keys, (key, pls1) => { if (token.IsCancellationRequested) { log.Info("Выход из потока создания тестов"); pls1.Break(); } List <DataTable> value = dllToData[key]; BlockingCollection <DataTable> blockedValue = new BlockingCollection <DataTable>(); foreach (DataTable v in value) { blockedValue.Add(v); } //DataTable dt = new DataTable(); ParallelLoopResult result = Parallel.ForEach(blockedValue, (data, pls2) => { if (token.IsCancellationRequested) { log.Info("Выход из потока создания тестов"); pls2.Break(); } List <DataRow> rows = data.Rows.Cast <DataRow>().Select(item => item).ToList(); BlockingCollection <DataRow> blockedRow = new BlockingCollection <DataRow>(); foreach (DataRow row in rows) { blockedRow.Add(row); } Parallel.ForEach(blockedRow, (row, pls3) => { string logmsg = null; foreach (Type type in key.GetTypes()) { if (token.IsCancellationRequested) { log.Info("Выход из цикла создания тестов"); return; } if (typeof(TestBuilder).IsAssignableFrom(type)) { TestBuilder builder = (TestBuilder)Activator.CreateInstance(type); JObject config = (JObject)configuration[key.GetName().Name]; DataBuffer buffer = new DataBuffer(contacts, beneficiars, logins); Test test = null; try { test = builder.Build(config, buffer, row); if (!test.InitError) { logmsg = String.Format("Создан тест id={0} file={1} casenum={2}" , test.Id , test.File , test.Casenum); log.Info(logmsg); tests.Add(test); } else { logmsg = String.Format("ОШИБКА!!!Ошибка создания теста id={0} file={1} casenum={2}. Подробности в логах" , test.Id , test.File , test.Casenum); log.Error(logmsg); } } catch (UriFormatException ex) { log.Error("Ошибка uri", ex); cancelTokenSource.Cancel(); if (token.IsCancellationRequested) { MessageBox.Show("Ошибка url.Создание тестов прервано", "Ошибка!"); pls3.Break(); } } } } //this.testCreatingWorker.ReportProgress(0, logmsg); this.richTextBox1.Invoke(new Action(() => this.richTextBox1.AppendText(logmsg + "\n"))); this.currentCreatedTest.Invoke(new Action(() => this.currentCreatedTest.Text = (Int32.Parse(this.currentCreatedTest.Text) + 1).ToString())); }); }); }); } }