public void ServiceFunctions_AddService_InvokesNextFunctionWhenPathNotCorrect() { // Arrange #region BodyString var bodyString = @"# BodyString Method: GET # This path is irrelevant Path: /api/things/53"; #endregion var request = new TestHttpRequest() { Method = "POST", // This path causes the request not to match the required pattern. Path = "/__vs/somethingWrong", BodyString = bodyString }; var response = new TestHttpResponse(); var context = new TestHttpContext(request, response); var numCallsToNext = 0; Task next() { numCallsToNext++; return(Task.CompletedTask); } // Act ServiceFunctions.AddService(context, next).Wait(); // Assert Assert.AreEqual(1, numCallsToNext); }
public void ServiceFunctions_AddService_ReturnsOkAndServiceId() { // Arrange #region BodyString var bodyString = @"# BodyString Method: GET Path: /api/things/53"; #endregion var request = new TestHttpRequest() { Method = "POST", Path = "/__vs/services", BodyString = bodyString }; var response = new TestHttpResponse(); var context = new TestHttpContext(request, response); Task next() => Task.CompletedTask; // Act ServiceFunctions.AddService(context, next).Wait(); // Assert Assert.AreEqual(200, response.StatusCode); Assert.AreEqual("text/plain", response.ContentType); Assert.IsTrue(Guid.TryParse(response.ReadBody(), out Guid serviceId)); Assert.AreNotEqual(Guid.Empty, serviceId); }
public bool insertSensor(Sensor sensor) { string SID, Name, Description, Settings; int count = (int)executeScalar("SELECT COUNT(*) FROM Sensors WHERE SID='" + sensor.SID + "'"); if (count > 0) { return(false); } SID = "'" + sensor.SID + "'"; Name = "'" + sensor.Name + "'"; Description = sensor.Description == null ? "NULL" : "'" + sensor.Description + "'"; Settings = "'" + ServiceFunctions.serializeProperties(sensor.Settings) + "'"; string query = "INSERT INTO SENSORS (SID, [Name], Description, Settings) VALUES (" + SID + ", " + Name + ", " + Description + ", " + Settings + ")"; try { int res = executeNonQuery(query); sensorList = getSensorList(); return(res > 0); } catch (Exception ex) { sensorList = getSensorList(); throw ex; } }
public bool updateSensor(Sensor sensor, string sid) { string SID, Name, Description, Settings; int id = getIDbySID(sid); int count = (int)executeScalar("SELECT COUNT(*) FROM Sensors WHERE ID=" + id); if (count == 0) { return(false); } SID = qouted(sensor.SID); Name = qouted(sensor.Name); Description = sensor.Description == null ? "NULL" : qouted(sensor.Description); Settings = "'" + ServiceFunctions.serializeProperties(sensor.Settings) + "'"; string query = "UPDATE SENSORS SET [SID]=" + SID + ", [Name]=" + Name + ", Description=" + Description + ", Settings=" + Settings + " WHERE ID=" + id; try { int res = executeNonQuery(query); sensorList = getSensorList(); return(res > 0); } catch (Exception ex) { sensorList = getSensorList(); throw ex; } }
public void ServiceFunctions_DeleteAllServices_ReturnsNotFoundAfterDeleting() { // Arrange var service1Id = AddService("GET", "/api/resource/5be5223c-70d4-4a61-aa5c-be5d60d90001"); var service2Id = AddService("GET", "/api/resource/5be5223c-70d4-4a61-aa5c-be5d60d90002"); var service3Id = AddService("GET", "/api/resource/5be5223c-70d4-4a61-aa5c-be5d60d90003"); var request = new TestHttpRequest() { Method = "DELETE", Path = "/__vs/services", BodyString = string.Empty }; var response = new TestHttpResponse(); var context = new TestHttpContext(request, response); Task next() => Task.CompletedTask; // Act ServiceFunctions.DeleteAllServices(context, next).Wait(); // Assert Assert.AreEqual(200, response.StatusCode); Assert.AreEqual(404, InvokeService("GET", "/api/resource/5be5223c-70d4-4a61-aa5c-be5d60d90001"), "Invoking service1 should result in a 404."); Assert.AreEqual(404, InvokeService("GET", "/api/resource/5be5223c-70d4-4a61-aa5c-be5d60d90002"), "Invoking service2 should result in a 404."); Assert.AreEqual(404, InvokeService("GET", "/api/resource/5be5223c-70d4-4a61-aa5c-be5d60d90003"), "Invoking service3 should result in a 404."); }
public ActionResult Index() { ViewBag.DropDown = _db.DropDownListGeneration(); ViewBag.Result = ServiceFunctions.GetResultField(); ViewBag.Images = _db.GetAllBoards(); return(View()); }
public void ServiceFunctions_QueryService_ReturnsServiceStats() { // Arrange var serviceId = AddService("GET", "/api/serviceToBeQueried/1"); InvokeService("GET", "/api/serviceToBeQueried/1", "Lorem ipsum dolor"); InvokeService("GET", "/api/serviceToBeQueried/1", "sit amet, consectetur adipiscing"); var request = new TestHttpRequest() { Method = "GET", Path = "/__vs/services/" + serviceId }; var response = new TestHttpResponse(); var context = new TestHttpContext(request, response); Task next() => Task.CompletedTask; // Act ServiceFunctions.QueryService(context, next).Wait(); // Assert Assert.AreEqual(200, response.StatusCode); Assert.AreEqual("text/plain", response.ContentType); var expectedResponseBody = new StringBuilder() .AppendLine($"CallCount: 2") .AppendLine() .AppendLine("LastRequestBody:") .Append("sit amet, consectetur adipiscing") .ToString(); Assert.AreEqual(expectedResponseBody, response.ReadBody()); }
public void ChooseStats() { int _attackCoefficient = 0; int _defenceCoefficient = 0; int _socialCoefficient = 0; do { _attackCoefficient = 0; _defenceCoefficient = 0; _socialCoefficient = 0; Console.WriteLine("\nTo make your attacks more effective, press 1, to make your evasive manoeuvres more effective, press 2, to make your social interactions more effective, any other key"); int result = ServiceFunctions.ChoosingRightKey(Console.ReadKey().KeyChar); switch (result) { case 1: _attackCoefficient = 1; break; case 2: _defenceCoefficient = 1; break; default: _socialCoefficient = 1; break; } Console.WriteLine($"Your defence skill is {_defenceCoefficient}, your attack skill is {_attackCoefficient}, your social skill is {_socialCoefficient}. If you agree, enter 1, if not, enter anything else. "); }while (ServiceFunctions.ChoosingRightKey(Console.ReadKey().KeyChar) != 1); attackCoefficient += _attackCoefficient; defenceCoefficient += _defenceCoefficient; socialCoefficient += _socialCoefficient; }
private void MarkDefaultEdge(TVertex src, TVertex stc) { if (!Field.SetModelDefaultOptions(ServiceFunctions.EdgeRepresentation(src.GetRepresentation(), stc.GetRepresentation()))) { Field.SetModelDefaultOptions(ServiceFunctions.EdgeRepresentation(stc.GetRepresentation(), src.GetRepresentation())); } }
private void MarkEdge(TVertex src, TVertex stc, RGBcolor color, int width) { if (!Field.SetColorAndWidth(ServiceFunctions.EdgeRepresentation(src.GetRepresentation(), stc.GetRepresentation()), color, width)) { Field.SetColorAndWidth(ServiceFunctions.EdgeRepresentation(stc.GetRepresentation(), src.GetRepresentation()), color, width); } }
public override ValidationResult IsConditionalValid(string property, object value, ValidationContext validationContext) { var dependsOnProp = validationContext.ObjectType.GetProperty(property.Trim()); var postcode = dependsOnProp.GetValue(validationContext.ObjectInstance)?.ToString(); if (!string.IsNullOrEmpty(UKPostCodeRegex) && !string.IsNullOrEmpty(EnglishOrBFPOPostCodeRegex) && !string.IsNullOrEmpty(BfpoPostCodeRegex) && !string.IsNullOrEmpty(postcode?.Trim())) { if (IsNotBfpo) { // It applies to Town if (!ServiceFunctions.IsValidRegexValue(postcode, BfpoPostCodeRegex) && string.IsNullOrEmpty(value?.ToString())) { return(new ValidationResult(ErrorMessage)); } } // It applies to AddressLine2 & AddressLine3 (when other dependent property is valid UK BFPO postcode) else if (!IsNonEnglishBfpo && ServiceFunctions.IsValidDoubleRegexValue(postcode, UKPostCodeRegex, BfpoPostCodeRegex, true) && string.IsNullOrEmpty(value?.ToString())) { return(new ValidationResult(ErrorMessage)); } // It applies to AlternativePostCode // Here we are evaluating the value of the HomePostCode (postcode), not AlternativePostCode if (IsNonEnglishBfpo && !ServiceFunctions.IsValidDoubleRegexValue(postcode, UKPostCodeRegex, EnglishOrBFPOPostCodeRegex, true) && string.IsNullOrEmpty(value?.ToString())) { return(new ValidationResult(ErrorMessage)); } } return(null); }
public void ServiceFunctions_DeleteService_InvokesNextFunctionWhenPathNotCorrect() { // Arrange var request = new TestHttpRequest() { Method = "GET", // This path causes the request not to match the required pattern. Path = "/__vs/badResource/ab61870e-8427-ae57effd5c6a", BodyString = string.Empty }; var response = new TestHttpResponse(); var context = new TestHttpContext(request, response); var numCallsToNext = 0; Task next() { numCallsToNext++; return(Task.CompletedTask); } // Act ServiceFunctions.DeleteService(context, next).Wait(); // Assert Assert.AreEqual(1, numCallsToNext); }
private void FindPath(Graph <TVertex> G, TVertex source, TVertex stock, SortedDictionary <TVertex, TVertex> parents) { if (stock.Equals(source)) { Field.SetColor(source.GetRepresentation(), RGBcolor.DarkGreen); Thread.Sleep(500); } else if (parents[stock] == null) { //Field.UnmarkGraphModels(); Field.UserInterface.PostMessage($"Путь из {source} в {stock} не существует"); return; } else { FindPath(G, source, parents[stock], parents); Thread.Sleep(500); var tmp = parents[stock]; if (!Field.SetColor(ServiceFunctions.EdgeRepresentation(tmp?.ToString(), stock.ToString()), RGBcolor.DarkGreen) && !G.IsOrgraph) { Field.SetColor(ServiceFunctions.EdgeRepresentation(tmp?.ToString(), stock.ToString()), RGBcolor.DarkGreen); } Thread.Sleep(500); Field.SetColor(stock.GetRepresentation(), RGBcolor.DarkGreen); } }
private async void InitAndroidPushNotifier() { Common.AndroidPushNotifier = new AndroidPushNotifier(await MSAAuthenticator.GetUserUniqueIdAsync()); Common.AndroidPushNotifier.Devices.CollectionChanged += DevicesCollectionChanged; await Common.AndroidPushNotifier.DiscoverAndroidDevices(ServiceFunctions.GetDeviceUniqueId()); }
public override void OnBackPressed() { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed ServiceFunctions.RegisterDevice(this); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed base.OnBackPressed(); }
private int BFS(TVertex s, TVertex t, out SortedDictionary <TVertex, TVertex> p) { int sleep = 400; var color = RGBcolor.DarkGreen; int incrFlow = int.MaxValue; Field.RefreshDefault(false); p = new SortedDictionary <TVertex, TVertex>(); foreach (var v in G.AdjList.Keys) { p[v] = null; } var Q = new Queue <TVertex>(); Q.Enqueue(s); while (Q.Count != 0) { var v = Q.Dequeue(); foreach (var uw in G[v]) { var u = uw.Vertex; if (c[v][u] > 0 && p[u] == null) { Q.Enqueue(u); p[u] = v; if (u == t) { List <TVertex> vs = new List <TVertex>(); var last = t; while (last != null) { vs.Add(last); last = p[last]; } vs.Reverse(); for (int i = 0; i < vs.Count - 1; i++) { if (c[vs[i]][vs[i + 1]] < incrFlow) { incrFlow = c[vs[i]][vs[i + 1]]; } } for (int j = 0; j < vs.Count - 1; j++) { Field.SetColorAndWidth(vs[j].GetRepresentation(), color, 2); Thread.Sleep(sleep); Field.SetColorAndWidth(ServiceFunctions.EdgeRepresentation(vs[j].GetRepresentation(), vs[j + 1].GetRepresentation()), color, 2); Thread.Sleep(sleep); } Field.SetColorAndWidth(vs[vs.Count - 1].GetRepresentation(), color, 2); Thread.Sleep(sleep); return(incrFlow); } } } } return(0); }
public void ServiceFunctions_DeleteAllServices_ThrowsOnNullNextFunction() { // Arrange var context = new TestHttpContext(); Func <Task> nullNextFunction = null; // Act ServiceFunctions.DeleteAllServices(context, nullNextFunction).Wait(); }
public void ServiceFunctions_AddService_ThrowsOnNullNextFunction() { // Arrange HttpContext context = new TestHttpContext(); Func <Task> nullNextFunction = null; // Act ServiceFunctions.AddService(context, nullNextFunction).Wait(); }
void SendRegistrationToServer(string token) { Context context = this; Task.Run(async() => { await ServiceFunctions.RegisterDevice(context); }); }
public AEdgeModel(AVertexModel source, AVertexModel stock, string weight) : base(ServiceFunctions.EdgeRepresentation(source.VertexStr, stock.VertexStr)) { StringRepresent = weight; Source = source; Stock = stock; Weight = weight; Weighted = weight != null; }
private void OnCreate_Main() { showToolbarMenu = true; var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); //Toolbar will now take on default actionbar characteristics SetSupportActionBar(toolbar); SupportActionBar.Title = "Roamit"; toolbar.Background = new Android.Graphics.Drawables.ColorDrawable(Android.Graphics.Color.ParseColor("#111111")); FindViewById <RelativeLayout>(Resource.Id.main_actions).Visibility = ViewStates.Visible; FindViewById <RelativeLayout>(Resource.Id.main_share).Visibility = ViewStates.Gone; //FindViewById<Button>(Resource.Id.button3).Click += Button3_Click; //FindViewById<Button>(Resource.Id.mainSendMessageCarrier).Click += SendMessageCarrier_Click; var mainLayout = FindViewById <LinearLayout>(Resource.Id.mainLayout); clipboardButton = FindViewById <Button>(Resource.Id.clipboardButton); sendUrlButton = FindViewById <Button>(Resource.Id.main_btn_openUrl); sendFileButton = FindViewById <Button>(Resource.Id.sendFileButton); sendPictureButton = FindViewById <Button>(Resource.Id.sendPictureButton); clipboardPreviewText = FindViewById <TextView>(Resource.Id.clipboardPreviewText); clipboardButton.Click += SendClipboard_Click; sendUrlButton.Click += SendUrlButton_Click; sendFileButton.Click += SendFile_Click; sendPictureButton.Click += SendPictureButton_Click; mainLayout.ViewTreeObserver.GlobalLayout += (ss, ee) => { int x = Math.Min(mainLayout.Width, mainLayout.Height); sendFileButton.SetWidth((int)(x * 0.5)); sendFileButton.SetHeight((int)(x * 0.5)); clipboardButton.SetWidth((int)(x * 0.25)); clipboardButton.SetHeight((int)(x * 0.25)); sendPictureButton.SetWidth((int)(x * 0.25)); sendPictureButton.SetHeight((int)(x * 0.25)); }; SetClipboardPreviewText(); clipboardUpdateTimer = new Timer(ClipboardUpdateTimer_Tick, null, 0, 1000); Context context = this; Task.Run(async() => { #if DEBUG FirebaseInstanceId.Instance.DeleteInstanceId(); #endif await ServiceFunctions.RegisterDevice(context); RefreshUserTrialStatus(); }); Analytics.TrackPage("MainPage"); }
public void ServiceFunctions_QueryService_ThrowsOnNullContext() { // Arrange HttpContext nullContext = null; Task next() => Task.CompletedTask; // Act ServiceFunctions.QueryService(nullContext, next).Wait(); }
public void ServiceFunctions_DeleteAllServices_ThrowsOnNullContext() { // Arrange HttpContext nullContext = null; Task next() => Task.CompletedTask; // Act ServiceFunctions.DeleteAllServices(nullContext, next).Wait(); }
public static float[] rangeCoeffs() { TeraDevice t = new TeraDevice(); float[] a = new float[t.rangeCoeffs.Length]; for (int i = 0; i < t.rangeCoeffs.Length; i++) { a[i] = ServiceFunctions.getRandomNearOne(); } return(a); }
public ObservableCollection <DocumentVM> ConvertDocumentToDocumentVM(List <Document> docs) { List <DocumentVM> result = new List <DocumentVM>(); foreach (Document doc in docs) { doc.company = ServiceFunctions.CompanyRenamer(doc.company); result.Add(new DocumentVM(doc)); } return(new ObservableCollection <DocumentVM>(result)); }
public void RefreshMeasureTimer(int seconds) //Для обновления поля результата из другого потока в котором проходит испытание { if (InvokeRequired) { BeginInvoke(new refreshMeasureTimerDelegate(RefreshMeasureTimer), new object[] { seconds }); return; } else { this.measTimeLbl.Text = ServiceFunctions.TimerTime(seconds); } }
public void preGiving() { string result; do { Console.WriteLine("\nType the name of your creature"); result = Console.ReadLine(); Console.WriteLine($"Your name is {result}. If you agree, enter 1, if not, enter anything else."); }while (ServiceFunctions.ChoosingRightKey(Console.ReadKey().KeyChar) != 1); name = result; }
protected decimal getDecimalFromRow(string colName) { object v = getAttrFromRow(colName); if (v != null) { return(ServiceFunctions.convertToDecimal(v)); } else { return(0); } }
protected override void fillParametersFromRow(DataRow row) { this.Id = row["id"].ToString(); this.Name = row["name"].ToString(); for (int res = 0; res < ResistanceList.Length; res++) { for (int volt = 0; volt < ResistanceList[res].Length; volt++) { if (ResistanceList[res][volt] >= 0) { ResistanceList[res][volt] = ServiceFunctions.convertToFloat(row[String.Format("res{0}_volt{1}", res, volt)]); } } } }
// Invokes a service and returns the HTTP status code result. // // Do not use this to test the ServiceFunctions.InvokeService method. // This was designed to help other tests and assumes that the // ServiceFunctions.InvokeService has already been tested. private static int InvokeService(string method, string path, string bodyString = "") { var request = new TestHttpRequest() { Method = method, Path = path, BodyString = bodyString }; var response = new TestHttpResponse(); var context = new TestHttpContext(request, response); Task next() => Task.CompletedTask; ServiceFunctions.InvokeService(context, next).Wait(); return(response.StatusCode); }