コード例 #1
0
        public async Task DivisionShouldBeReturned()
        {
            using (var context = await NewParkSharkInMemoryTestContext())
            {
                //Setup test data
                await context.ParkSharkDbContext.Divisions.AddAsync(new Division("Apple", "Apple Computer", "Steve Jobs"));

                await context.ParkSharkDbContext.SaveChangesAsync();

                var steveJobsDivision = context.ParkSharkDbContext.Divisions.FirstOrDefault(d => d.Name == "Apple");

                var divisionService = new DivisionService(context.ParkSharkDbContext);

                var controller = new DivisionsController(context.Mapper, divisionService);
                var division   = GetResult <DivisionDto>((await controller.GetDivision(steveJobsDivision.Id)));

                Assert.AreEqual("Apple", division.Name);
                Assert.AreEqual("Steve Jobs", division.Director);
                Assert.AreEqual("Apple Computer", division.OriginalName);
                Assert.AreEqual(steveJobsDivision.Id, division.Id);
            }
        }
コード例 #2
0
        public async Task DivisionsWithSubDivisionsShouldBeReturned()
        {
            using (var context = await NewParkSharkInMemoryTestContext())
            {
                //Setup test data
                var parentDivision = new Division("Parent", "Parent", "Steve Jobs");
                await context.ParkSharkDbContext.Divisions.AddAsync(parentDivision);

                await context.ParkSharkDbContext.Divisions.AddAsync(new Division("Child1", "Child1", "Steve Jobs", parentDivision.Id));

                await context.ParkSharkDbContext.Divisions.AddAsync(new Division("Child2", "Child2", "Steve Jobs", parentDivision.Id));

                await context.ParkSharkDbContext.SaveChangesAsync();

                var divisionService = new DivisionService(context.ParkSharkDbContext);

                var controller = new DivisionsController(context.Mapper, divisionService);
                var division   = GetResult <DivisionDto>((await controller.GetDivision(parentDivision.Id)));

                Assert.AreEqual(2, division.SubDivisions.Count);
            }
        }