public void ExecuteStep03_MultipleCountersDifferentValues_CountersMerged() { // ARRANGE var collection = _database.GetCollection <BsonDocument>("hangfire.jobGraph"); collection.Indexes.DropAll(); collection.DeleteMany(new BsonDocument("_t", "CounterDto")); var counters = new List <BsonDocument>(); foreach (var i in Enumerable.Range(0, 5)) { counters.Add(new BsonDocument { ["_id"] = ObjectId.GenerateNewId(), ["Key"] = "stats:succeeded", ["Value"] = 1L, ["ExpireAt"] = BsonNull.Value, ["_t"] = "CounterDto" }); } var mergedCounter = new BsonDocument { ["_id"] = ObjectId.GenerateNewId(), ["Key"] = "stats:succeeded", ["Value"] = 5L, ["ExpireAt"] = BsonNull.Value, ["_t"] = "CounterDto" }; var aggregatedCounter = new BsonDocument { ["_id"] = ObjectId.GenerateNewId(), ["Key"] = "stats:succeeded", ["Value"] = 5L, ["ExpireAt"] = BsonNull.Value, ["_t"] = "CounterDto" }; counters.Add(mergedCounter); counters.Add(aggregatedCounter); collection.InsertMany(counters); // ACT var result = new RemoveMergedCounters().Execute(_database, new MongoStorageOptions(), _mongoMigrationBagMock.Object); // ASSERT var remainingCounter = collection.Find(new BsonDocument("_t", "CounterDto")).Single(); Assert.True(result, "Expected migration to be successful, reported 'false'"); Assert.Equal(10, remainingCounter["Value"].AsInt64); }
public void ExecuteStep03_TwoCountersSameValue_NewestChosen() { // ARRANGE var collection = _database.GetCollection <BsonDocument>("hangfire.jobGraph"); collection.Indexes.DropAll(); collection.DeleteMany(new BsonDocument("_t", "CounterDto")); collection.InsertOne(new BsonDocument { ["_id"] = ObjectId.GenerateNewId(), ["Key"] = "stats:succeeded", ["Value"] = 1L, ["ExpireAt"] = BsonNull.Value, ["_t"] = "CounterDto" }); var expectedDoc = new BsonDocument { ["_id"] = ObjectId.GenerateNewId(), ["Key"] = "stats:succeeded", ["Value"] = 1L, ["ExpireAt"] = BsonNull.Value, ["_t"] = "CounterDto" }; collection.InsertOne(expectedDoc); // ACT var result = new RemoveMergedCounters().Execute(_database, new MongoStorageOptions(), _mongoMigrationBagMock.Object); // ASSERT var remainingCounter = collection.Find(new BsonDocument("_t", "CounterDto")).Single(); Assert.NotNull(remainingCounter); Assert.True(result, "Expected migration to be successful, reported 'false'"); Assert.Equal(expectedDoc["_id"], remainingCounter["_id"]); }