Skip to content

Commit

Permalink
convert all to FA
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Jan 7, 2025
1 parent 8907c8c commit 92c7b48
Show file tree
Hide file tree
Showing 52 changed files with 258 additions and 364 deletions.
3 changes: 1 addition & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<PackageVersion Include="Polly" Version="7.2.3" />
<PackageVersion Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageVersion Include="Shouldly" Version="4.2.1" />
<PackageVersion Include="Speckle.Newtonsoft.Json" Version="13.0.2" />
<PackageVersion Include="Speckle.DoubleNumerics" Version="4.0.1" />
<PackageVersion Include="SimpleExec" Version="12.0.0" />
Expand All @@ -33,4 +32,4 @@
<GlobalPackageReference Include="GitVersion.MsBuild" Version="5.12.0" />
<GlobalPackageReference Include="Speckle.InterfaceGenerator" Version="0.9.6" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.ComponentModel;
using FluentAssertions;
using GraphQL;
using GraphQL.Client.Http;
using Shouldly;

using Speckle.Newtonsoft.Json;
using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL.Inputs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FluentAssertions;
using Shouldly;

using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL.Inputs;
using Speckle.Sdk.Api.GraphQL.Models;
Expand Down Expand Up @@ -29,7 +29,7 @@ public Task DisposeAsync()
public async Task ActiveUserGet()
{
var res = await Sut.Get();
res.ShouldNotBeNull();
res.Should().NotBeNull();
res!.id.Should().Be(_testUser.Account.userInfo.id);
}

Expand All @@ -49,7 +49,7 @@ public async Task ActiveUserUpdate()

var res = await Sut.Update(new UserUpdateInput(name: NEW_NAME, bio: NEW_BIO, company: NEW_COMPANY));

res.ShouldNotBeNull();
res.Should().NotBeNull();
res.id.Should().Be(_testUser.Account.userInfo.id);
res.name.Should().Be(NEW_NAME);
res.company.Should().Be(NEW_COMPANY);
Expand All @@ -64,14 +64,14 @@ public async Task ActiveUserGetProjects()

var res = await Sut.GetProjects();

res.items.ShouldContain(x => x.id == p1.id);
res.items.ShouldContain(x => x.id == p2.id);
res.items.Should().Contain(x => x.id == p1.id);
res.items.Should().Contain(x => x.id == p2.id);
res.items.Count.Should().Be(2);
}

[Fact]
public async Task ActiveUserGetProjects_NoAuth()
{
await Should.ThrowAsync<SpeckleGraphQLException>(async () => await Fixtures.Unauthed.ActiveUser.GetProjects());
await FluentActions.Invoking(async () => await Fixtures.Unauthed.ActiveUser.GetProjects()).Should().ThrowAsync<SpeckleGraphQLException>();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Shouldly;
using FluentAssertions;

using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL.Inputs;
using Speckle.Sdk.Api.GraphQL.Models;
Expand Down Expand Up @@ -34,7 +35,7 @@ public async Task Get()
{
var comment = await Sut.Get(_comment.id, _project.id);

comment.ShouldNotBeNull();
comment.Should().NotBeNull();
comment.id.Should().Be(_comment.id);
comment.authorId.Should().Be(_testUser.Account.userInfo.id);
}
Expand All @@ -44,19 +45,17 @@ public async Task GetProjectComments()
{
var comments = await Sut.GetProjectComments(_project.id);

comments.ShouldNotBeNull();
comments.Should().NotBeNull();
comments.items.Count.Should().Be(1);
comments.totalCount.Should().Be(1);

Comment comment = comments.items[0];
comment.ShouldNotBeNull();
comment.Should().NotBeNull();
comment.authorId.Should().Be(_testUser.Account.userInfo.id);
comment.ShouldSatisfyAllConditions(
() => comment.id.Should().Be(_comment.id),
() => comment.authorId.Should().Be(_comment.authorId),
() => comment.archived.Should().Be(false),
() => comment.createdAt.Should().Be(_comment.createdAt)
);
comment.id.Should().Be(_comment.id);
comment.authorId.Should().Be(_comment.authorId);
comment.archived.Should().Be(false);
comment.createdAt.Should().Be(_comment.createdAt);
}

[Fact]
Expand All @@ -65,7 +64,7 @@ public async Task MarkViewed()
await Sut.MarkViewed(new(_comment.id, _project.id));

var res = await Sut.Get(_comment.id, _project.id);
res.viewedAt.ShouldNotBeNull();
res.viewedAt.Should().NotBeNull();
}

