[Mantisconnect-cvs] SF.net SVN: mantisconnect: [136] mantisconnect/trunk/clients/dotnet
Brought to you by:
vboctor
From: <vb...@us...> - 2007-04-22 04:53:33
|
Revision: 136 http://svn.sourceforge.net/mantisconnect/?rev=136&view=rev Author: vboctor Date: 2007-04-21 21:53:32 -0700 (Sat, 21 Apr 2007) Log Message: ----------- - Modified the ProjectVersionAdd() in the dotnet client to return the version id + added some extra validation. - Added some test cases for the version add cases. Modified Paths: -------------- mantisconnect/trunk/clients/dotnet/UnitTests/ProjectVersions.cs mantisconnect/trunk/clients/dotnet/mantisconnect/Properties/Settings.Designer.cs mantisconnect/trunk/clients/dotnet/mantisconnect/Request.cs Modified: mantisconnect/trunk/clients/dotnet/UnitTests/ProjectVersions.cs =================================================================== --- mantisconnect/trunk/clients/dotnet/UnitTests/ProjectVersions.cs 2007-04-22 02:25:31 UTC (rev 135) +++ mantisconnect/trunk/clients/dotnet/UnitTests/ProjectVersions.cs 2007-04-22 04:53:32 UTC (rev 136) @@ -112,5 +112,118 @@ Session.Request.ProjectGetVersionsUnreleased( projectId ); } #endregion + + #region Request.ProjectGetVersions() + [Test] + public void ProjectVersionAddNotReleased() + { + ProjectVersionAddTestCase(false); + } + + [Test] + public void ProjectVersionAddReleased() + { + ProjectVersionAddTestCase(true); + } + + [Test] + [ExpectedException(typeof(ArgumentException))] + public void ProjectVersionAddWithId() + { + ProjectVersion versionToAdd = CreateVersionToAdd(); + versionToAdd.Id = 1000; + Session.Request.ProjectVersionAdd(versionToAdd); + } + + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public void ProjectVersionAddWithNullName() + { + ProjectVersion versionToAdd = CreateVersionToAdd(); + versionToAdd.Name = null; + Session.Request.ProjectVersionAdd(versionToAdd); + } + + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public void ProjectVersionAddWithNullDescription() + { + ProjectVersion versionToAdd = CreateVersionToAdd(); + versionToAdd.Description = null; + Session.Request.ProjectVersionAdd(versionToAdd); + } + #endregion + + #region Private Methods + /// <summary> + /// Get a project version by id or null if not found. + /// </summary> + /// <param name="projectVersionId">The version id</param> + /// <returns></returns> + private ProjectVersion GetProjectVersionById(int projectVersionId) + { + ProjectVersion[] versions = Session.Request.ProjectGetVersions(this.FirstProjectId); + + foreach (ProjectVersion version in versions) + { + if (version.Id == projectVersionId) + { + return version; + } + } + + return null; + } + + private void ProjectVersionAddTestCase(bool released) + { + const string VersionName = "VersionName"; + const string VersionDescription = "VersionDescription"; + DateTime now = DateTime.Now; + + ProjectVersion version = new ProjectVersion(); + version.ProjectId = this.FirstProjectId; + version.Name = VersionName; + version.Description = VersionDescription; + version.DateOrder = now; + version.IsReleased = released; + + int versionId = Session.Request.ProjectVersionAdd(version); + + try + { + // Check that the version id is set. + Assert.AreEqual(versionId, version.Id); + Assert.AreNotEqual(versionId, 0); + + ProjectVersion versionAdded = GetProjectVersionById(versionId); + + Assert.AreEqual(versionAdded.Id, versionId); + Assert.AreEqual(versionAdded.Name, VersionName); + Assert.AreEqual(versionAdded.Description, VersionDescription); + Assert.AreEqual(versionAdded.DateOrder, now); + Assert.AreEqual(versionAdded.IsReleased, released); + } + finally + { + Session.Request.ProjectVersionDelete(versionId); + } + } + + private ProjectVersion CreateVersionToAdd() + { + const string VersionName = "VersionName"; + const string VersionDescription = "VersionDescription"; + + ProjectVersion version = new ProjectVersion(); + version.ProjectId = this.FirstProjectId; + version.Name = VersionName; + version.Description = VersionDescription; + version.DateOrder = DateTime.Now; + version.IsReleased = false; + + return version; + } + #endregion } } Modified: mantisconnect/trunk/clients/dotnet/mantisconnect/Properties/Settings.Designer.cs =================================================================== --- mantisconnect/trunk/clients/dotnet/mantisconnect/Properties/Settings.Designer.cs 2007-04-22 02:25:31 UTC (rev 135) +++ mantisconnect/trunk/clients/dotnet/mantisconnect/Properties/Settings.Designer.cs 2007-04-22 04:53:32 UTC (rev 136) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. -// Runtime Version:2.0.50727.112 +// Runtime Version:2.0.50727.312 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. Modified: mantisconnect/trunk/clients/dotnet/mantisconnect/Request.cs =================================================================== --- mantisconnect/trunk/clients/dotnet/mantisconnect/Request.cs 2007-04-22 02:25:31 UTC (rev 135) +++ mantisconnect/trunk/clients/dotnet/mantisconnect/Request.cs 2007-04-22 04:53:32 UTC (rev 136) @@ -263,12 +263,31 @@ } /// <summary> - /// Adds a project version. + /// Adds a project version and sets the id on the supplied project version instance. /// </summary> /// <param name="version">The new project version details.</param> - public void ProjectVersionAdd(ProjectVersion version) + /// <returns>The version id of the added project version.</returns> + public int ProjectVersionAdd(ProjectVersion version) { - mc.mc_project_version_add(session.Username, session.Password, version.ToWebservice()); + ValidateProjectId(version.ProjectId); + + if (version.Id != 0) + { + throw new ArgumentException("Version already has a version id"); + } + + if (version.Name == null) + { + throw new ArgumentNullException("version.Name"); + } + + if (version.Description == null) + { + throw new ArgumentNullException("version.Description"); + } + + version.Id = Convert.ToInt32(mc.mc_project_version_add(session.Username, session.Password, version.ToWebservice())); + return version.Id; } /// <summary> @@ -281,6 +300,16 @@ ValidateProjectVersionId(version.Id); ValidateProjectId(version.ProjectId); + if (version.Name == null) + { + throw new ArgumentNullException("version.Name"); + } + + if (version.Description == null) + { + throw new ArgumentNullException("version.Description"); + } + mc.mc_project_version_update(session.Username, session.Password, version.Id.ToString(), version.ToWebservice()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |