forked from microsoft/component-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
494 additions
and
1 deletion.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/Microsoft.ComponentDetection.Detectors/swiftpm/Contracts/SwiftPMResolvedFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
test/Microsoft.ComponentDetection.Detectors.Tests/SwiftPMComponentTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
namespace Microsoft.ComponentDetection.Detectors.Tests.SwiftPM; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using FluentAssertions; | ||
using Microsoft.ComponentDetection.Contracts.TypedComponent; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using PackageUrl; | ||
|
||
[TestClass] | ||
public class SwiftPMComponentTests | ||
{ | ||
[TestMethod] | ||
public void Constructor_ShouldInitializeProperties() | ||
{ | ||
var name = "alamofire"; | ||
var version = "5.9.1"; | ||
var packageUrl = "https://github.com/Alamofire/Alamofire"; | ||
var hash = "f455c2975872ccd2d9c81594c658af65716e9b9a"; | ||
|
||
var component = new SwiftPMComponent(name, version, packageUrl, hash); | ||
|
||
component.Name.Should().Be(name); | ||
component.Version.Should().Be(version); | ||
component.Type.Should().Be(ComponentType.SwiftPM); | ||
component.Id.Should().Be($"{name} {version} - {component.Type}"); | ||
} | ||
|
||
[TestMethod] | ||
public void Constructor_ShouldThrowException_WhenNameIsNull() | ||
{ | ||
Action action = () => new SwiftPMComponent(null, "5.9.1", "https://github.com/Alamofire/Alamofire", "f455c2975872ccd2d9c81594c658af65716e9b9a"); | ||
action.Should().Throw<ArgumentException>().WithMessage("*name*"); | ||
} | ||
|
||
[TestMethod] | ||
public void Constructor_ShouldThrowException_WhenVersionIsNull() | ||
{ | ||
Action action = () => new SwiftPMComponent("alamofire", null, "https://github.com/Alamofire/Alamofire", "f455c2975872ccd2d9c81594c658af65716e9b9a"); | ||
action.Should().Throw<ArgumentException>().WithMessage("*version*"); | ||
} | ||
|
||
[TestMethod] | ||
public void Constructor_ShouldThrowException_WhenPackageUrlIsNull() | ||
{ | ||
Action action = () => new SwiftPMComponent("alamofire", "5.9.1", null, "f455c2975872ccd2d9c81594c658af65716e9b9a"); | ||
action.Should().Throw<ArgumentException>().WithMessage("*packageUrl*"); | ||
} | ||
|
||
[TestMethod] | ||
public void Constructor_ShouldThrowException_WhenHashIsNull() | ||
{ | ||
Action action = () => new SwiftPMComponent("alamofire", "5.9.1", "https://github.com/Alamofire/Alamofire", null); | ||
action.Should().Throw<ArgumentException>().WithMessage("*hash*"); | ||
} | ||
|
||
[TestMethod] | ||
public void PackageURL_ShouldReturnCorrectPackageURL() | ||
{ | ||
var name = "alamofire"; | ||
var version = "5.9.1"; | ||
var packageUrl = "https://github.com/Alamofire/Alamofire"; | ||
var hash = "f455c2975872ccd2d9c81594c658af65716e9b9a"; | ||
|
||
var component = new SwiftPMComponent(name, version, packageUrl, hash); | ||
|
||
var expectedPackageURL = new PackageURL( | ||
type: "swift", | ||
@namespace: "github.com", | ||
name: name, | ||
version: hash, | ||
qualifiers: new SortedDictionary<string, string> | ||
{ | ||
{ "repository_url", packageUrl }, | ||
}, | ||
subpath: null); | ||
|
||
component.PackageURL.Should().BeEquivalentTo(expectedPackageURL); | ||
} | ||
} |
Oops, something went wrong.