public string SearchQueryForExistingBrother_ReturnsExpectedResult(string query) { SearchController controller = new SearchController(_dbContext); OkObjectResult result = controller.Search(query) as OkObjectResult; ContentModel <MinimalBrother> brothers = result?.Value as ContentModel <MinimalBrother>; Assert.Multiple(() => { Assert.That(result, Is.Not.Null); Assert.That(brothers, Is.Not.Null); Assert.That(brothers.Content.Count(), Is.GreaterThan(0)); }); MinimalBrother brother = brothers?.Content?.FirstOrDefault(); return($"{brother?.FirstName} {brother?.LastName}"); }
public async Task ActiveBrothers_AreInCorrectOrder() { await _dbContext.Database.EnsureDeletedAsync(); _dbContext.SaveChanges(); DateTime sameDate = DateTime.Now; List <Brother> brotherList = new List <Brother> { // Should be 1 (Zeta number) new Brother { FirstName = "FName", LastName = "LName", ExpectedGraduation = DateTime.MaxValue, ZetaNumber = 1 }, // Should be 2 (Zeta number) new Brother { FirstName = "FName1", LastName = "LName1", ExpectedGraduation = DateTime.MaxValue, ZetaNumber = 2 }, // Should be 3 (Join date) new Brother { FirstName = "FName2", LastName = "LName2", ExpectedGraduation = DateTime.MaxValue, DateJoined = sameDate.AddDays(-5) }, // Should be 4 (Join date) new Brother { FirstName = "FName3", LastName = "LName3", ExpectedGraduation = DateTime.MaxValue, DateJoined = sameDate.AddDays(-3) }, // Should be 5 (Last name) new Brother { FirstName = "ZFirst", LastName = "ALast", ExpectedGraduation = DateTime.MaxValue, DateJoined = sameDate }, // Should be 6 (First name) new Brother { FirstName = "AFirst", LastName = "ZLast", ExpectedGraduation = DateTime.MaxValue, DateJoined = sameDate }, // Should be 7 (First name) new Brother { FirstName = "ZFirst", LastName = "ZLast", ExpectedGraduation = DateTime.MaxValue, DateJoined = sameDate } }; DirectoryContext dbContext = new DirectoryContext(new DbContextOptionsBuilder <DirectoryContext>() .UseInMemoryDatabase("directory") .Options); await dbContext.Brother.AddRangeAsync(brotherList); await dbContext.SaveChangesAsync(); BrotherController controller = new BrotherController(dbContext, new ClaimsPrincipal(), Mock.Of <ILogger <BrotherController> >()); Assert.Multiple(() => { OkObjectResult result = controller.GetBrothers() as OkObjectResult; Assert.That(result, Is.Not.Null); IEnumerable <MinimalBrother> brothers = (result.Value as ContentModel <MinimalBrother>)?.Content; Assert.That(brothers, Is.Not.Null); Assert.That(brothers.Count(), Is.EqualTo(7)); for (int i = 0; i < brotherList.Count; i++) { MinimalBrother actual = brothers.ElementAt(i); Brother expected = brotherList[i]; Assert.That(actual.LastName, Is.EqualTo(expected.LastName)); Assert.That(actual.FirstName, Is.EqualTo(expected.FirstName)); Assert.That(actual.ZetaNumber, Is.EqualTo(expected.ZetaNumber)); Assert.That(actual.DateJoined, Is.EqualTo(expected.DateJoined)); } }); }