Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badge trading #231

Open
wants to merge 21 commits into
base: badge-trading
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions TPP.Persistence.MongoDB.Tests/Repos/BadgeRepoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MongoDB.Driver;
using Moq;
using NodaTime;
using NodaTime.Text;
using NUnit.Framework;
using TPP.Common;
using TPP.Persistence.Models;
Expand All @@ -19,6 +20,12 @@ public class BadgeRepoTest : MongoTestBase
public BadgeRepo CreateBadgeRepo() =>
new BadgeRepo(CreateTemporaryDatabase(), Mock.Of<IMongoBadgeLogRepo>(), Mock.Of<IClock>());

internal class MockClock : IClock
{
public Instant FixedCurrentInstant = Instant.FromUnixTimeSeconds(1234567890);
public Instant GetCurrentInstant() => FixedCurrentInstant;
}

[Test]
public async Task insert_then_read_are_equal()
{
Expand Down Expand Up @@ -190,6 +197,33 @@ public async Task FindAllForSaleByCustom_only_returns_badges_for_sale()
Assert.AreEqual(new List<Badge>() { forSale }, saleList);
}

[Test]
public async Task can_handle_null_shiny_fields()
{
IMongoDatabase db = CreateTemporaryDatabase();

const string id = "590df61373b975210006fcdf";
Instant instant = InstantPattern.ExtendedIso.Parse("2017-05-06T16:13:07.314Z").Value;

BadgeRepo badgeRepo = new BadgeRepo(db, new BadgeLogRepo(db), new MockClock());
IMongoCollection<BsonDocument> bsonBadgeCollection = db.GetCollection<BsonDocument>("badges");
await bsonBadgeCollection.InsertOneAsync(BsonDocument.Create(new Dictionary<string, object?>
{
["_id"] = ObjectId.Parse(id),
["userid"] = "mogi",
["species"] = "1",
["source"] = "manual_creation",
["created_at"] = instant.ToDateTimeUtc(),
["form"] = 0,
}));

IMongoCollection<Badge> badgeCollection = db.GetCollection<Badge>("badges"); ;

Badge b = await badgeCollection.Find(b => b.Id == id).FirstAsync();

Assert.AreEqual(false, b.Shiny);
Mogiiii marked this conversation as resolved.
Show resolved Hide resolved
}

[TestFixture]
private class TransferBadge : MongoTestBase
{
Expand Down