-
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.
Add fakers for implemented schema, add projection helper tests
- Loading branch information
Showing
18 changed files
with
304 additions
and
7 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
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
2 changes: 1 addition & 1 deletion
2
...cusAPI.Tests/Fakers/BaseUserBadgeFaker.cs → ...s/Fakers/BaseModels/BaseUserBadgeFaker.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
2 changes: 1 addition & 1 deletion
2
...cusAPI.Tests/Fakers/BaseUserDecorFaker.cs → ...s/Fakers/BaseModels/BaseUserDecorFaker.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
2 changes: 1 addition & 1 deletion
2
test/FocusAPI.Tests/Fakers/BaseUserFaker.cs → ....Tests/Fakers/BaseModels/BaseUserFaker.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
2 changes: 1 addition & 1 deletion
2
...FocusAPI.Tests/Fakers/BaseUserPetFaker.cs → ...sts/Fakers/BaseModels/BaseUserPetFaker.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
22 changes: 22 additions & 0 deletions
22
test/FocusAPI.Tests/Fakers/ImplementedModels/BadgeFaker.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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Bogus; | ||
using FocusAPI.Models; | ||
|
||
|
||
namespace FocusAPI.Tests.Fakers.ImplementedModels | ||
{ | ||
internal class BadgeFaker : Faker<Badge> | ||
{ | ||
public BadgeFaker() | ||
{ | ||
RuleFor(badge => badge.Id, f => f.Random.Guid()); | ||
RuleFor(badge => badge.Name, f => f.Random.Word()); | ||
RuleFor(badge => badge.Description, f => f.Random.Words(4)); | ||
RuleFor(badge => badge.Image, f => [0x1]); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
test/FocusAPI.Tests/Fakers/ImplementedModels/DecorFaker.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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Bogus; | ||
using FocusAPI.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers.ImplementedModels | ||
{ | ||
internal class DecorFaker : Faker<Decor> | ||
{ | ||
public DecorFaker() | ||
{ | ||
RuleFor(decor => decor.Id, f => f.Random.Guid()); | ||
RuleFor(decor => decor.Price, f => Math.Abs(f.Random.Int())); | ||
RuleFor(decor => decor.Name, f => f.Random.Word()); | ||
RuleFor(decor => decor.HeightRequest, f => Math.Abs(f.Random.Int())); | ||
RuleFor(decor => decor.Image, f => [0x1]); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test/FocusAPI.Tests/Fakers/ImplementedModels/IslandFaker.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,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Bogus; | ||
using FocusAPI.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers.ImplementedModels | ||
{ | ||
internal class IslandFaker : Faker<Island> | ||
{ | ||
public IslandFaker() | ||
{ | ||
RuleFor(island => island.Id, f => f.Random.Guid()); | ||
RuleFor(island => island.Price, f => Math.Abs(f.Random.Int())); | ||
RuleFor(island => island.Name, f => f.Random.Word()); | ||
RuleFor(island => island.Image, f => [0x1]); | ||
} | ||
} | ||
} |
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,17 @@ | ||
using Bogus; | ||
using FocusAPI.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers.ImplementedModels | ||
{ | ||
internal class PetFaker : Faker<Pet> | ||
{ | ||
public PetFaker() | ||
{ | ||
RuleFor(pet => pet.Id, f => f.Random.Guid()); | ||
RuleFor(pet => pet.Price, f => Math.Abs(f.Random.Int())); | ||
RuleFor(pet => pet.Name, f => f.Random.Word()); | ||
RuleFor(pet => pet.Image, f => [0x1]); | ||
RuleFor(pet => pet.HeightRequest, f => Math.Abs(f.Random.Int())); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test/FocusAPI.Tests/Fakers/ImplementedModels/UserBadgeFaker.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,16 @@ | ||
using Bogus; | ||
using FocusAPI.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers.ImplementedModels; | ||
internal class UserBadgeFaker : Faker<UserBadge> | ||
{ | ||
internal UserBadgeFaker(Guid? userId = null) | ||
{ | ||
BadgeFaker badgeFaker = new(); | ||
Badge badge = badgeFaker.Generate(); | ||
RuleFor(userBadge => userBadge.UserId, f => userId ??= f.Random.Guid()); | ||
RuleFor(userBadge => userBadge.BadgeId, f => badge.Id); | ||
RuleFor(userBadge => userBadge.DateAcquired, f => f.Date.Recent()); | ||
RuleFor(userBadge => userBadge.Badge, f => badge); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/FocusAPI.Tests/Fakers/ImplementedModels/UserDecorFaker.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,15 @@ | ||
using Bogus; | ||
using FocusAPI.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers.ImplementedModels; | ||
internal class UserDecorFaker : Faker<UserDecor> | ||
{ | ||
internal UserDecorFaker(Guid? userId = null) | ||
{ | ||
DecorFaker decorFaker = new(); | ||
Decor decor = decorFaker.Generate(); | ||
RuleFor(userDecor => userDecor.UserId, f => userId ??= f.Random.Guid()); | ||
RuleFor(userDecor => userDecor.DecorId, f => decor.Id); | ||
RuleFor(userDecor => userDecor.Decor, f => decor); | ||
} | ||
} |
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,39 @@ | ||
using Bogus; | ||
using FocusAPI.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers.ImplementedModels; | ||
internal class UserFaker : Faker<User> | ||
{ | ||
internal UserFaker() | ||
{ | ||
Guid userId = Guid.NewGuid(); | ||
RuleFor(user => user.Id, f => userId); | ||
RuleFor(user => user.Auth0Id, f => f.Random.Word()); | ||
RuleFor(user => user.UserName, f => f.Random.Word()); | ||
RuleFor(user => user.Email, f => f.Internet.Email()); | ||
RuleFor(user => user.DateCreated, f => f.Date.Recent()); | ||
RuleFor(user => user.Balance, f => Math.Abs(f.Random.Int())); | ||
RuleFor(user => user.Pronouns, f => f.Random.Word()); | ||
RuleFor(user => user.ProfilePicture, f => [0x1]); | ||
|
||
UserPetFaker userPetFaker = new(userId); | ||
List<UserPet> userPets = userPetFaker.Generate(2); | ||
RuleFor(user => user.Pets, f => userPets); | ||
RuleFor(user => user.SelectedPetId, f => userPets.First().PetId); | ||
|
||
UserIslandFaker userIslandFaker = new(userId); | ||
List<UserIsland> userIslands = userIslandFaker.Generate(2); | ||
RuleFor(user => user.Islands, f => userIslands); | ||
RuleFor(user => user.SelectedIslandId, f => userIslands.First().IslandId); | ||
|
||
UserDecorFaker userDecorFaker = new(userId); | ||
List<UserDecor> userDecor = userDecorFaker.Generate(2); | ||
RuleFor(user => user.Decor, f => userDecor); | ||
RuleFor(user => user.SelectedDecorId, f => userDecor.First().DecorId); | ||
|
||
UserBadgeFaker userBadgeFaker = new(userId); | ||
List<UserBadge> userBadges = userBadgeFaker.Generate(2); | ||
RuleFor(user => user.Badges, f => userBadges); | ||
RuleFor(user => user.SelectedBadgeId, f => userBadges.First().BadgeId); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/FocusAPI.Tests/Fakers/ImplementedModels/UserIslandFaker.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,15 @@ | ||
using Bogus; | ||
using FocusAPI.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers.ImplementedModels; | ||
internal class UserIslandFaker : Faker<UserIsland> | ||
{ | ||
internal UserIslandFaker(Guid? userId = null) | ||
{ | ||
IslandFaker islandFaker = new(); | ||
Island island = islandFaker.Generate(); | ||
RuleFor(userIsland => userIsland.UserId, f => userId ??= f.Random.Guid()); | ||
RuleFor(userIsland => userIsland.IslandId, f => island.Id); | ||
RuleFor(userIsland => userIsland.Island, f => island); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/FocusAPI.Tests/Fakers/ImplementedModels/UserPetFaker.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,15 @@ | ||
using Bogus; | ||
using FocusAPI.Models; | ||
|
||
namespace FocusAPI.Tests.Fakers.ImplementedModels; | ||
internal class UserPetFaker : Faker<UserPet> | ||
{ | ||
internal UserPetFaker(Guid? userId = null) | ||
{ | ||
PetFaker petFaker = new(); | ||
Pet pet = petFaker.Generate(); | ||
RuleFor(userPet => userPet.UserId, f => userId ??= f.Random.Guid()); | ||
RuleFor(userPet => userPet.PetId, f => pet.Id); | ||
RuleFor(userPet => userPet.Pet, f => pet); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
test/FocusAPI.Tests/ProjectionHelperMethods/ProjectionHelperTests.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,112 @@ | ||
using FocusAPI.Helpers; | ||
using FocusAPI.Models; | ||
using FocusAPI.Tests.Fakers.BaseModels; | ||
using FocusAPI.Tests.Fakers.ImplementedModels; | ||
using FocusCore.Models; | ||
using Shouldly; | ||
|
||
namespace FocusAPI.Tests.ProjectionHelperMethods; | ||
public class ProjectionHelperTests | ||
{ | ||
UserFaker _userFaker; | ||
BaseUserFaker _baseUserFaker; | ||
public ProjectionHelperTests() | ||
{ | ||
SetupTestHelpers(); | ||
} | ||
|
||
void SetupTestHelpers() | ||
{ | ||
_userFaker = new UserFaker(); | ||
_baseUserFaker = new BaseUserFaker(); | ||
} | ||
|
||
[Fact] | ||
public void ProjectToBaseUser_CorrectlyProjectsAllFields() | ||
{ | ||
// ARRANGE | ||
User user = _userFaker.Generate(); | ||
|
||
// ACT | ||
BaseUser projectedUser = ProjectionHelper.ProjectToBaseUser(user); | ||
|
||
// ASSERT | ||
projectedUser.Id.ShouldBe(user.Id); | ||
projectedUser.Auth0Id.ShouldBe(user.Auth0Id); | ||
projectedUser.UserName.ShouldBe(user.UserName); | ||
projectedUser.Email.ShouldBe(user.Email); | ||
projectedUser.DateCreated.ShouldBe(user.DateCreated); | ||
projectedUser.Balance.ShouldBe(user.Balance); | ||
projectedUser.Pronouns.ShouldBe(user.Pronouns); | ||
projectedUser.ProfilePicture.ShouldBe(user.ProfilePicture); | ||
projectedUser.SelectedPetId.ShouldBe(user.SelectedPetId); | ||
projectedUser.SelectedIslandId.ShouldBe(user.SelectedIslandId); | ||
projectedUser.SelectedDecorId.ShouldBe(user.SelectedDecorId); | ||
projectedUser.SelectedBadgeId.ShouldBe(user.SelectedBadgeId); | ||
|
||
projectedUser.Pets.ShouldNotBeNull(); | ||
projectedUser.Pets.Count.ShouldBe(user.Pets.Count); | ||
for (int i = 0; i < projectedUser.Pets.Count; i++) | ||
{ | ||
UserPet userPet = user.Pets.ElementAt(i); | ||
BaseUserPet projectedUserPet = projectedUser.Pets.ElementAt(i); | ||
projectedUserPet.UserId.ShouldBe(userPet.UserId); | ||
projectedUserPet.PetId.ShouldBe(userPet.PetId); | ||
/* Check these assertions w/ team - do we want to do a complete mapping of all items when projecting? | ||
projectedUserPet.Pet.Id.ShouldBe(userPet.Pet.Id); | ||
projectedUserPet.Pet.Price.ShouldBe(userPet.Pet.Price); | ||
projectedUserPet.Pet.Name.ShouldBe(userPet.Pet.Name); | ||
projectedUserPet.Pet.Image.ShouldBe(userPet.Pet.Image); | ||
projectedUserPet.Pet.HeightRequest.ShouldBe(userPet.Pet.HeightRequest); | ||
*/ | ||
} | ||
|
||
projectedUser.Islands.ShouldNotBeNull(); | ||
projectedUser.Islands.Count.ShouldBe(user.Islands.Count); | ||
for (int i = 0; i < projectedUser.Islands.Count; i++) | ||
{ | ||
UserIsland userIsland = user.Islands.ElementAt(i); | ||
BaseUserIsland projectedUserIsland = projectedUser.Islands.ElementAt(i); | ||
projectedUserIsland.UserId.ShouldBe(userIsland.UserId); | ||
projectedUserIsland.IslandId.ShouldBe(userIsland.IslandId); | ||
/* | ||
projectedUserIsland.Island.Id.ShouldBe(userIsland.Island.Id); | ||
projectedUserIsland.Island.Price.ShouldBe(userIsland.Island.Price); | ||
projectedUserIsland.Island.Name.ShouldBe(userIsland.Island.Name); | ||
projectedUserIsland.Island.Image.ShouldBe(userIsland.Island.Image); | ||
*/ | ||
} | ||
|
||
projectedUser.Decor.ShouldNotBeNull(); | ||
projectedUser.Decor.Count.ShouldBe(user.Decor.Count); | ||
for (int i = 0; i < projectedUser.Decor.Count; i++) | ||
{ | ||
UserDecor userDecor = user.Decor.ElementAt(i); | ||
BaseUserDecor projectedUserDecor = projectedUser.Decor.ElementAt(i); | ||
projectedUserDecor.UserId.ShouldBe(userDecor.UserId); | ||
projectedUserDecor.DecorId.ShouldBe(userDecor.DecorId); | ||
/* | ||
projectedUserDecor.Decor.Id.ShouldBe(userDecor.Decor.Id); | ||
projectedUserDecor.Decor.Price.ShouldBe(userDecor.Decor.Price); | ||
projectedUserDecor.Decor.Name.ShouldBe(userDecor.Decor.Name); | ||
projectedUserDecor.Decor.Image.ShouldBe(userDecor.Decor.Image); | ||
projectedUserDecor.Decor.HeightRequest.ShouldBe(userDecor.Decor.HeightRequest); | ||
*/ | ||
} | ||
|
||
projectedUser.Badges.ShouldNotBeNull(); | ||
projectedUser.Badges.Count.ShouldBe(user.Badges.Count); | ||
for (int i = 0; i < projectedUser.Badges.Count; i++) | ||
{ | ||
UserBadge userBadge = user.Badges.ElementAt(i); | ||
BaseUserBadge projectedUserBadge = projectedUser.Badges.ElementAt(i); | ||
projectedUserBadge.UserId.ShouldBe(userBadge.UserId); | ||
projectedUserBadge.BadgeId.ShouldBe(userBadge.BadgeId); | ||
/* | ||
projectedUserBadge.Badge.Id.ShouldBe(userBadge.Badge.Id); | ||
projectedUserBadge.Badge.Name.ShouldBe(userBadge.Badge.Name); | ||
projectedUserBadge.Badge.Description.ShouldBe(userBadge.Badge.Description); | ||
*/ | ||
} | ||
} | ||
} |
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