Пример #1
0
        public async void PostEditNegativeId()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(-1, new Breed(-1, string.Empty));

                CheckMessage(result, $"The Breed ID must be between 1 and {int.MaxValue}.");
            }
        }
Пример #2
0
        public async void PostEditNotFound()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(50, new Breed(50, "Test Breed 6 Modified"));

                CheckMessage(result, "The selected Breed could not be found.");
            }
        }
Пример #3
0
        public async void PostEditNoName()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(1, new Breed(1, string.Empty));

                CheckMessage(result, "A Breed must have a name.");
            }
        }
Пример #4
0
        public async void PostEditMismatchedIds()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(7, new Breed(6));

                CheckMessage(result, "The Breed ID provided doesn't match the Breed being updated.");
            }
        }
Пример #5
0
        public async void PostEditParentBreedNegative()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(1, new Breed { Id = 1, Name = "Test Breed with Negative Parent Breed", BreedId = -1 });

                CheckMessage(result, $"The Parent Breed ID cannot be negative or greater than {int.MaxValue}.");
            }
        }
Пример #6
0
        public async void PostEditParentSetAsOwnParent()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(1, new Breed { Id = 1, Name = "Test Breed with Null Parent Breed", BreedId = 1 });

                CheckMessage(result, "A breed cannot be set as it's own Parent Breed.");
            }
        }
Пример #7
0
        public async void GetEditZeroId()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(0);

                CheckMessage(result, $"The Breed ID must be between 1 and {int.MaxValue}.");
            }
        }
Пример #8
0
        public async void GetEditNullId()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(null);

                CheckMessage(result, "The Breed ID provided was invalid.");
            }
        }
Пример #9
0
        public async void PostEditParentBreedDoesntExist()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(1, new Breed { Id = 1, Name = "Test Breed with Invalid Parent Breed", BreedId = 500 });

                BreedViewModel viewModel = CheckViewModel(result);

                CheckMessage(result, "The parent Breed selected could not be found.");
            }
        }
Пример #10
0
        public async void GetEditFound()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(2);

                BreedViewModel viewModel = CheckViewModel(result);
                Breed          breed     = database.Context.Breeds.SingleOrDefault(b => b.Id == 2);

                Assert.Equal(2, viewModel.Breed.Id);
                Assert.Equal(breed.Name, viewModel.Breed.Name);
            }
        }
Пример #11
0
        public async void PostEditParentBreedZero()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(1, new Breed { Id = 1, Name = "Test Modified Breed with Zero Parent Breed", BreedId = 0 });

                RedirectToActionResult redirect = Assert.IsType <RedirectToActionResult>(result);

                Assert.Equal("Index", redirect.ActionName);

                Breed breed = database.Context.Breeds.SingleOrDefault(b => b.Name == "Test Modified Breed with Zero Parent Breed");

                Assert.Equal(1, breed.Id);
            }
        }
Пример #12
0
        public async void PostEditParentBreedNull()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(10, new Breed { Id = 10, Name = "Test Breed with Null Parent Breed", BreedId = null });

                RedirectToActionResult redirect = Assert.IsType <RedirectToActionResult>(result);

                Assert.Equal("Index", redirect.ActionName);

                Breed breed = database.Context.Breeds.SingleOrDefault(b => b.Id == 10);

                Assert.Equal("Test Breed with Null Parent Breed", breed.Name);
            }
        }
Пример #13
0
        public async void PostEditSuccess()
        {
            using (var database = new TestDb())
            {
                var controller = new BreedsController(database.Context);

                IActionResult result = await controller.Edit(6, new Breed(6, "Modified Breed"));

                RedirectToActionResult redirect = Assert.IsType <RedirectToActionResult>(result);

                Assert.Equal("Index", redirect.ActionName);

                Breed breed = database.Context.Breeds.SingleOrDefault(b => b.Id == 6);

                Assert.Equal("Modified Breed", breed.Name);
            }
        }