[Fact]
Expand All @@ -91,13 +90,11 @@ public async Task Edit()

var editedComment = await Sut.Edit(input);

editedComment.ShouldNotBeNull();
editedComment.ShouldSatisfyAllConditions(
() => editedComment.id.Should().Be(_comment.id),
() => editedComment.authorId.Should().Be(_comment.authorId),
() => editedComment.createdAt.Should().Be(_comment.createdAt),
() => editedComment.updatedAt.Should().BeGreaterThanOrEqualTo(_comment.updatedAt)
);
editedComment.Should().NotBeNull();
editedComment.id.Should().Be(_comment.id);
editedComment.authorId.Should().Be(_comment.authorId);
editedComment.createdAt.Should().Be(_comment.createdAt);
editedComment.updatedAt.Should().BeOnOrAfter(_comment.updatedAt);
}

[Fact]
Expand All @@ -109,7 +106,7 @@ public async Task Reply()

var editedComment = await Sut.Reply(input);

editedComment.ShouldNotBeNull();
editedComment.Should().NotBeNull();
}

private async Task<Comment> CreateComment()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Shouldly;

using FluentAssertions;
using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL.Enums;
using Speckle.Sdk.Api.GraphQL.Inputs;
Expand Down Expand Up @@ -34,42 +35,36 @@ public async Task ModelCreate_Throws_InvalidInput(string name)
CreateModelInput input = new(name, null, _project.id);

// Act & Assert
var ex = await Should.ThrowAsync<AggregateException>(async () => await Sut.Create(input));
var ex = await FluentActions.Invoking(async () => await Sut.Create(input)).Should().ThrowAsync<AggregateException>();

ex.InnerExceptions.ShouldHaveSingleItem();
ex.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLException>();
ex.WithInnerExceptionExactly<SpeckleGraphQLException>();
}

[Fact]
public async Task ModelGet_Throws_NoAuth()
{
// Act & Assert
var ex = await Should.ThrowAsync<AggregateException>(
var ex = await FluentActions.Invoking(
async () => await Fixtures.Unauthed.Model.Get(_model.id, _project.id)
);
).Should().ThrowAsync<AggregateException>();

ex.InnerExceptions.ShouldHaveSingleItem();
ex.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLForbiddenException>();
ex.WithInnerExceptionExactly<SpeckleGraphQLForbiddenException>();
}

[Fact]
public async Task ModelGet_Throws_NonExistentModel()
{
// Act & Assert
var ex = await Should.ThrowAsync<AggregateException>(async () => await Sut.Get("non existent model", _project.id));

ex.InnerExceptions.ShouldHaveSingleItem();
ex.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLException>();
var ex = await FluentActions.Invoking(async () => await Sut.Get("non existent model", _project.id)).Should().ThrowAsync<AggregateException>();
ex.WithInnerExceptionExactly<SpeckleGraphQLException>();
}

[Fact]
public async Task ModelGet_Throws_NonExistentProject()
{
// Act & Assert
var ex = await Should.ThrowAsync<AggregateException>(async () => await Sut.Get(_model.id, "non existent project"));

ex.InnerExceptions.ShouldHaveSingleItem();
ex.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLStreamNotFoundException>();
var ex = await FluentActions.Invoking(async () => await Sut.Get(_model.id, "non existent project")).Should().ThrowAsync<AggregateException>();
ex.WithInnerExceptionExactly<SpeckleGraphQLStreamNotFoundException>();
}

