Skip to content

Commit

Permalink
use manual serialization (#331)
Browse files Browse the repository at this point in the history
* use manual serialization

use manual serialization. this avoids conflict with serializer conventions

#328

* remove not used convention

* minor optimization of type casting
  • Loading branch information
gottscj authored Nov 27, 2022
1 parent 92f7ca6 commit 9f5da1d
Show file tree
Hide file tree
Showing 41 changed files with 1,410 additions and 586 deletions.
34 changes: 15 additions & 19 deletions src/Hangfire.Mongo.Tests/ExpirationManagerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public void Execute_Processes_CounterTable()
Key = "key",
Value = 1L,
ExpireAt = DateTime.UtcNow.AddMonths(-1)
});
}.Serialize());

var manager = CreateManager();

// Act
manager.Execute(_token);

// Assert
var count = _dbContext.JobGraph.OfType<CounterDto>().Count(new BsonDocument());
var count = _dbContext.JobGraph.Count(new BsonDocument("_t", nameof(CounterDto)));
Assert.Equal(0, count);
}

Expand All @@ -91,15 +91,15 @@ public void Execute_Processes_JobTable()
Arguments = "",
CreatedAt = DateTime.UtcNow,
ExpireAt = DateTime.UtcNow.AddMonths(-1),
});
}.Serialize());

var manager = CreateManager();

// Act
manager.Execute(_token);

// Assert
var count = _dbContext.JobGraph.OfType<JobDto>().Count(new BsonDocument());
var count = _dbContext.JobGraph.Count(new BsonDocument("_t", nameof(JobDto)));
Assert.Equal(0, count);
}

Expand All @@ -112,7 +112,7 @@ public void Execute_Processes_ListTable()
Id = ObjectId.GenerateNewId(),
Item = "key",
ExpireAt = DateTime.UtcNow.AddMonths(-1)
});
}.Serialize());

var manager = CreateManager();

Expand All @@ -122,22 +122,22 @@ public void Execute_Processes_ListTable()
// Assert
var count = _dbContext
.JobGraph
.OfType<ListDto>()
.Count(new BsonDocument());
.Count(new BsonDocument("_t", nameof(ListDto)));
Assert.Equal(0, count);
}

[Fact, CleanDatabase]
public void Execute_Processes_SetTable()
{
// Arrange
_dbContext.JobGraph.InsertOne(new SetDto
var setDto = new SetDto
{
Id = ObjectId.GenerateNewId(),
Key = "key<>",
Score = 0,
ExpireAt = DateTime.UtcNow.AddMonths(-1)
});
}.Serialize();
_dbContext.JobGraph.InsertOne(setDto);

var manager = CreateManager();

Expand All @@ -147,8 +147,7 @@ public void Execute_Processes_SetTable()
// Assert
var count = _dbContext
.JobGraph
.OfType<SetDto>()
.Count(new BsonDocument());
.Count(new BsonDocument("_t", nameof(SetDto)));
Assert.Equal(0, count);
}

Expand All @@ -162,7 +161,7 @@ public void Execute_Processes_HashTable()
Key = "key",
Fields = new Dictionary<string, string> {["field"] = ""},
ExpireAt = DateTime.UtcNow.AddMonths(-1)
});
}.Serialize());

var manager = CreateManager();

Expand All @@ -172,8 +171,7 @@ public void Execute_Processes_HashTable()
// Assert
var count = _dbContext
.JobGraph
.OfType<HashDto>()
.Count(new BsonDocument());
.Count(new BsonDocument("_t", nameof(HashDto)));
Assert.Equal(0, count);
}

Expand All @@ -187,7 +185,7 @@ public void Execute_Processes_AggregatedCounterTable()
Key = "key",
Value = 1,
ExpireAt = DateTime.UtcNow.AddMonths(-1)
});
}.Serialize());

var manager = CreateManager();

Expand All @@ -197,8 +195,7 @@ public void Execute_Processes_AggregatedCounterTable()
// Assert
Assert.Equal(0, _dbContext
.JobGraph
.OfType<CounterDto>()
.Find(new BsonDocument()).Count());
.Count(new BsonDocument("_t", nameof(CounterDto))));
}


Expand All @@ -222,8 +219,7 @@ private static bool IsEntryExpired(HangfireDbContext connection)
{
var count = connection
.JobGraph
.OfType<ExpiringJobDto>()
.Count(new BsonDocument());
.Count(new BsonDocument("_t", nameof(ExpiringJobDto)));

return count == 0;
}
Expand Down
Loading

0 comments on commit 9f5da1d

Please sign in to comment.