示例#1
0
        public void ActiveBrother_IsInListOfActiveBrothers()
        {
            int id = _dbContext.Brother.Add(new Brother {
                FirstName = "First", LastName = "Last", ExpectedGraduation = DateTime.MaxValue
            }).Entity.Id;

            _dbContext.SaveChanges();

            BrotherController             controller = new BrotherController(_dbContext, null, null);
            ContentModel <MinimalBrother> result     =
                (controller.GetBrothers() as OkObjectResult)?.Value as ContentModel <MinimalBrother>;

            Assert.Multiple(() => {
                Assert.That(result, Is.Not.Null);
                Assert.That(result.Content.Count(), Is.EqualTo(1));
                Assert.That(result.Content.Any(b => b.Id == id));
            });
        }
示例#2
0
        public void GraduatedBrothers_AreNotReturnedFromList()
        {
            _dbContext.Brother.Add(new Brother {
                FirstName = "First", LastName = "Last", ExpectedGraduation = new DateTime(1900, 1, 1)
            });
            _dbContext.SaveChanges();

            BrotherController controller = new BrotherController(_dbContext, null, null);

            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(0));
            });
        }
示例#3
0
        public void GetBrothers_NoExpectedGraduation_Excluded()
        {
            int id = _dbContext.Brother.Add(new Brother {
                FirstName = "First", LastName = "Last"
            }).Entity.Id;

            _dbContext.SaveChanges();

            BrotherController controller = new BrotherController(_dbContext, null, null);

            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(0));
            });
        }
示例#4
0
        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));
                }
            });
        }