-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#27] Added regex filters
- Loading branch information
Showing
34 changed files
with
791 additions
and
315 deletions.
There are no files selected for viewing
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,12 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"dotnet-stryker": { | ||
"version": "0.22.3", | ||
"commands": [ | ||
"dotnet-stryker" | ||
] | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<CodeAnalysisRuleSet>StyleCop.ruleset</CodeAnalysisRuleSet> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<CollectCoverage>true</CollectCoverage> | ||
<CoverletOutputFormat>lcov</CoverletOutputFormat> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.msbuild" Version="3.1.2" /> | ||
<PackageReference Include="fluentassertions" Version="6.6.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="Moq" Version="4.17.2" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" /> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<AdditionalFiles Include="stylecop.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Backend\Backend.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,42 @@ | ||
using System.Threading.Tasks; | ||
using GitMonitor.Configurations; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GitMonitor.Services | ||
{ | ||
[TestClass] | ||
public class BasicUserValidationServiceTest | ||
{ | ||
[TestMethod] | ||
public async Task IsValidAsync_Anonymous() | ||
{ | ||
var options = new ApplicationOptions | ||
{ | ||
Username = null, | ||
Password = null, | ||
}; | ||
|
||
var service = new BasicUserValidationService(Options.Create(options)); | ||
|
||
Assert.IsTrue(await service.IsValidAsync("username", "password")); | ||
} | ||
|
||
[TestMethod] | ||
public async Task IsValidAsync_Credentials() | ||
{ | ||
var options = new ApplicationOptions | ||
{ | ||
Username = "username", | ||
Password = "password", | ||
}; | ||
|
||
var service = new BasicUserValidationService(Options.Create(options)); | ||
|
||
Assert.IsTrue(await service.IsValidAsync("username", "password")); | ||
Assert.IsFalse(await service.IsValidAsync("wrong_username", "password")); | ||
Assert.IsFalse(await service.IsValidAsync("username", "wrong_password")); | ||
Assert.IsFalse(await service.IsValidAsync("wrong_username", "wrong_password")); | ||
} | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
Backend.Tests/Services/ChangesTrackers/BranchesTrackerTest.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,109 @@ | ||
using System.Collections.Generic; | ||
using FluentAssertions; | ||
using GitMonitor.Objects.Changes; | ||
using LibGit2Sharp; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
|
||
namespace GitMonitor.Services.ChangesTrackers | ||
{ | ||
[TestClass] | ||
public class BranchesTrackerTest | ||
{ | ||
public BranchesTrackerTest() | ||
{ | ||
Branches = new List<Branch>(); | ||
|
||
var branchCollection = new Mock<BranchCollection>(); | ||
|
||
branchCollection.Setup(b => b.GetEnumerator()).Returns(() => Branches.GetEnumerator()); | ||
|
||
Repository = Mock.Of<IRepository>(r => r.Branches == branchCollection.Object); | ||
|
||
Changes = new List<Change>(); | ||
} | ||
|
||
private List<Branch> Branches { get; } | ||
|
||
private IRepository Repository { get; } | ||
|
||
private List<Change> Changes { get; } | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
Branches.Clear(); | ||
Changes.Clear(); | ||
} | ||
|
||
[TestMethod] | ||
public void AddedBranch() | ||
{ | ||
Branches.Add(MockBranch("original", "1")); | ||
|
||
using (var tracker = new BranchesTracker(Repository, Changes)) | ||
{ | ||
Branches.Clear(); | ||
Branches.Add(MockBranch("original", "1")); | ||
Branches.Add(MockBranch("new", "1")); | ||
} | ||
|
||
Changes.Should().HaveCount(1) | ||
.And.SatisfyRespectively(c => | ||
{ | ||
c.ObjectType.Should().Be(ChangeObjectType.Branch); | ||
c.Type.Should().Be(ChangeType.Created); | ||
c.ObjectName.Should().Be("new"); | ||
c.Should().BeOfType<BranchChange>() | ||
.Which.TargetCommit.Should().Be("1"); | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public void RemovedBranch() | ||
{ | ||
Branches.Add(MockBranch("original", "1")); | ||
|
||
using (var tracker = new BranchesTracker(Repository, Changes)) | ||
{ | ||
Branches.Clear(); | ||
} | ||
|
||
Assert.AreEqual(1, Changes.Count); | ||
Assert.AreEqual(ChangeObjectType.Branch, Changes[0].ObjectType); | ||
Assert.AreEqual(ChangeType.Deleted, Changes[0].Type); | ||
Assert.AreEqual("original", Changes[0].ObjectName); | ||
Assert.IsInstanceOfType(Changes[0], typeof(BranchChange)); | ||
Assert.AreEqual("1", ((BranchChange)Changes[0]).TargetCommit); | ||
} | ||
|
||
[TestMethod] | ||
public void UpdatedBranch() | ||
{ | ||
Branches.Add(MockBranch("original", "1")); | ||
|
||
using (var tracker = new BranchesTracker(Repository, Changes)) | ||
{ | ||
Branches.Clear(); | ||
Branches.Add(MockBranch("original", "2")); | ||
} | ||
|
||
Assert.AreEqual(1, Changes.Count); | ||
Assert.AreEqual(ChangeObjectType.Branch, Changes[0].ObjectType); | ||
Assert.AreEqual(ChangeType.Updated, Changes[0].Type); | ||
Assert.AreEqual("original", Changes[0].ObjectName); | ||
Assert.IsInstanceOfType(Changes[0], typeof(BranchChange)); | ||
Assert.AreEqual("2", ((BranchChange)Changes[0]).TargetCommit); | ||
} | ||
|
||
private Branch MockBranch(string name, string sha) | ||
{ | ||
return Mock.Of<Branch>(b => | ||
b.IsRemote == true && | ||
b.RemoteName == "origin" && | ||
b.CanonicalName == name && | ||
b.FriendlyName == "origin/" + name && | ||
b.Tip == Mock.Of<Commit>(c => c.Sha == sha)); | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
Backend.Tests/Services/ChangesTrackers/CommitsTrackerTest.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,95 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using GitMonitor.Objects.Changes; | ||
using LibGit2Sharp; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
|
||
namespace GitMonitor.Services.ChangesTrackers | ||
{ | ||
[TestClass] | ||
public class CommitsTrackerTest | ||
{ | ||
public CommitsTrackerTest() | ||
{ | ||
Commits = new List<Commit>(); | ||
|
||
var commitCollection = new Mock<IQueryableCommitLog>(); | ||
|
||
commitCollection.Setup(c => c.GetEnumerator()).Returns(() => Commits.GetEnumerator()); | ||
commitCollection.Setup(c => c.QueryBy(It.IsAny<CommitFilter>())).Returns(() => commitCollection.Object); | ||
|
||
Repository = Mock.Of<IRepository>(r => | ||
r.Commits == commitCollection.Object && | ||
r.Refs == new Mock<ReferenceCollection>().Object); | ||
|
||
Changes = new List<Change>(); | ||
} | ||
|
||
private List<Commit> Commits { get; } | ||
|
||
private IRepository Repository { get; } | ||
|
||
private List<Change> Changes { get; } | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
Commits.Clear(); | ||
Changes.Clear(); | ||
} | ||
|
||
[TestMethod] | ||
public void AddedCommit() | ||
{ | ||
Commits.Add(MockCommit("Message1", "1", "U", "E")); | ||
|
||
using (var tracker = new CommitsTracker(Repository, Changes)) | ||
{ | ||
Commits.Clear(); | ||
Commits.Add(MockCommit("Message1", "1", "U", "E")); | ||
Commits.Add(MockCommit("Message2", "2", "User", "test@example.com")); | ||
} | ||
|
||
Assert.AreEqual(1, Changes.Count); | ||
Assert.AreEqual(ChangeObjectType.Commit, Changes[0].ObjectType); | ||
Assert.AreEqual(ChangeType.Created, Changes[0].Type); | ||
Assert.AreEqual("Message2", Changes[0].ObjectName); | ||
Assert.IsInstanceOfType(Changes[0], typeof(CommitChange)); | ||
Assert.AreEqual("2", ((CommitChange)Changes[0]).Hash); | ||
Assert.AreEqual("Message2", ((CommitChange)Changes[0]).Message); | ||
Assert.AreEqual("User", ((CommitChange)Changes[0]).User?.Name); | ||
Assert.AreEqual("test@example.com", ((CommitChange)Changes[0]).User?.Email); | ||
} | ||
|
||
[TestMethod] | ||
public void RemovedCommit() | ||
{ | ||
Commits.Add(MockCommit("Message1", "1", "User", "test@example.com")); | ||
|
||
using (var tracker = new CommitsTracker(Repository, Changes)) | ||
{ | ||
Commits.Clear(); | ||
} | ||
|
||
Assert.AreEqual(1, Changes.Count); | ||
Assert.AreEqual(ChangeObjectType.Commit, Changes[0].ObjectType); | ||
Assert.AreEqual(ChangeType.Deleted, Changes[0].Type); | ||
Assert.AreEqual("Message1", Changes[0].ObjectName); | ||
Assert.IsInstanceOfType(Changes[0], typeof(CommitChange)); | ||
Assert.AreEqual("1", ((CommitChange)Changes[0]).Hash); | ||
Assert.AreEqual("Message1", ((CommitChange)Changes[0]).Message); | ||
Assert.AreEqual("User", ((CommitChange)Changes[0]).User?.Name); | ||
Assert.AreEqual("test@example.com", ((CommitChange)Changes[0]).User?.Email); | ||
} | ||
|
||
private Commit MockCommit(string message, string sha, string user, string email) | ||
{ | ||
return Mock.Of<Commit>(c => | ||
c.Message == message && | ||
c.MessageShort == message && | ||
c.Sha == sha && | ||
c.Committer == new Signature(user, email, DateTimeOffset.FromUnixTimeSeconds(1))); | ||
} | ||
} | ||
} |
Oops, something went wrong.