public void AllTeamsShouldReturnCorrectTeamsCount() { var options = new DbContextOptionsBuilder <FooteoDbContext>() .UseInMemoryDatabase(databaseName: "AllTeams_Teams_DB") .Options; var dbContext = new FooteoDbContext(options); var townsService = new TownsService(dbContext); var leaguesService = new LeaguesService(dbContext, townsService); var mockUserStore = new Mock <IUserStore <FooteoUser> >(); var userManager = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null); var town = townsService.CreateTown("Sofia"); var user = new FooteoUser { Age = new Random().Next(20, 30), Email = $"*****@*****.**", FirstName = "Footeo", LastName = "Player", UserName = $"footeoPlayer", Town = town, PasswordHash = "123123", Player = new Player { FullName = "Footeo Player" } }; dbContext.Users.Add(user); dbContext.SaveChanges(); userManager.Setup(u => u.RemoveFromRoleAsync(user, "Player")).Returns(Task.FromResult(IdentityResult.Success)); userManager.Setup(u => u.AddToRoleAsync(user, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success)); userManager.Setup(u => u.AddToRoleAsync(user, "Captain")).Returns(Task.FromResult(IdentityResult.Success)); var user2 = new FooteoUser { Age = new Random().Next(20, 30), Email = $"*****@*****.**", FirstName = "Footeo", LastName = "Player", UserName = $"footeoPlayer2", Town = town, PasswordHash = "123123", Player = new Player { FullName = "Footeo Player" } }; dbContext.Users.Add(user2); dbContext.SaveChanges(); userManager.Setup(u => u.RemoveFromRoleAsync(user2, "Player")).Returns(Task.FromResult(IdentityResult.Success)); userManager.Setup(u => u.AddToRoleAsync(user2, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success)); userManager.Setup(u => u.AddToRoleAsync(user2, "Captain")).Returns(Task.FromResult(IdentityResult.Success)); var teamsService = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null); teamsService.CreateTeam("Team1", "TTT", user.UserName); teamsService.CreateTeam("Team2", "TTT", user2.UserName); var teams = teamsService.AllTeams <Team>().ToList(); var expectedTeamsCount = 2; Assert.AreEqual(expectedTeamsCount, teams.Count); }