private void WCFSendMeasurements(int measurementsCount, int dataCount, bool useLocation, bool createFaultyMeasurements) { MeasurementsServiceClient client = new MeasurementsServiceClient(); DateTimeOffset measTime = DateTimeOffset.Now; var package = measTime.GetMeasurementPackageWithXMeasurementsAndYData("WCF client", measurementsCount, dataCount, useLocation); if (createFaultyMeasurements) { var lastMeasurement = package.Measurements[package.Measurements.Length - 1]; if (lastMeasurement.Data.Length > 1) { lastMeasurement.Data[0].Tag = lastMeasurement.Data[1].Tag; } } Stopwatch sw = Stopwatch.StartNew(); var result = client.SaveMeasurementPackage(package); sw.Stop(); client.Close(); Trace.WriteLine(string.Format("SaveMeasurementPackage with {0} measurement took {1} ms", package.Measurements.Length, sw.ElapsedMilliseconds)); Assert.IsNotNull(result); if (createFaultyMeasurements) { Assert.IsFalse(result.Success); Assert.IsNotNull(result.Failures); foreach (var f in result.Failures) { Trace.WriteLine(string.Format("{0}, {1}, {2}", f.Index, f.Code, f.Reason)); } } else { Assert.IsTrue(result.Success); Assert.IsNull(result.Failures); } //Assert.AreEqual<int>(result.Statuses.Length, measurementsCount); //var item = result.Statuses[0]; //Assert.IsTrue(item.IsSaved); //Assert.AreEqual<DateTimeOffset>(item.MeasurementTimeStamp, measTime); }
public void WCFSendMeasurementPackageFaultyLocation() { MeasurementsServiceClient client = new MeasurementsServiceClient(); DateTimeOffset measTime = DateTimeOffset.Now; var package = measTime.GetMeasurementPackage("WCF client"); package.Measurements[0].Location.Latitude = 91; // set invalid latitude try { var result = client.SaveMeasurementPackage(package); Assert.Fail(); // service should throw } catch (FaultException fe) { Trace.TraceError(fe.ToString()); Assert.IsTrue(fe.Message.Contains("24201: Latitude values must be between -90 and 90 degrees.")); } }
public void WCFSendMeasurementPackage() { MeasurementsServiceClient client = new MeasurementsServiceClient(); DateTimeOffset measTime = DateTimeOffset.Now; var package = measTime.GetMeasurementPackage("WCF client"); try { var result = client.SaveMeasurementPackage(package); Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsNull(result.Failures); } catch (FaultException fe) { Trace.TraceError(fe.ToString()); Assert.Fail(); } }
public void SendMeasurementPackage() { // init the client MeasurementsServiceClient client = new MeasurementsServiceClient(); // create the measurement package and populate it MeasurementPackage package = new MeasurementPackage(); package.Key = "your-key-goes-here"; // create a collection of measurements List <MeasurementModel> measurements = new List <MeasurementModel>(); // create a measurement MeasurementModel m = new MeasurementModel() { Object = "your-measurement-object", Tag = "your-measurement-tag", Timestamp = DateTimeOffset.Now, Location = new Location() { Latitude = 62.8989, Longitude = 27.6630 } }; // add some data to your measurement DataModel d = new DataModel() { Tag = "your-data-tag", Value = 3.14 }; // add data to measurement m.Data = new DataModel[1]; m.Data[0] = d; // add measurement to measurements collection measurements.Add(m); // add measurements collection to measurement package package.Measurements = measurements.ToArray(); // save the measurement package and check the result SaveResult result = client.SaveMeasurementPackage(package); }