public void DisplayListWithNewestTestOnly() { //Arrange City city = new City { CityName = "Vilnius" }; _context.Cities.Add(city); var firstTest = new PRIS.WEB.Models.Test { City = city, DateOfTest = DateTime.Today }; var secondTest = new PRIS.WEB.Models.Test { City = city, DateOfTest = DateTime.Today.AddDays(1) }; _context.AddRange(firstTest, secondTest); Candidate candidateFirst = new Candidate { CandidateID = 1, FirstName = "Foo", LastName = "Bar", PhoneNumber = 11111111, Test = firstTest }; Candidate candidateSecond = new Candidate { CandidateID = 2, FirstName = "Foo", LastName = "Bar", PhoneNumber = 11111111, Test = secondTest }; _context.AddRange(candidateFirst, candidateSecond); _context.SaveChanges(); //Act IActionResult result = _sut.List("Vilnius"); ViewResult viewResult = Assert.IsType <ViewResult>(result); List <ListCandidateViewModel> test = viewResult.ViewData.Model as List <ListCandidateViewModel>; Assert.Equal(candidateSecond.CandidateID, test[0].CandidateID); }
private void CreateValidCandidate(ApplicationDbContext _context) { City city = new City { CityName = "Kaunas" }; City cityKaunas = new City { CityName = "Vilnius" }; _context.Cities.AddRange(city, cityKaunas); var firstTest = new PRIS.WEB.Models.Test { City = city, DateOfTest = DateTime.Today }; var secondTest = new PRIS.WEB.Models.Test { City = cityKaunas, DateOfTest = DateTime.Today }; Candidate candidateFirst = new Candidate { CandidateID = 1, FirstName = "Foo", LastName = "Bar", PhoneNumber = 11111111, Test = firstTest }; Candidate candidateSecond = new Candidate { CandidateID = 2, FirstName = "Foo", LastName = "Bar", PhoneNumber = 11111111, Test = secondTest }; _context.AddRange(candidateFirst, candidateSecond); _context.SaveChanges(); }