public void Should_Be_Right_Challenges_When_Find_By_Accelartion_And_User(int accelerationId, int userId) { var fakeContext = new FakeContext("ChallengeByAccelerationAndUser"); fakeContext.FillWithAll(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData <User>(). Where(user => user.Id == userId). Join(fakeContext.GetFakeData <Candidate>(), user => user.Id, candidate => candidate.UserId, (user, candidate) => candidate). Join(fakeContext.GetFakeData <Acceleration>(), candidate => candidate.AccelerationId, acceleration => acceleration.Id, (candidate, acceleration) => acceleration). Where(acceleration => acceleration.Id == accelerationId). Join(fakeContext.GetFakeData <Models.Challenge>(), acceleration => acceleration.ChallengeId, challenge => challenge.Id, (acceleration, challenge) => challenge). Distinct(). ToList(); var service = new ChallengeService(context); var actual = service.FindByAccelerationIdAndUserId(userId, accelerationId); Assert.Equal(expected, actual, new ChallengeIdComparer()); } }
public void FindByAccelerationIdTest_Return_Right(int challengeId, int accelerationId, params string[] idSubmissionsExpected) { var fakeContext = new FakeContext("FindByChallengeIdAndAccelerationId"); fakeContext.FillWith<Acceleration>(); fakeContext.FillWith<Candidate>(); fakeContext.FillWith<User>(); fakeContext.FillWith<Submission>(); fakeContext.FillWith <Models.Challenge>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { List<Submission> expected = new List<Submission>(); foreach (var idCandidate in idSubmissionsExpected) { var idSubmissionInt = idCandidate.Split(',').Select(x => int.Parse(x)).ToList(); expected.Add(fakeContext .GetFakeData<Submission>() .Find(x => x.UserId == idSubmissionInt[0] && x.ChallengeId == idSubmissionInt[1])); } var service = new SubmissionService(context); var actual = service.FindByChallengeIdAndAccelerationId(challengeId, accelerationId) .OrderBy(s => s.UserId) .ThenBy(s => s.ChallengeId); Assert.Equal(expected, actual, new SubmissionIdComparer()); } }
public void Should_Be_Right_Submissions_When_Find_By_Challenge_And_Acceleration(int challengeId, int accelerationId) { var fakeContext = new FakeContext("SubmissionByChallengeAndAcceleration"); fakeContext.FillWithAll(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData <Candidate>(). Where(candidate => candidate.AccelerationId == accelerationId). Join(fakeContext.GetFakeData <User>(), candidate => candidate.UserId, user => user.Id, (candidate, user) => user). Join(fakeContext.GetFakeData <Submission>(), user => user.Id, submission => submission.UserId, (user, submission) => submission). Where(submission => submission.ChallengeId == challengeId). Distinct(). ToList(); var service = new SubmissionService(context); var actual = service.FindByChallengeIdAndAccelerationId(accelerationId, challengeId); Assert.Equal(expected, actual, new SubmissionIdComparer()); } }
public void SaveTeste_When_Update(int userId, int challengeId) { var fakeContext = new FakeContext("UpdateSubmission"); fakeContext.FillWith<Submission>(); fakeContext.FillWith<User>(); fakeContext.FillWith<Models.Challenge>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData<Submission>() .Find(x => x.UserId == userId && x.ChallengeId == challengeId); expected.UserId = 1; expected.ChallengeId = 2; expected.Score = 100; expected.CreatedAt = DateTime.Today; var service = new SubmissionService(context); var actual = service.Save(expected); Assert.Equal(expected, actual); Assert.Equal(expected.Score, actual.Score); Assert.Equal(expected.CreatedAt, actual.CreatedAt); } }
public void Should_Add_New_Candidate_When_Save() { var fakeContext = new FakeContext("SaveNewCandidate"); fakeContext.FillWith <Candidate>(); fakeContext.FillWith <User>(); fakeContext.FillWith <Company>(); fakeContext.FillWith <Acceleration>(); var fakeCandidate = new Candidate(); fakeCandidate.UserId = 1; fakeCandidate.AccelerationId = 1; fakeCandidate.CompanyId = 2; fakeCandidate.Status = 1; fakeCandidate.CreatedAt = DateTime.Today; using (var context = new CodenationContext(fakeContext.FakeOptions)) { var service = new CandidateService(context); var actual = service.Save(fakeCandidate); Assert.Equal(fakeCandidate, actual, new CandidateIdComparer()); Assert.Equal(fakeCandidate.Status, actual.Status); Assert.Equal(fakeCandidate.CreatedAt, actual.CreatedAt); } }
public void SaveTeste_When_Update_Id_Not_Exist() { var fakeContext = new FakeContext("UpdateUser"); fakeContext.FillWith <User>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = new User(); expected.Id = 999; expected.FullName = "full name"; expected.Email = "email"; expected.Nickname = "nickname"; expected.Password = "******"; expected.CreatedAt = DateTime.Today; var service = new UserService(context); var actual = service.Save(expected); Assert.NotEqual(0, actual.Id); Assert.Equal(expected.FullName, actual.FullName); Assert.Equal(expected.Email, actual.Email); Assert.Equal(expected.Nickname, actual.Nickname); Assert.Equal(expected.Password, actual.Password); Assert.Equal(expected.CreatedAt, actual.CreatedAt); } }
public void Should_Be_Right_Users_When_Find_By_Accelaration_Name(string accelerationName) { var fakeContext = new FakeContext("UserByAcceleration"); fakeContext.FillWithAll(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData <Acceleration>(). Where(acceleration => acceleration.Name == accelerationName). Join(fakeContext.GetFakeData <Candidate>(), acceleration => acceleration.Id, candidate => candidate.AccelerationId, (acceleration, candidate) => candidate). Join(fakeContext.GetFakeData <User>(), candidate => candidate.UserId, user => user.Id, (candidate, user) => user). Distinct(). ToList(); var service = new UserService(context); var actual = service.FindByAccelerationName(accelerationName); Assert.Equal(expected, actual, new UserIdComparer()); } }
public void Should_Add_New_User_When_Save() { var fakeContext = new FakeContext("SaveNewUser"); var fakeUser = new User(); fakeUser.FullName = "full name"; fakeUser.Email = "email"; fakeUser.Nickname = "nickname"; fakeUser.Password = "******"; fakeUser.CreatedAt = DateTime.Today; using (var context = new CodenationContext(fakeContext.FakeOptions)) { var service = new UserService(context); var actual = service.Save(fakeUser); Assert.NotEqual(0, actual.Id); Assert.Equal(fakeUser.FullName, actual.FullName); Assert.Equal(fakeUser.Email, actual.Email); Assert.Equal(fakeUser.Nickname, actual.Nickname); Assert.Equal(fakeUser.Password, actual.Password); Assert.Equal(fakeUser.CreatedAt, actual.CreatedAt); } }
public void Should_Be_Right_Companies_When_Find_By_Accelaration_Id(int accelerationId) { var fakeContext = new FakeContext("CompanyByAcceleration"); fakeContext.FillWithAll(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData <Acceleration>(). Where(acceleration => acceleration.Id == accelerationId). Join(fakeContext.GetFakeData <Candidate>(), acceleration => acceleration.Id, candidate => candidate.AccelerationId, (acceleration, candidate) => candidate). Join(fakeContext.GetFakeData <Company>(), candidate => candidate.CompanyId, company => company.Id, (candidate, company) => company). Distinct(). ToList(); var service = new CompanyService(context); var actual = service.FindByAccelerationId(accelerationId); Assert.Equal(expected, actual, new CompanyIdComparer()); } }
public void Should_Be_Right_Users_When_Find_By_Company_Id(int companyId) { var fakeContext = new FakeContext("UserByCompany"); fakeContext.FillWithAll(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData <Company>(). Where(company => company.Id == companyId). Join(fakeContext.GetFakeData <Candidate>(), company => company.Id, candidate => candidate.CompanyId, (company, candidate) => candidate). Join(fakeContext.GetFakeData <User>(), candidate => candidate.UserId, user => user.Id, (candidate, user) => user). Distinct(). ToList(); var service = new UserService(context); var actual = service.FindByCompanyId(companyId); Assert.Equal(expected, actual, new UserIdComparer()); } }
public void Should_Add_New_Acceleration_When_Save() { var fakeContext = new FakeContext("SaveNewAcceleration"); fakeContext.FillWith <Models.Challenge>(); var fakeAcceleration = new Acceleration(); fakeAcceleration.Name = "name"; fakeAcceleration.Slug = "slug"; fakeAcceleration.ChallengeId = 1; fakeAcceleration.CreatedAt = DateTime.Today; using (var context = new CodenationContext(fakeContext.FakeOptions)) { var service = new AccelerationService(context); var actual = service.Save(fakeAcceleration); Assert.NotEqual(0, actual.Id); Assert.Equal(fakeAcceleration.Name, actual.Name); Assert.Equal(fakeAcceleration.Slug, actual.Slug); Assert.Equal(fakeAcceleration.ChallengeId, actual.ChallengeId); Assert.Equal(fakeAcceleration.CreatedAt, actual.CreatedAt); } }
public void SaveTeste_When_Update() { var fakeContext = new FakeContext("UpdateAcceleration"); int idAccelerationUpdate = 1; fakeContext.FillWith <Acceleration>(); fakeContext.FillWith <Models.Challenge>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData <Acceleration>().Find(x => x.Id == idAccelerationUpdate); expected.Name = "name"; expected.Slug = "slug"; expected.ChallengeId = 1; expected.CreatedAt = DateTime.Today; var service = new AccelerationService(context); var actual = service.Save(expected); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.Slug, actual.Slug); Assert.Equal(expected.ChallengeId, actual.ChallengeId); Assert.Equal(expected.CreatedAt, actual.CreatedAt); } }
public void SaveTeste_When_Update_Id_Not_Exist() { var fakeContext = new FakeContext("UpdateAccelerationNotExists"); fakeContext.FillWith <Acceleration>(); fakeContext.FillWith <Models.Challenge>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = new Acceleration(); expected.Id = -1; expected.Name = "name"; expected.Slug = "slug"; expected.ChallengeId = 1; expected.CreatedAt = DateTime.Today; var service = new AccelerationService(context); var actual = service.Save(expected); Assert.NotEqual(0, actual.Id); Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.Slug, actual.Slug); Assert.Equal(expected.ChallengeId, actual.ChallengeId); Assert.Equal(expected.CreatedAt, actual.CreatedAt); } }
public void FindByCompanyIdTest_Return_Right(int companyId, params int[] idAccelerationExpected) { var fakeContext = new FakeContext("AccelerationFindByCompanyId"); fakeContext.FillWith <Candidate>(); fakeContext.FillWith <Acceleration>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { List <Acceleration> expected = new List <Acceleration>(); foreach (var id in idAccelerationExpected) { var expectedData = fakeContext.GetFakeData <Acceleration>().Find(x => x.Id == id); if (!(expectedData is null)) { expected.Add(fakeContext.GetFakeData <Acceleration>().Find(x => x.Id == id)); } } var service = new AccelerationService(context); var actual = service.FindByCompanyId(companyId); Assert.Equal(expected, actual, new AccelerationIdComparer()); } }
public void FindByCompanyIdTest_Return_Right(int companyId, params string[] idCandidatesExpected) { var fakeContext = new FakeContext("Candidate_FindByCompanyId"); fakeContext.FillWith <Candidate>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { List <Candidate> expected = new List <Candidate>(); foreach (var idCandidate in idCandidatesExpected) { var idCandidateInt = idCandidate.Split(',').Select(x => int.Parse(x)).ToList(); expected.Add(fakeContext .GetFakeData <Candidate>() .Find(x => x.UserId == idCandidateInt[0] && x.AccelerationId == idCandidateInt[1] && x.CompanyId == idCandidateInt[2])); } var service = new CandidateService(context); var actual = service.FindByCompanyId(companyId); Assert.Equal(expected, actual, new CandidateIdComparer()); } }
public void SaveTeste_When_Update_Id_Not_Exist(int userId, int accelerationId, int companyId) { var fakeContext = new FakeContext("UpdateCandidateNotExist"); fakeContext.FillWith <Candidate>(); fakeContext.FillWith <User>(); fakeContext.FillWith <Company>(); fakeContext.FillWith <Acceleration>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var fakeCandidate = new Candidate(); fakeCandidate.UserId = userId; fakeCandidate.AccelerationId = accelerationId; fakeCandidate.CompanyId = companyId; fakeCandidate.Status = 1; fakeCandidate.CreatedAt = DateTime.Today; var service = new CandidateService(context); var actual = service.Save(fakeCandidate); Assert.Equal(fakeCandidate, actual, new CandidateIdComparer()); Assert.Equal(fakeCandidate.Status, actual.Status); Assert.Equal(fakeCandidate.CreatedAt, actual.CreatedAt); } }
public void SaveTeste_When_Update(int userId, int accelerationId, int companyId) { var fakeContext = new FakeContext("UpdateCandidate"); fakeContext.FillWith <Candidate>(); fakeContext.FillWith <User>(); fakeContext.FillWith <Company>(); fakeContext.FillWith <Acceleration>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData <Candidate>() .Find(x => x.UserId == userId && x.AccelerationId == accelerationId && x.CompanyId == companyId); expected.UserId = 1; expected.AccelerationId = 1; expected.CompanyId = 3; expected.Status = 1; expected.CreatedAt = DateTime.Today; var service = new CandidateService(context); var actual = service.Save(expected); Assert.Equal(expected, actual); Assert.Equal(expected.Status, actual.Status); Assert.Equal(expected.CreatedAt, actual.CreatedAt); } }
public void Should_Update_The_User_When_Save() { var fakeContext = new FakeContext("SaveUser"); fakeContext.FillWithAll(); var expected = fakeContext.GetFakeData <User>().First(); expected.FullName = "new value"; expected.Email = "new value"; expected.Nickname = "new value"; expected.Password = "******"; using (var context = new CodenationContext(fakeContext.FakeOptions)) { var service = new UserService(context); var actual = service.Save(expected); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.FullName, actual.FullName); Assert.Equal(expected.Nickname, actual.Nickname); Assert.Equal(expected.Email, actual.Email); Assert.Equal(expected.Password, actual.Password); } }
public void SaveTeste_When_Update() { var fakeContext = new FakeContext("UpdateUser"); int idUserUpdate = 1; fakeContext.FillWith <User>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData <User>().Find(x => x.Id == idUserUpdate); expected.FullName = "full name"; expected.Email = "email"; expected.Nickname = "nickname"; expected.Password = "******"; expected.CreatedAt = DateTime.Today; var service = new UserService(context); var actual = service.Save(expected); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.FullName, actual.FullName); Assert.Equal(expected.Email, actual.Email); Assert.Equal(expected.Nickname, actual.Nickname); Assert.Equal(expected.Password, actual.Password); Assert.Equal(expected.CreatedAt, actual.CreatedAt); } }
public SubmissionServiceTest() { _contextoFake = new FakeContext("SubmissionTest"); _contextoFake.FillWithAll(); _contexto = new CodenationContext(_contextoFake.FakeOptions); _submissionService = new SubmissionService(_contexto); }
public ChallengeServiceTest() { _contextoFake = new FakeContext("ChallengeService"); _contextoFake.FillWithAll(); _contexto = new CodenationContext(_contextoFake.FakeOptions); _challengeService = new ChallengeService(_contexto); }
public UserServiceTest() { _contextoFake = new FakeContext("UserTest"); _contextoFake.FillWithAll(); _contexto = new CodenationContext(_contextoFake.FakeOptions); _userService = new UserService(_contexto); }
public CandidateServiceTest() { _contextoFake = new FakeContext("CandidateTest"); _contextoFake.FillWithAll(); _contexto = new CodenationContext(_contextoFake.FakeOptions); _candidateService = new CandidateService(_contexto); }
public CompanyServiceTest() { _contextoFake = new FakeContext("CompanyTest"); _contextoFake.FillWithAll(); _contexto = new CodenationContext(_contextoFake.FakeOptions); _companyService = new CompanyService(_contexto); }
public void FillWith <T>() where T : class { using (var context = new CodenationContext(FakeOptions)) { if (context.Set <T>().Count() == 0) { foreach (T item in GetFakeData <T>()) { context.Set <T>().Add(item); } context.SaveChanges(); } } }
public void FindHigherScoreByChallengeIdTeste_Return_Right(int challengeId, decimal expectedMaxScore) { var fakeContext = new FakeContext("FindHigherScoreByChallengeId"); fakeContext.FillWith<Submission>(); fakeContext.FillWith<Models.Challenge>(); using (var context = new CodenationContext(fakeContext.FakeOptions)) { var service = new SubmissionService(context); var actual = service.FindHigherScoreByChallengeId(challengeId); Assert.Equal(expectedMaxScore, actual); } }
public void Should_Add_New_User_When_Save() { var fakeContext = new FakeContext("SaveNewUser"); var fakeUser = fakeContext.GetFakeData <User>().First(); fakeUser.Id = 0; using (var context = new CodenationContext(fakeContext.FakeOptions)) { var service = new UserService(context); var actual = service.Save(fakeUser); Assert.NotEqual(0, actual.Id); } }
public void Should_Add_New_Company_When_Save() { var fakeContext = new FakeContext("SaveNewCompany"); var fakeCompany = fakeContext.GetFakeData <Company>().First(); fakeCompany.Id = 0; using (var context = new CodenationContext(fakeContext.FakeOptions)) { var service = new CompanyService(context); var actual = service.Save(fakeCompany); Assert.NotEqual(0, actual.Id); } }
public void Should_Return_By_Acceleration_Name(string name, int[] usersIds) { var fakeContext = new FakeContext("UserByAccelerationName"); fakeContext.FillWith <User>(); using (var context = new CodenationContext(new Microsoft.EntityFrameworkCore.DbContextOptions <CodenationContext>())) { var expected = fakeContext.GetFakeData <User>().Where(x => usersIds.Contains(x.Id)).ToList(); var service = new UserService(context); var actual = service.FindByAccelerationName(name); Assert.Equal(expected, actual, new UserIdComparer()); } }
public void Should_Add_New_Acceleration_When_Save() { var fakeContext = new FakeContext("SaveNewAcceleration"); var fakeAcceleration = fakeContext.GetFakeData <Acceleration>().First(); fakeAcceleration.Id = 0; using (var context = new CodenationContext(fakeContext.FakeOptions)) { var service = new AccelerationService(context); var actual = service.Save(fakeAcceleration); Assert.NotEqual(0, actual.Id); } }