[Fact]
Expand All @@ -79,10 +74,8 @@ public async Task ModelUpdate_Throws_NonExistentModel()
UpdateModelInput input = new("non-existent model", "MY new name", "MY new desc", _project.id);

// Act & Assert
var ex = await Should.ThrowAsync<AggregateException>(async () => await Sut.Update(input));

ex.InnerExceptions.ShouldHaveSingleItem();
ex.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLException>();
var ex = await FluentActions.Invoking(async () => await Sut.Update(input)).Should().ThrowAsync<AggregateException>();
ex.WithInnerExceptionExactly<SpeckleGraphQLException>();
}

[Fact]
Expand All @@ -92,10 +85,8 @@ public async Task ModelUpdate_Throws_NonExistentProject()
UpdateModelInput input = new(_model.id, "MY new name", "MY new desc", "non-existent project");

// Act & Assert
var ex = await Should.ThrowAsync<AggregateException>(async () => await Sut.Update(input));

ex.InnerExceptions.ShouldHaveSingleItem();
ex.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLForbiddenException>();
var ex = await FluentActions.Invoking(async () => await Sut.Update(input)).Should().ThrowAsync<AggregateException>();
ex.WithInnerExceptionExactly<SpeckleGraphQLForbiddenException>();
}

[Fact]
Expand All @@ -105,10 +96,8 @@ public async Task ModelUpdate_Throws_NonAuthProject()
UpdateModelInput input = new(_model.id, "MY new name", "MY new desc", _project.id);

// Act & Assert
var ex = await Should.ThrowAsync<AggregateException>(async () => await Fixtures.Unauthed.Model.Update(input));

ex.InnerExceptions.ShouldHaveSingleItem();
ex.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLForbiddenException>();
var ex = await FluentActions.Invoking(async () => await Fixtures.Unauthed.Model.Update(input)).Should().ThrowAsync<AggregateException>();
ex.WithInnerExceptionExactly<SpeckleGraphQLForbiddenException>();
}

[Fact]
Expand All @@ -121,9 +110,7 @@ public async Task ModelDelete_Throws_NoAuth()
await Sut.Delete(input);

// Act & Assert
var ex = await Should.ThrowAsync<AggregateException>(async () => await Sut.Delete(input));

ex.InnerExceptions.ShouldHaveSingleItem();
ex.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLException>();
var ex = await FluentActions.Invoking(async () => await Sut.Delete(input)).Should().ThrowAsync<AggregateException>();
ex.WithInnerExceptionExactly<SpeckleGraphQLException>();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FluentAssertions;
using Shouldly;

using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL.Inputs;
using Speckle.Sdk.Api.GraphQL.Models;
Expand Down Expand Up @@ -41,8 +41,8 @@ public async Task ModelCreate(string name, string? description)
Model result = await Sut.Create(input);

// Assert
result.ShouldNotBeNull();
result.id.ShouldNotBeNull();
result.Should().NotBeNull();
result.id.Should().NotBeNull();
result.name.Should().ContainEquivalentOf(input.name);
result.description.Should().Be(input.description);
}
Expand Down Expand Up @@ -115,13 +115,11 @@ public async Task ModelDelete()
await Sut.Delete(input);

// Assert: Ensure fetching the deleted model throws an exception
var getEx = await Should.ThrowAsync<AggregateException>(() => Sut.Get(_model.id, _project.id));
getEx.InnerExceptions.ShouldHaveSingleItem();
getEx.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLException>();
var getEx = await FluentActions.Invoking(() => Sut.Get(_model.id, _project.id)).Should().ThrowAsync<AggregateException>();
getEx.WithInnerExceptionExactly<SpeckleGraphQLException>();

