-
Notifications
You must be signed in to change notification settings - Fork 96
Unit tests #81
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
Comments
fixes if DatabaseVersion == 4, migration 5 -> 6 will not run resulting in invalid schema. adds build.yml github action which builds and runs test on PR's and push'es to master branch. also addresses matteofabbri#81
Speaking of test, I am unable to do unit or integrated tests on my controllers that use Idenitty Mongo as a dependency. Is there a way to mock Identity Mongo RolesManager and UserManagers classes? Or is there a away to spin up test containers on random ports and feed that port to Identity Mongo's connection string? Please advise. |
I'm having the same problem. I did it this way with no success: _config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.SetBasePath(Directory.GetCurrentDirectory())
.Build();
MongoDbConfig mongoDbSettings = _config.GetSection(nameof(MongoDbConfig)).Get<MongoDbConfig>();
client = new MongoClient(mongoDbSettings.ConnectionString);
var database = client.GetDatabase("MyDb");
IMongoCollection<AppUser> userCollection = database.GetCollection<AppUser>("Users");
IMongoCollection<AppRole> roleCollection = database.GetCollection<AppRole>("Roles");
IdentityErrorDescriber error = new IdentityErrorDescriber();
userStore = new UserStore<AppUser, AppRole, Guid>(userCollection, roleCollection, error);
userManager = new UserManager<AppUser>(userStore, null, null, null, null, null, null, null, null);
signInManager = new SignInManager<AppUser>(
userManager, Mock.Of<IHttpContextAccessor>(), Mock.Of<IUserClaimsPrincipalFactory<AppUser>>(), null, null, null, null);
//Create user unit test method
bool success = false;
AppUser user = Activator.CreateInstance<AppUser>();
user.UserName = "user1";
user.Email = "user1@test.com";
IdentityResult result = userManager.CreateAsync(user, "Password2023?").Result;
if(result == null)
{
Assert.Fail("Error creating user user1");
} But I receive a null result on the "CreateAsync" method. I thought that this was the way to make the userStore to point to the mongoDb, but I´m not sure if it is the correct way. Anyone has the same issue? |
Have you considered to use Mongo2Go? A library that starts a MongoDB instance for integration tests. I already use it with success. |
Repository does not have unit tests.
Also test projects are not the best way to test library. They good to be useful examples of library usage.
The text was updated successfully, but these errors were encountered: