diff --git a/Nodejs/Product/Npm/IBugs.cs b/Nodejs/Product/Npm/IBugs.cs deleted file mode 100644 index be80b3586..000000000 --- a/Nodejs/Product/Npm/IBugs.cs +++ /dev/null @@ -1,22 +0,0 @@ -//*********************************************************// -// Copyright (c) Microsoft. All rights reserved. -// -// Apache 2.0 License -// -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. -// -//*********************************************************// - -namespace Microsoft.NodejsTools.Npm { - public interface IBugs { - string Url { get; } - string Email { get; } - } -} \ No newline at end of file diff --git a/Nodejs/Product/Npm/IPackageJson.cs b/Nodejs/Product/Npm/IPackageJson.cs index 1adddeabb..e28c00b20 100644 --- a/Nodejs/Product/Npm/IPackageJson.cs +++ b/Nodejs/Product/Npm/IPackageJson.cs @@ -20,13 +20,10 @@ namespace Microsoft.NodejsTools.Npm { public interface IPackageJson { string Name { get; } SemverVersion Version { get; } - IScripts Scripts { get; } IPerson Author { get; } string Description { get; } IKeywords Keywords { get; } IHomepages Homepages { get; } - IBugs Bugs { get; } - ILicenses Licenses { get; } IFiles Files { get; } IMan Man { get; } IDependencies Dependencies { get; } diff --git a/Nodejs/Product/Npm/IScript.cs b/Nodejs/Product/Npm/IScript.cs deleted file mode 100644 index 4a7ca8814..000000000 --- a/Nodejs/Product/Npm/IScript.cs +++ /dev/null @@ -1,22 +0,0 @@ -//*********************************************************// -// Copyright (c) Microsoft. All rights reserved. -// -// Apache 2.0 License -// -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. -// -//*********************************************************// - -namespace Microsoft.NodejsTools.Npm { - public interface IScript { - string Name { get; } - string Code { get; } - } -} \ No newline at end of file diff --git a/Nodejs/Product/Npm/IScripts.cs b/Nodejs/Product/Npm/IScripts.cs deleted file mode 100644 index 6b24bf73e..000000000 --- a/Nodejs/Product/Npm/IScripts.cs +++ /dev/null @@ -1,22 +0,0 @@ -//*********************************************************// -// Copyright (c) Microsoft. All rights reserved. -// -// Apache 2.0 License -// -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. -// -//*********************************************************// - -namespace Microsoft.NodejsTools.Npm { - public interface IScripts { - int Count { get; } - IScript this[string name] { get; } - } -} \ No newline at end of file diff --git a/Nodejs/Product/Npm/Npm.csproj b/Nodejs/Product/Npm/Npm.csproj index 95fb24a20..9dcdb7ba1 100644 --- a/Nodejs/Product/Npm/Npm.csproj +++ b/Nodejs/Product/Npm/Npm.csproj @@ -1,4 +1,4 @@ - + @@ -114,7 +114,6 @@ - @@ -137,8 +136,6 @@ - - Nodejs.cs @@ -173,15 +170,12 @@ - - - @@ -200,8 +194,6 @@ - - diff --git a/Nodejs/Product/Npm/SPI/Bugs.cs b/Nodejs/Product/Npm/SPI/Bugs.cs deleted file mode 100644 index 29f86d84c..000000000 --- a/Nodejs/Product/Npm/SPI/Bugs.cs +++ /dev/null @@ -1,64 +0,0 @@ -//*********************************************************// -// Copyright (c) Microsoft. All rights reserved. -// -// Apache 2.0 License -// -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. -// -//*********************************************************// - -using Newtonsoft.Json.Linq; - -namespace Microsoft.NodejsTools.Npm.SPI { - internal class Bugs : IBugs { - private readonly dynamic _package; - - public Bugs(dynamic package) { - _package = package; - } - - - public string Url { - get { - string url = null; - var bugs = _package.bugs; - if (null != bugs) { - var token = bugs as JToken; - if (token.Type == JTokenType.Object) { - var temp = bugs.url ?? bugs.web; - if (null != temp) { - url = temp.ToString(); - } - } else { - url = token.Value(); - } - } - return url; - } - } - - public string Email { - get { - string email = null; - var bugs = _package.bugs; - if (null != bugs) { - var token = bugs as JToken; - if (token.Type == JTokenType.Object) { - var temp = bugs.email ?? bugs.mail; - if (null != temp) { - email = temp.ToString(); - } - } - } - return email; - } - } - } -} \ No newline at end of file diff --git a/Nodejs/Product/Npm/SPI/Dependencies.cs b/Nodejs/Product/Npm/SPI/Dependencies.cs index b3bf42a6b..9ac67c644 100644 --- a/Nodejs/Product/Npm/SPI/Dependencies.cs +++ b/Nodejs/Product/Npm/SPI/Dependencies.cs @@ -21,31 +21,24 @@ namespace Microsoft.NodejsTools.Npm.SPI { internal class Dependencies : IDependencies { - private JObject _package; - private string[] _dependencyPropertyNames; + private IList _dependencyProperties; public Dependencies(JObject package, params string[] dependencyPropertyNames) { - _package = package; - _dependencyPropertyNames = dependencyPropertyNames; - } - - private IEnumerable GetDependenciesProperties() { - foreach (var propertyName in _dependencyPropertyNames) { - var property = _package[propertyName] as JObject; - if (null != property) { - yield return property; + _dependencyProperties = new List(); + foreach (var propertyName in dependencyPropertyNames) { + var dependencies = package[propertyName] as JObject; + if (dependencies != null) { + foreach (var property in dependencies.Properties()) { + if (property.Value.Type == JTokenType.String) { + _dependencyProperties.Add(new Dependency(property.Name, property.Value.Value())); + } + } } } } public IEnumerator GetEnumerator() { - var dependencyProps = GetDependenciesProperties(); - foreach (var dependencies in dependencyProps) { - var properties = null == dependencies ? new List() : dependencies.Properties(); - foreach (var property in properties) { - yield return new Dependency(property.Name, property.Value.Value()); - } - } + return _dependencyProperties.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { @@ -58,10 +51,9 @@ public int Count { public IDependency this[string name] { get { - foreach (var dependencies in GetDependenciesProperties()) { - var property = dependencies[name]; - if (null != property) { - return new Dependency(name, property.Value()); + foreach (var dependeny in _dependencyProperties) { + if (dependeny.Name == name) { + return dependeny; } } return null; diff --git a/Nodejs/Product/Npm/SPI/License.cs b/Nodejs/Product/Npm/SPI/License.cs deleted file mode 100644 index 71423f8dc..000000000 --- a/Nodejs/Product/Npm/SPI/License.cs +++ /dev/null @@ -1,31 +0,0 @@ -//*********************************************************// -// Copyright (c) Microsoft. All rights reserved. -// -// Apache 2.0 License -// -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. -// -//*********************************************************// - -namespace Microsoft.NodejsTools.Npm.SPI { - internal class License : ILicense { - public License(string type) { - Type = type; - } - - public License(string type, string url) - : this(type) { - Url = url; - } - - public string Type { get; private set; } - public string Url { get; private set; } - } -} \ No newline at end of file diff --git a/Nodejs/Product/Npm/SPI/Licenses.cs b/Nodejs/Product/Npm/SPI/Licenses.cs deleted file mode 100644 index 59197b57d..000000000 --- a/Nodejs/Product/Npm/SPI/Licenses.cs +++ /dev/null @@ -1,64 +0,0 @@ -//*********************************************************// -// Copyright (c) Microsoft. All rights reserved. -// -// Apache 2.0 License -// -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. -// -//*********************************************************// - -using System; -using Newtonsoft.Json.Linq; - -namespace Microsoft.NodejsTools.Npm.SPI { - internal class Licenses : ILicenses { - private dynamic _package; - - public Licenses(dynamic package) { - _package = package; - } - - public int Count { - get { - if (_package.license != null) { - return 1; - } - - var json = _package.licenses; - if (null == json) { - return 0; - } - - JArray array = json; - return array.Count; - } - } - - public ILicense this[int index] { - get { - if (index < 0) { - throw new IndexOutOfRangeException(Resources.CannotRetrieveLicenseInvalidIndex); - } - - if (index == 0 && _package.license != null) { - return new License(_package.license.ToString()); - } - - var json = _package.licenses; - if (null == json) { - throw new IndexOutOfRangeException(Resources.CannotRetrieveLicenseEmptyCollection); - } - - var lic = json[index]; - return new License(lic.type.ToString(), lic.url.ToString()); - } - } - } -} \ No newline at end of file diff --git a/Nodejs/Product/Npm/SPI/PackageJson.cs b/Nodejs/Product/Npm/SPI/PackageJson.cs index 10f6f8082..4f78243be 100644 --- a/Nodejs/Product/Npm/SPI/PackageJson.cs +++ b/Nodejs/Product/Npm/SPI/PackageJson.cs @@ -21,31 +21,29 @@ namespace Microsoft.NodejsTools.Npm.SPI { internal class PackageJson : IPackageJson { - private dynamic _package; - private Scripts _scripts; - private Bugs _bugs; + private string _versionString; public PackageJson(dynamic package) { - _package = package; - - InitKeywords(); - InitHomepages(); - InitLicenses(); - InitFiles(); - InitMan(); - InitDependencies(); - InitDevDependencies(); - InitBundledDependencies(); - InitOptionalDependencies(); - InitAllDependencies(); - InitRequiredBy(); - } - - private void WrapRuntimeBinderExceptionAndRethrow( - string errorProperty, - RuntimeBinderException rbe) { - throw new PackageJsonException( - string.Format(@"Exception occurred retrieving {0} from package.json. The file may be invalid: you should edit it to correct an errors. + Keywords = LoadKeywords(package); + Homepages = LoadHomepages(package); + Files = LoadFiles(package); + Man = LoadMan(package); + Dependencies = LoadDependencies(package); + DevDependencies = LoadDevDependencies(package); + BundledDependencies = LoadBundledDependencies(package); + OptionalDependencies = LoadOptionalDependencies(package); + AllDependencies = LoadAllDependencies(package); + RequiredBy = LoadRequiredBy(package); + + Name = package.name == null ? null : package.name.ToString(); + _versionString = package.version; + Description = package.description == null ? null : package.description.ToString(); + Author = package.author == null ? null : Person.CreateFromJsonSource(package.author.ToString()); + } + + private static PackageJsonException WrapRuntimeBinderException(string errorProperty, RuntimeBinderException rbe) { + return new PackageJsonException( + string.Format(@"Exception occurred retrieving {0} from package.json. The file may be invalid: you should edit it to correct an errors. The following error occurred: @@ -54,167 +52,104 @@ private void WrapRuntimeBinderExceptionAndRethrow( rbe)); } - private void InitKeywords() { + private static IKeywords LoadKeywords(dynamic package) { try { - Keywords = new Keywords(_package); + return new Keywords(package); } catch (RuntimeBinderException rbe) { - WrapRuntimeBinderExceptionAndRethrow( - "keywords", - rbe); + throw WrapRuntimeBinderException("keywords", rbe); } } - private void InitHomepages() { + private static IHomepages LoadHomepages(dynamic package) { try { - Homepages = new Homepages(_package); + return new Homepages(package); } catch (RuntimeBinderException rbe) { - WrapRuntimeBinderExceptionAndRethrow( - "homepage", - rbe); - } - } - - private void InitFiles() { - try { - Files = new PkgFiles(_package); - } catch (RuntimeBinderException rbe) { - WrapRuntimeBinderExceptionAndRethrow( - "files", - rbe); + throw WrapRuntimeBinderException("homepage", rbe); } } - private void InitLicenses() { + private static IFiles LoadFiles(dynamic package) { try { - Licenses = new Licenses(_package); + return new PkgFiles(package); } catch (RuntimeBinderException rbe) { - WrapRuntimeBinderExceptionAndRethrow( - "licenses", - rbe); + throw WrapRuntimeBinderException("files", rbe); } } - private void InitMan() { + private static IMan LoadMan(dynamic package) { try { - Man = new Man(_package); + return new Man(package); } catch (RuntimeBinderException rbe) { - WrapRuntimeBinderExceptionAndRethrow( - "man", - rbe); + throw WrapRuntimeBinderException("man", rbe); } } - private void InitDependencies() { + private static IDependencies LoadDependencies(dynamic package) { try { - Dependencies = new Dependencies(_package, "dependencies"); + return new Dependencies(package, "dependencies"); } catch (RuntimeBinderException rbe) { - WrapRuntimeBinderExceptionAndRethrow( - "dependencies", - rbe); + throw WrapRuntimeBinderException("dependencies", rbe); } } - private void InitDevDependencies() { + private static IDependencies LoadDevDependencies(dynamic package) { try { - DevDependencies = new Dependencies(_package, "devDependencies"); + return new Dependencies(package, "devDependencies"); } catch (RuntimeBinderException rbe) { - WrapRuntimeBinderExceptionAndRethrow( - "dev dependencies", - rbe); + throw WrapRuntimeBinderException("dev dependencies", rbe); } } - private void InitBundledDependencies() { + private static IBundledDependencies LoadBundledDependencies(dynamic package) { try { - BundledDependencies = new BundledDependencies(_package); + return new BundledDependencies(package); } catch (RuntimeBinderException rbe) { - WrapRuntimeBinderExceptionAndRethrow( - "bundled dependencies", - rbe); + throw WrapRuntimeBinderException("bundled dependencies", rbe); } } - private void InitOptionalDependencies() { + private static IDependencies LoadOptionalDependencies(dynamic package) { try { - OptionalDependencies = new Dependencies(_package, "optionalDependencies"); + return new Dependencies(package, "optionalDependencies"); } catch (RuntimeBinderException rbe) { - WrapRuntimeBinderExceptionAndRethrow( - "optional dependencies", - rbe); + throw WrapRuntimeBinderException("optional dependencies", rbe); } } - private void InitAllDependencies() { + private static IDependencies LoadAllDependencies(dynamic package) { try { - AllDependencies = new Dependencies(_package, "dependencies", "devDependencies", "optionalDependencies"); + return new Dependencies(package, "dependencies", "devDependencies", "optionalDependencies"); } catch (RuntimeBinderException rbe) { - WrapRuntimeBinderExceptionAndRethrow( - "all dependencies", - rbe); + throw WrapRuntimeBinderException("all dependencies", rbe); } } - private void InitRequiredBy() { + private static IEnumerable LoadRequiredBy(dynamic package) { try { - RequiredBy = (_package["_requiredBy"] as IEnumerable ?? Enumerable.Empty()).Values(); + return (package["_requiredBy"] as IEnumerable ?? Enumerable.Empty()).Values().ToList(); } catch (RuntimeBinderException rbe) { System.Diagnostics.Debug.WriteLine(rbe); - WrapRuntimeBinderExceptionAndRethrow( - "required by", - rbe); + throw WrapRuntimeBinderException("required by", rbe); } } - public string Name { - get { return null == _package.name ? null : _package.name.ToString(); } - } + public string Name { get; private set; } public SemverVersion Version { get { - return null == _package.version ? new SemverVersion() : SemverVersion.Parse(_package.version.ToString()); - } - } - - public IScripts Scripts { - get { - if (null == _scripts) { - dynamic scriptsJson = _package.scripts; - if (null == scriptsJson) { - scriptsJson = new JObject(); - _package.scripts = scriptsJson; - } - _scripts = new Scripts(scriptsJson); - } - - return _scripts; + return _versionString == null ? new SemverVersion() : SemverVersion.Parse(_versionString); } } - public IPerson Author { - get { - var author = _package.author; - return null == author ? null : Person.CreateFromJsonSource(author.ToString()); - } - } + public IPerson Author { get; private set; } - public string Description { - get { return null == _package.description ? null : _package.description.ToString(); } - } + public string Description { get; private set; } public IKeywords Keywords { get; private set; } public IHomepages Homepages { get; private set; } - public IBugs Bugs { - get { - if (null == _bugs && null != _package.bugs) { - _bugs = new Bugs(_package); - } - return _bugs; - } - } - public ILicenses Licenses { get; private set; } public IFiles Files { get; private set; } diff --git a/Nodejs/Product/Npm/SPI/PkgStringArray.cs b/Nodejs/Product/Npm/SPI/PkgStringArray.cs index 0eef8c0a7..4fca546c7 100644 --- a/Nodejs/Product/Npm/SPI/PkgStringArray.cs +++ b/Nodejs/Product/Npm/SPI/PkgStringArray.cs @@ -22,17 +22,33 @@ namespace Microsoft.NodejsTools.Npm.SPI { internal abstract class PkgStringArray : IPkgStringArray { - private readonly JObject _package; - private readonly string[] arrayPropertyNames; + private IList elements; protected PkgStringArray(JObject package, params string[] arrayPropertyNames) { - _package = package; - this.arrayPropertyNames = arrayPropertyNames; + + var token = GetArrayProperty(package, arrayPropertyNames); + if (token == null) { + elements = new List(); + } else { + switch (token.Type) { + case JTokenType.String: + elements = new[] { token.Value() }; + break; + + case JTokenType.Array: + elements = (token as JArray).Select(value => value.Value()).ToList(); + break; + + default: + elements = new List(); + break; + } + } } - private JToken GetArrayProperty() { + private static JToken GetArrayProperty(JObject package, string[] arrayPropertyNames) { foreach (var name in arrayPropertyNames) { - var array = _package[name] as JToken; + var array = package[name] as JToken; if (null != array) { return array; } @@ -42,21 +58,7 @@ private JToken GetArrayProperty() { public int Count { get { - var token = GetArrayProperty(); - if (null == token) { - return 0; - } - - switch (token.Type) { - case JTokenType.String: - return 1; - - case JTokenType.Array: - return (token as JArray).Count; - - default: - return 0; - } + return elements.Count; } } @@ -67,37 +69,18 @@ public string this[int index] { "Cannot retrieve item from empty package.json string array."); } - var token = GetArrayProperty(); - switch (token.Type) { - case JTokenType.String: - if (index != 0) { - throw new IndexOutOfRangeException( - string.Format( - "Cannot retrieve value from index '{0}' in a package.json string array containing only 1 item.", - index)); - } - return token.Value(); - - default: // Can only be an array at this point, since Count has been called. - return (token as JArray)[index].Value(); + if (index > Count) { + throw new IndexOutOfRangeException( + string.Format( + "Cannot retrieve value from index '{0}' in a package.json string array containing only 1 item.", + index)); } + return elements[index]; } } public IEnumerator GetEnumerator() { - switch (Count) { - case 0: - return new List().GetEnumerator(); - - case 1: - return new List { this[0] }.GetEnumerator(); - - default: - return - (GetArrayProperty() as JArray).Select(value => value.Value()) - .ToList() - .GetEnumerator(); - } + return elements.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { diff --git a/Nodejs/Product/Npm/SPI/Script.cs b/Nodejs/Product/Npm/SPI/Script.cs deleted file mode 100644 index c16234d87..000000000 --- a/Nodejs/Product/Npm/SPI/Script.cs +++ /dev/null @@ -1,32 +0,0 @@ -//*********************************************************// -// Copyright (c) Microsoft. All rights reserved. -// -// Apache 2.0 License -// -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. -// -//*********************************************************// - -namespace Microsoft.NodejsTools.Npm.SPI { - internal class Script : IScript { - private dynamic _code; - - public Script(string name, dynamic code) { - Name = name; - _code = code; - } - - public string Name { get; private set; } - - public string Code { - get { return _code.ToString(); } - } - } -} \ No newline at end of file diff --git a/Nodejs/Product/Npm/SPI/Scripts.cs b/Nodejs/Product/Npm/SPI/Scripts.cs deleted file mode 100644 index e43dbf8f9..000000000 --- a/Nodejs/Product/Npm/SPI/Scripts.cs +++ /dev/null @@ -1,45 +0,0 @@ -//*********************************************************// -// Copyright (c) Microsoft. All rights reserved. -// -// Apache 2.0 License -// -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. -// -//*********************************************************// - -using Newtonsoft.Json.Linq; - -namespace Microsoft.NodejsTools.Npm.SPI { - internal class Scripts : IScripts { - private dynamic _scripts; - - public Scripts(dynamic scripts) { - _scripts = scripts; - } - - public int Count { - get { - JObject temp = _scripts; - return null == temp ? 0 : temp.Count; - } - } - - public IScript this[string name] { - get { - IScript script = null; - dynamic json = _scripts[name]; - if (null != json) { - script = new Script(name, json); - } - return script; - } - } - } -} \ No newline at end of file diff --git a/Nodejs/Tests/NpmTests/PackageJsonTests.cs b/Nodejs/Tests/NpmTests/PackageJsonTests.cs index 3c30dfb78..c57c3f3f1 100644 --- a/Nodejs/Tests/NpmTests/PackageJsonTests.cs +++ b/Nodejs/Tests/NpmTests/PackageJsonTests.cs @@ -217,43 +217,6 @@ public void TestReadNameAndVersion() { SemverVersionTestHelper.AssertVersionsEqual(0, 1, 0, null, null, pkgJson.Version); } - [TestMethod, Priority(0)] - public void TestGetEmptyScripts() { - var pkg = LoadFrom(PkgSimple); - var scripts = pkg.Scripts; - Assert.IsNotNull(scripts, "Scripts collection should not be null."); - Assert.AreEqual(0, scripts.Count, "Shouldn't find any scripts."); - } - - [TestMethod, Priority(0)] - public void TestReadSingleStartScript() { - var pkg = LoadFrom(PkgStartScript); - var scripts = pkg.Scripts; - Assert.AreEqual(1, scripts.Count, "Should be a single script."); - IScript start = scripts[ScriptName.Start]; - Assert.IsNotNull(start, "Start script should not be null."); - Assert.AreEqual(ScriptName.Start, start.Name, "Script name mismatch."); - Assert.AreEqual("node server.js", start.Code, "Script code mismatch."); - } - - [TestMethod, Priority(0)] - public void TestReadNonExistentScriptsNull() { - var pkg = LoadFrom(PkgStartScript); - var scripts = pkg.Scripts; - - foreach (var name in new[]{ - ScriptName.Install, - ScriptName.Postinstall, - ScriptName.Postpublish, - ScriptName.Postrestart, - ScriptName.Poststart, - ScriptName.Poststop, - ScriptName.Posttest - }) { - Assert.IsNull(scripts[name], string.Format("Script '{0}' should be null.", name)); - } - } - [TestMethod, Priority(0)] public void TestReadNoDescriptionNull() { var pkg = LoadFrom(PkgEmpty); @@ -306,68 +269,6 @@ public void TestReadHomepageNonCompliant() { new[] { "http://www.mypackagehomepage.com/" }); } - [TestMethod, Priority(0)] - public void TestReadNoBugsNull() { - var pkg = LoadFrom(PkgSimple); - Assert.IsNull(pkg.Bugs, "Bugs should be null."); - } - - [TestMethod, Priority(0)] - public void TestReadBugsUrlOnly() { - var pkg = LoadFrom(PkgSimpleBugs); - var bugs = pkg.Bugs; - Assert.IsNotNull(bugs, "Bugs should not be null."); - Assert.AreEqual("http://www.mybugtracker.com/", bugs.Url, "Bugs URL mismatch."); - Assert.IsNull(bugs.Email, "Bugs email should be null."); - } - - private void TestReadBugsUrlAndEmail(string json) { - var pkg = LoadFrom(json); - var bugs = pkg.Bugs; - Assert.IsNotNull(bugs, "Bugs should not be null."); - Assert.AreEqual("http://www.example.com/bugs", bugs.Url, "Bugs URL mismatch."); - Assert.AreEqual("dev@example.com", bugs.Email, "Bugs email mismatch."); - } - - [TestMethod, Priority(0)] - public void TestReadBugsUrlAndEmailCompliant() { - TestReadBugsUrlAndEmail(PkgLargeCompliant); - } - - [TestMethod, Priority(0)] - public void TestReadBugsUrlAndEmailNonCompliant() { - TestReadBugsUrlAndEmail(PkgLargeNonCompliant); - } - - [TestMethod, Priority(0)] - public void TestReadNoLicensesEmpty() { - var pkg = LoadFrom(PkgSimpleBugs); - var licenses = pkg.Licenses; - Assert.IsNotNull(licenses, "Licenses should not be null."); - Assert.AreEqual(0, licenses.Count, "Should not be any licenses."); - } - - [TestMethod, Priority(0)] - public void TestReadLicensesTypeOnly() { - var pkg = LoadFrom(PkgSingleLicenseType); - var licenses = pkg.Licenses; - Assert.AreEqual(1, licenses.Count, "License count mismatch."); - var license = licenses[0]; - Assert.IsNotNull(license, "License should not be null."); - Assert.AreEqual("BSD", license.Type, "License type mismatch."); - } - - [TestMethod, Priority(0)] - public void ReadLicensesTypeAndUrl() { - var pkg = LoadFrom(PkgLargeCompliant); - var licenses = pkg.Licenses; - Assert.AreEqual(1, licenses.Count, "License count mismatch."); - var license = licenses[0]; - Assert.IsNotNull(license, "License should not be null."); - Assert.AreEqual("GPLv2", license.Type, "License type mismatch."); - Assert.AreEqual("http://www.example.org/licenses/gpl.html", license.Url, "License URL mismatch."); - } - [TestMethod, Priority(0)] public void TestReadEmptyFilesEmpty() { CheckEmptyArray(LoadFrom(PkgSimple).Files);