// Assert: Ensure deleting the non-existing model again throws an exception
var delEx = await Should.ThrowAsync<AggregateException>(() => Sut.Delete(input));
delEx.InnerExceptions.ShouldHaveSingleItem();
delEx.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLException>();
var delEx = await FluentActions.Invoking(() => Sut.Delete(input)).Should().ThrowAsync<AggregateException>();
getEx.WithInnerExceptionExactly<SpeckleGraphQLException>();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Threading.Tasks;
using Shouldly;
using FluentAssertions;
using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL.Resources;
using Speckle.Sdk.Credentials;
Expand All @@ -24,7 +24,7 @@ public async Task OtherUserGet_Should_ReturnCorrectUser()
{
var res = await Sut.Get(_testData.userInfo.id);

res.ShouldNotBeNull();
res.Should().NotBeNull();
res!.name.Should().Be(_testData.userInfo.name);
}

Expand All @@ -41,7 +41,7 @@ public async Task UserSearch_Should_ReturnMatchingUser()
{
var res = await Sut.UserSearch(_testData.userInfo.email, 25);

res.items.ShouldHaveSingleItem();
res.items.Should().ContainSingle();
res.items[0].id.Should().Be(_testData.userInfo.id);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FluentAssertions;
using Shouldly;

using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL.Inputs;
using Speckle.Sdk.Api.GraphQL.Models;
Expand Down Expand Up @@ -36,12 +36,11 @@ public async Task ProjectInviteCreate_InvalidInput_ShouldThrowSpeckleGraphQLExce
{
var input = new ProjectInviteCreateInput(email, role, serverRole, userId);

var exception = await Should.ThrowAsync<AggregateException>(async () =>
var exception = await FluentActions.Invoking(async () =>
{
await Sut.Create(_project.id, input);
});
}).Should().ThrowAsync<AggregateException>();

exception.InnerExceptions.Should().ContainSingle();
exception.InnerExceptions[0].Should().BeOfType<SpeckleGraphQLException>();
exception.WithInnerExceptionExactly<SpeckleGraphQLException>();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Linq;
using System.Threading.Tasks;
using Shouldly;
using FluentAssertions;
using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL;
using Speckle.Sdk.Api.GraphQL.Inputs;
Expand Down Expand Up @@ -46,9 +46,9 @@ public async Task ProjectInviteCreate_ByEmail()
var invite = invites.First(i => i.projectId == res.id);

res.id.Should().Be(_project.id);
res.invitedTeam.ShouldHaveSingleItem();
res.invitedTeam.Should().ContainSingle();
invite.user!.id.Should().Be(_invitee.Account.userInfo.id);
invite.token.ShouldNotBeNull();
invite.token.Should().NotBeNull();
}

[Fact]
Expand All @@ -58,7 +58,7 @@ public async Task ProjectInviteCreate_ByUserId()
var res = await _inviter.ProjectInvite.Create(_project.id, input);

res.id.Should().Be(_project.id);
res.invitedTeam.ShouldHaveSingleItem();
res.invitedTeam.Should().ContainSingle();
res.invitedTeam[0].user!.id.Should().Be(_invitee.Account.userInfo.id);
}

Expand All @@ -67,10 +67,8 @@ public async Task ProjectInviteGet()
{
var collaborator = await _invitee.ProjectInvite.Get(_project.id, _createdInvite.token).NotNull();

collaborator.ShouldSatisfyAllConditions(
() => collaborator.inviteId.Should().Be(_createdInvite.inviteId),
() => collaborator.user!.id.Should().Be(_createdInvite.user!.id)
);
collaborator.inviteId.Should().Be(_createdInvite.inviteId);
collaborator.user!.id.Should().Be(_createdInvite.user!.id);
}

[Fact]
Expand All @@ -90,7 +88,7 @@ public async Task ProjectInviteUse_MemberAdded()
var teamMembers = project.team.Select(c => c.user.id).ToArray();
var expectedTeamMembers = new[] { _inviter.Account.userInfo.id, _invitee.Account.userInfo.id };

teamMembers.Should().Be(expectedTeamMembers, ignoreOrder: true);
teamMembers.Should().BeEquivalentTo(expectedTeamMembers);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Shouldly;

using FluentAssertions;
using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL;
using Speckle.Sdk.Api.GraphQL.Enums;
Expand Down
Loading

0 comments on commit 92c7b48

Please sign in to comment.