summaryrefslogtreecommitdiff
path: root/spec/unit/dotnet
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-03-02 17:48:16 -0700
committermo khan <mo.khan@gmail.com>2020-03-02 17:48:16 -0700
commit689ad02603a1eacb79eaf0a93f63f6d727dadda8 (patch)
tree3f53cfb2e1b15000ae7d3bdae4226e553661c085 /spec/unit/dotnet
parentbba5d863507fa47ba7767d1cdda56e0812658736 (diff)
Extract dotnet namespace
Diffstat (limited to 'spec/unit/dotnet')
-rw-r--r--spec/unit/dotnet/index_spec.rb33
-rw-r--r--spec/unit/dotnet/nuget_gateway_spec.rb32
-rw-r--r--spec/unit/dotnet/parsers/csproj_spec.rb61
-rw-r--r--spec/unit/dotnet/parsers/packages_config_spec.rb27
-rw-r--r--spec/unit/dotnet/parsers/sln_spec.rb36
-rw-r--r--spec/unit/dotnet/project_file_spec.rb42
6 files changed, 231 insertions, 0 deletions
diff --git a/spec/unit/dotnet/index_spec.rb b/spec/unit/dotnet/index_spec.rb
new file mode 100644
index 0000000..9d1fc55
--- /dev/null
+++ b/spec/unit/dotnet/index_spec.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+RSpec.describe Spandx::Dotnet::Index do
+ subject { described_class.new(directory: directory) }
+
+ let(:directory) { Dir.mktmpdir('spandx') }
+
+ after do
+ FileUtils.rm_r(directory, force: true, secure: true)
+ end
+
+ describe '#read' do
+ let(:key) { %w[x y z] }
+ let(:data) { SecureRandom.uuid }
+
+ before do
+ subject.write(key, data)
+ end
+
+ specify { expect(subject.read(key)).to eql(data) }
+ end
+
+ describe '#indexed?' do
+ let(:key) { %w[x y z] }
+ let(:data) { SecureRandom.uuid }
+
+ before do
+ subject.write(key, data)
+ end
+
+ specify { expect(subject).to be_indexed(key) }
+ end
+end
diff --git a/spec/unit/dotnet/nuget_gateway_spec.rb b/spec/unit/dotnet/nuget_gateway_spec.rb
new file mode 100644
index 0000000..4b359d3
--- /dev/null
+++ b/spec/unit/dotnet/nuget_gateway_spec.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+RSpec.describe Spandx::Dotnet::NugetGateway do
+ subject { described_class.new(catalogue: catalogue) }
+
+ let(:catalogue) { Spandx::Catalogue.from_file(fixture_file('spdx/json/licenses.json')) }
+
+ describe '#licenses_for' do
+ context 'when the package specifies the license using an expression' do
+ specify do
+ VCR.use_cassette('jive-0.1.0') do
+ expect(subject.licenses_for('jive', '0.1.0')).to match_array(['MIT'])
+ end
+ end
+ end
+
+ pending 'when the package specifies the license using a file'
+ pending 'when the package specifies the license using a url'
+ end
+
+ describe '#update!' do
+ let(:index) { instance_double(Spandx::Dotnet::Index, write: nil) }
+
+ before do
+ VCR.use_cassette('nuget-catalogue') do
+ subject.update!(index, limit: 10)
+ end
+ end
+
+ it { expect(index).to have_received(:write).with(['api.nuget.org', 'Polaroider', '0.2.0'], 'MIT') }
+ end
+end
diff --git a/spec/unit/dotnet/parsers/csproj_spec.rb b/spec/unit/dotnet/parsers/csproj_spec.rb
new file mode 100644
index 0000000..a913ed7
--- /dev/null
+++ b/spec/unit/dotnet/parsers/csproj_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+RSpec.describe Spandx::Dotnet::Parsers::Csproj do
+ subject { described_class.new(catalogue: catalogue) }
+
+ let(:catalogue) { Spandx::Catalogue.from_file(fixture_file('spdx/json/licenses.json')) }
+
+ describe '#parse' do
+ context 'when parsing a .csproj file' do
+ let(:lockfile) { fixture_file('nuget/example.csproj') }
+
+ let(:because) do
+ VCR.use_cassette(File.basename(lockfile)) do
+ subject.parse(lockfile)
+ end
+ end
+ let(:jive) { because.find { |item| item.name == 'jive' } }
+
+ specify { expect(jive.name).to eql('jive') }
+ specify { expect(jive.version).to eql('0.1.0') }
+ specify { expect(jive.licenses.map(&:id)).to match_array(['MIT']) }
+ end
+
+ context 'when parsing a .csproj file that has a reference to another project' do
+ let(:lockfile) { fixture_file('nuget/nested/test.csproj') }
+
+ let(:because) do
+ VCR.use_cassette(File.basename(lockfile)) do
+ subject.parse(lockfile)
+ end
+ end
+
+ specify { expect(because.map(&:name)).to match_array(%w[jive xunit]) }
+ end
+
+ context 'when parsing `Nancy.Hosting.Self.csproj`' do
+ let(:lockfile) { fixture_file('nuget/Nancy.Hosting.Self.csproj') }
+
+ let(:because) do
+ VCR.use_cassette(File.basename(lockfile)) do
+ subject.parse(lockfile)
+ end
+ end
+
+ specify { expect(because.count).to be(1) }
+ specify { expect(because[0].name).to eql('System.Security.Principal.Windows') }
+ specify { expect(because[0].version).to eql('4.3.0') }
+ specify { expect(because[0].licenses).to be_empty }
+ end
+ end
+
+ describe '.matches?' do
+ subject { described_class }
+
+ specify { expect(subject.matches?('/root/simple.csproj')).to be(true) }
+ specify { expect(subject.matches?('C:\Documents and Settings\simple.csproj')).to be(true) }
+ specify { expect(subject.matches?('C:\Documents and Settings\hello world.csproj')).to be(true) }
+ specify { expect(subject.matches?('/root/Packages.props')).to be(true) }
+ specify { expect(subject.matches?('/root/simple.sln')).to be(false) }
+ end
+end
diff --git a/spec/unit/dotnet/parsers/packages_config_spec.rb b/spec/unit/dotnet/parsers/packages_config_spec.rb
new file mode 100644
index 0000000..b9763cc
--- /dev/null
+++ b/spec/unit/dotnet/parsers/packages_config_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+RSpec.describe Spandx::Dotnet::Parsers::PackagesConfig do
+ subject { described_class.new(catalogue: catalogue) }
+
+ let(:catalogue) { Spandx::Catalogue.from_file(fixture_file('spdx/json/licenses.json')) }
+
+ describe '#parse' do
+ context 'when parsing a Gemfile with a single dependency' do
+ let(:lockfile) { fixture_file('nuget/packages.config') }
+ let(:because) do
+ VCR.use_cassette(File.basename(lockfile)) do
+ subject.parse(lockfile)
+ end
+ end
+ let(:nhibernate) { because.find { |item| item.name == 'NHibernate' } }
+
+ specify { expect(nhibernate.name).to eql('NHibernate') }
+ specify { expect(nhibernate.version).to eql('5.2.6') }
+ specify { expect(nhibernate.licenses.map(&:id)).to match_array(['LGPL-2.1-only']) }
+ pending { expect(because.map(&:name)).to include('Antlr3.Runtime') }
+ pending { expect(because.map(&:name)).to include('Iesi.Collections') }
+ pending { expect(because.map(&:name)).to include('Remotion.Linq') }
+ pending { expect(because.map(&:name)).to include('Remotion.Linq.EagerFetching') }
+ end
+ end
+end
diff --git a/spec/unit/dotnet/parsers/sln_spec.rb b/spec/unit/dotnet/parsers/sln_spec.rb
new file mode 100644
index 0000000..6051dbe
--- /dev/null
+++ b/spec/unit/dotnet/parsers/sln_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+RSpec.describe Spandx::Dotnet::Parsers::Sln do
+ subject { described_class.new(catalogue: catalogue) }
+
+ let(:catalogue) { Spandx::Catalogue.from_file(fixture_file('spdx/json/licenses.json')) }
+
+ describe '#parse' do
+ context 'when parsing a sln file without any project references' do
+ let(:sln) { fixture_file('nuget/empty.sln') }
+
+ it 'returns an empty list of dependencies' do
+ expect(subject.parse(sln)).to be_empty
+ end
+ end
+
+ context 'when parsing a sln file with a single project reference' do
+ let(:sln) { fixture_file('nuget/single.sln') }
+
+ let(:because) do
+ VCR.use_cassette(File.basename(sln)) do
+ subject.parse(sln)
+ end
+ end
+
+ specify { expect(because.map(&:name)).to match_array(%w[jive xunit]) }
+ end
+ end
+
+ describe '.matches?' do
+ subject { described_class }
+
+ specify { expect(subject.matches?('/root/example.sln')).to be(true) }
+ specify { expect(subject.matches?('C:\development\hello world.sln')).to be(true) }
+ end
+end
diff --git a/spec/unit/dotnet/project_file_spec.rb b/spec/unit/dotnet/project_file_spec.rb
new file mode 100644
index 0000000..3d26aea
--- /dev/null
+++ b/spec/unit/dotnet/project_file_spec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+RSpec.describe Spandx::Dotnet::ProjectFile do
+ subject { described_class.new(path) }
+
+ describe '#package_references' do
+ context 'when parsing a `simple.csproj`' do
+ let(:path) { fixture_file('nuget/example.csproj') }
+
+ specify { expect(subject.package_references.count).to be(1) }
+ specify { expect(subject.package_references[0].name).to eql('jive') }
+ specify { expect(subject.package_references[0].version).to eql('0.1.0') }
+ end
+
+ context 'when parsing a `Packages.props`' do
+ let(:path) { fixture_file('nuget/Packages.props') }
+
+ specify { expect(subject.package_references.count).to eq(16) }
+
+ specify do
+ expect(subject.package_references.map(&:to_h)).to match_array([
+ { name: 'MSBuild.ProjectCreation', version: '1.3.1' },
+ { name: 'McMaster.Extensions.CommandLineUtils', version: '2.5.0' },
+ { name: 'Microsoft.Build', version: '16.4.0' },
+ { name: 'Microsoft.Build.Artifacts', version: '2.0.1' },
+ { name: 'Microsoft.Build.Locator', version: '1.2.6' },
+ { name: 'Microsoft.Build.Runtime', version: '16.4.0' },
+ { name: 'Microsoft.Build.Utilities.Core', version: '16.4.0' },
+ { name: 'Microsoft.NET.Test.Sdk', version: '16.4.0' },
+ { name: 'Microsoft.NETFramework.ReferenceAssemblies', version: '1.0.0' },
+ { name: 'Microsoft.VisualStudio.Telemetry', version: '16.3.2' },
+ { name: 'Nerdbank.GitVersioning', version: '3.0.28' },
+ { name: 'Shouldly', version: '3.0.2' },
+ { name: 'SlnGen', version: '2.2.30' },
+ { name: 'StyleCop.Analyzers', version: '1.1.118' },
+ { name: 'xunit', version: '2.4.1' },
+ { name: 'xunit.runner.visualstudio', version: '2.4.1' },
+ ])
+ end
+ end
+ end
+end