SetInput() публичный Метод

public SetInput ( Stream stream ) : Deserializer
stream Stream
Результат Deserializer
Пример #1
0
        public void MetricsCollection ()
        {
            string id = "myuniqueid";
            var metrics = new MetricsCollection (id, new MemorySampleStore ());
            Assert.AreEqual ("myuniqueid", metrics.AnonymousUserId);

            metrics.AddDefaults ();
            Assert.IsTrue (metrics.Count > 0);

            string metrics_str = metrics.ToJsonString ();
            Assert.IsTrue (metrics_str.Contains ("\"ID\":\"myuniqueid\""));

            // tests/Makefile.am runs the tests with Locale=it_IT
            Assert.IsTrue (metrics_str.Contains ("it-IT"));

            // Make sure DateTime samples are saved as invariant strings
            var now = DateTime.Now;
            var time_metric = metrics.Add ("Foo", now);
            Assert.AreEqual (Hyena.DateTimeUtil.ToInvariantString (now), metrics.Store.GetFor (time_metric).First ().Value);

            // Make sure we can read the JSON back in
            var ds = new Json.Deserializer ();
            ds.SetInput (metrics.ToJsonString ());
            var json_obj = ds.Deserialize () as JsonObject;
            Assert.AreEqual (id, json_obj["ID"]);
            Assert.IsTrue (json_obj["Metrics"] is JsonObject);
        }
		public void ParseTest ()
		{
			Deserializer deserializer = new Deserializer ();
			
			string refJson =
				"{ \"api-ref\" : \"http://domain/api/1.0/sally/notes\", \"href\" : \"http://domain/sally/notes\"}";
			deserializer.SetInput (refJson);
			JsonObject refObj = (JsonObject) deserializer.Deserialize ();
			ResourceReference resourceRef = ResourceReference.ParseJson (refObj);

			Assert.AreEqual ("http://domain/api/1.0/sally/notes",
			                 resourceRef.ApiRef,
			                 "ApiRef");
			Assert.AreEqual ("http://domain/sally/notes",
			                 resourceRef.Href,
			                 "Href");

			refJson =
				"{ \"api-ref\" : \"http://domain/api/1.0/sally/notes\"}";
			deserializer.SetInput (refJson);
			refObj = (JsonObject) deserializer.Deserialize ();
			resourceRef = ResourceReference.ParseJson (refObj);

			Assert.AreEqual ("http://domain/api/1.0/sally/notes",
			                 resourceRef.ApiRef,
			                 "ApiRef");
			Assert.IsNull (resourceRef.Href, "Href should be null when none specified");

			refJson =
				"{ \"href\" : \"http://domain/sally/notes\"}";
			deserializer.SetInput (refJson);
			refObj = (JsonObject) deserializer.Deserialize ();
			resourceRef = ResourceReference.ParseJson (refObj);

			Assert.AreEqual ("http://domain/sally/notes",
			                 resourceRef.Href,
			                 "Href");
			Assert.IsNull (resourceRef.ApiRef, "ApiRef should be null when none specified");
		}
Пример #3
0
		public void ParseTest ()
		{
			Deserializer deserializer = new Deserializer ();

			string noteJson = "{\"guid\": \"002e91a2-2e34-4e2d-bf88-21def49a7705\"," +
				"\"title\" :\"New Note 6\"," +
				"\"note-content\" :\"New Note 6\\nDescribe youre note <b>here</b>.\"," +
				"\"note-content-version\" : 0.2," +
				"\"last-change-date\" : \"2009-04-19T21:29:23.2197340-07:00\"," +
				"\"last-metadata-change-date\" : \"2009-04-19T21:29:23.2197340-07:00\"," +
				"\"create-date\" : \"2008-03-06T13:44:46.4342680-08:00\"," +
				"\"last-sync-revision\" : 57," +
				"\"open-on-startup\" : false," +
				"\"tags\" : [\"tag1\",\"tag2\"]" +
				"}";
			deserializer.SetInput (noteJson);
			JsonObject noteObj = (JsonObject) deserializer.Deserialize ();
			//Assert.AreEqual (57, (int)noteObj["last-sync-revision"]);
			NoteInfo note = NoteInfo.ParseJson (noteObj);
			Assert.AreEqual ("002e91a2-2e34-4e2d-bf88-21def49a7705", note.Guid, "GUID");
			Assert.AreEqual ("New Note 6\nDescribe youre note <b>here</b>.", note.NoteContent, "NoteContent");
			Assert.AreEqual (0.2, note.NoteContentVersion, "NoteContentVersion");
			Assert.AreEqual ("New Note 6", note.Title, "Title");
			Assert.AreEqual (DateTime.Parse ("2009-04-19T21:29:23.2197340-07:00"),
					note.LastChangeDate, "LastChangeDate");
			Assert.AreEqual (DateTime.Parse ("2009-04-19T21:29:23.2197340-07:00"),
					note.LastMetadataChangeDate, "LastMetadataChangeDate");
			Assert.AreEqual (DateTime.Parse ("2008-03-06T13:44:46.4342680-08:00"),
					note.CreateDate, "CreateDate");
			Assert.AreEqual (57, note.LastSyncRevision, "LastSyncRevision");

			Assert.IsTrue (note.OpenOnStartup.HasValue, "OpenOnStartup should have value");
			Assert.IsFalse (note.OpenOnStartup.Value, "OpenOnStartup value");
			
			Assert.IsNotNull (note.Tags, "Tags should not be null");

			// TODO: Test resourceref,command,lack of guid,nullables,etc,
			//       ApplicationException when missing comma in string, wrong type, etc
		}
		public void ExceptionTest ()
		{
			bool expectedExceptionRaised = false;
			try {
				ResourceReference.ParseJson (null);
			} catch (ArgumentNullException) {
				expectedExceptionRaised = true;
			}
			Assert.IsTrue (expectedExceptionRaised,
			               "ArgumentNullException expected on null input");

			expectedExceptionRaised = false;
			
			Deserializer deserializer = new Deserializer ();
			string invalidRefJson =
				"{ \"api-ref\" : 5, \"href\" : \"http://domain/sally/notes\"}";
			deserializer.SetInput (invalidRefJson);
			JsonObject refObj = (JsonObject) deserializer.Deserialize ();
			try {
				ResourceReference.ParseJson (refObj);
			} catch (InvalidCastException) {
				expectedExceptionRaised = true;
			}
			Assert.IsTrue (expectedExceptionRaised,
			               "InvalidCastException expected on invalid input");
		}