[tomboy] Add initial unit tests for WebSyncService, some not yet started.



commit deb42e1702f4d05c3b0c2381980a086c4ba8415d
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date:   Sun May 17 07:41:40 2009 -0700

    Add initial unit tests for WebSyncService, some not yet started.
---
 .../WebSyncService/Api/Tests/NoteInfoTests.cs      |   83 +++++++++++++++
 .../Api/Tests/ResourceReferenceTests.cs            |  111 ++++++++++++++++++++
 .../WebSyncService/Api/Tests/UserInfoTests.cs      |   37 +++++++
 Tomboy/Addins/WebSyncService/Makefile.am           |    2 +
 .../WebSyncService/Tests/NoteConvertTests.cs       |   43 ++++++++
 5 files changed, 276 insertions(+), 0 deletions(-)

diff --git a/Tomboy/Addins/WebSyncService/Api/Tests/NoteInfoTests.cs b/Tomboy/Addins/WebSyncService/Api/Tests/NoteInfoTests.cs
new file mode 100644
index 0000000..cb2ccbe
--- /dev/null
+++ b/Tomboy/Addins/WebSyncService/Api/Tests/NoteInfoTests.cs
@@ -0,0 +1,83 @@
+// Permission is hereby granted, free of charge, to any person obtaining 
+// a copy of this software and associated documentation files (the 
+// "Software"), to deal in the Software without restriction, including 
+// without limitation the rights to use, copy, modify, merge, publish, 
+// distribute, sublicense, and/or sell copies of the Software, and to 
+// permit persons to whom the Software is furnished to do so, subject to 
+// the following conditions: 
+//  
+// The above copyright notice and this permission notice shall be 
+// included in all copies or substantial portions of the Software. 
+//  
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+// 
+// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
+// 
+// Authors: 
+//      Sandy Armstrong <sanfordarmstrong gmail com>
+// 
+
+#if ENABLE_TESTS
+
+using System;
+
+using Tomboy.WebSync.Api;
+using Hyena.Json;
+
+using NUnit.Framework;
+
+namespace Tomboy.WebSync.Api.Tests
+{
+	[TestFixture]
+	public class NoteInfoTests
+	{
+		[Test]
+		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
+		}
+	}
+}
+
+#endif
\ No newline at end of file
diff --git a/Tomboy/Addins/WebSyncService/Api/Tests/ResourceReferenceTests.cs b/Tomboy/Addins/WebSyncService/Api/Tests/ResourceReferenceTests.cs
new file mode 100644
index 0000000..0d54ed7
--- /dev/null
+++ b/Tomboy/Addins/WebSyncService/Api/Tests/ResourceReferenceTests.cs
@@ -0,0 +1,111 @@
+// Permission is hereby granted, free of charge, to any person obtaining 
+// a copy of this software and associated documentation files (the 
+// "Software"), to deal in the Software without restriction, including 
+// without limitation the rights to use, copy, modify, merge, publish, 
+// distribute, sublicense, and/or sell copies of the Software, and to 
+// permit persons to whom the Software is furnished to do so, subject to 
+// the following conditions: 
+//  
+// The above copyright notice and this permission notice shall be 
+// included in all copies or substantial portions of the Software. 
+//  
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+// 
+// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
+// 
+// Authors: 
+//      Sandy Armstrong <sanfordarmstrong gmail com>
+// 
+
+#if ENABLE_TESTS
+
+using System;
+
+using Tomboy.WebSync.Api;
+using Hyena.Json;
+
+using NUnit.Framework;
+
+namespace Tomboy.WebSync.Api.Tests
+{
+	[TestFixture]
+	public class ResourceReferenceTests
+	{
+		[Test]
+		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");
+		}
+
+		[Test]
+		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");
+		}
+	}
+}
+
+#endif
\ No newline at end of file
diff --git a/Tomboy/Addins/WebSyncService/Api/Tests/UserInfoTests.cs b/Tomboy/Addins/WebSyncService/Api/Tests/UserInfoTests.cs
new file mode 100644
index 0000000..8a41a32
--- /dev/null
+++ b/Tomboy/Addins/WebSyncService/Api/Tests/UserInfoTests.cs
@@ -0,0 +1,37 @@
+// Permission is hereby granted, free of charge, to any person obtaining 
+// a copy of this software and associated documentation files (the 
+// "Software"), to deal in the Software without restriction, including 
+// without limitation the rights to use, copy, modify, merge, publish, 
+// distribute, sublicense, and/or sell copies of the Software, and to 
+// permit persons to whom the Software is furnished to do so, subject to 
+// the following conditions: 
+//  
+// The above copyright notice and this permission notice shall be 
+// included in all copies or substantial portions of the Software. 
+//  
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+// 
+// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
+// 
+// Authors: 
+//      Sandy Armstrong <sanfordarmstrong gmail com>
+// 
+
+#if ENABLE_TESTS
+
+using System;
+
+namespace Tomboy.WebSync.Api.Tests
+{
+	public class UserInfoTests
+	{
+	}
+}
+
+#endif
\ No newline at end of file
diff --git a/Tomboy/Addins/WebSyncService/Makefile.am b/Tomboy/Addins/WebSyncService/Makefile.am
index 203204d..1c90695 100644
--- a/Tomboy/Addins/WebSyncService/Makefile.am
+++ b/Tomboy/Addins/WebSyncService/Makefile.am
@@ -26,10 +26,12 @@ CSFILES = \
 	$(srcdir)/NoteConvert.cs       	\
 	$(srcdir)/WebSyncServer.cs          \
 	$(srcdir)/WebSyncServiceAddin.cs	\
+	$(srcdir)/Tests/*.cs            	\
 	$(srcdir)/Api/NoteInfo.cs       	\
 	$(srcdir)/Api/ResourceReference.cs	\
 	$(srcdir)/Api/UserInfo.cs       	\
 	$(srcdir)/Api/WebHelper.cs          \
+	$(srcdir)/Api/Tests/*.cs            \
 	$(srcdir)/Hyena.Json/*.cs           \
 	$(srcdir)/Hyena.Json/Tests/*.cs
 RESOURCES = \
diff --git a/Tomboy/Addins/WebSyncService/Tests/NoteConvertTests.cs b/Tomboy/Addins/WebSyncService/Tests/NoteConvertTests.cs
new file mode 100644
index 0000000..9222d2a
--- /dev/null
+++ b/Tomboy/Addins/WebSyncService/Tests/NoteConvertTests.cs
@@ -0,0 +1,43 @@
+// Permission is hereby granted, free of charge, to any person obtaining 
+// a copy of this software and associated documentation files (the 
+// "Software"), to deal in the Software without restriction, including 
+// without limitation the rights to use, copy, modify, merge, publish, 
+// distribute, sublicense, and/or sell copies of the Software, and to 
+// permit persons to whom the Software is furnished to do so, subject to 
+// the following conditions: 
+//  
+// The above copyright notice and this permission notice shall be 
+// included in all copies or substantial portions of the Software. 
+//  
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
+// 
+// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
+// 
+// Authors: 
+//      Sandy Armstrong <sanfordarmstrong gmail com>
+// 
+
+#if ENABLE_TESTS
+
+using System;
+
+namespace Tomboy
+{
+	
+	
+	public class NoteConvertTests
+	{
+		
+		public NoteConvertTests()
+		{
+		}
+	}
+}
+
+#endif
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]