public void Initialize()
		{
			this.service = new Mock<ILeagueService>();
			this.controller = new CoachesController(service.Object);
			this.request = new HttpRequestMessage();
			request.SetConfiguration(new System.Web.Http.HttpConfiguration());
			Mapper.Initialize(x =>
			{
				x.AddProfile<DomainToViewModelMappingProfile>();
			});
		}
Пример #2
0
        public async void EditCoachNotFoundPageTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new CoachesController(db);

            //Act
            var r = await c.Edit(2);


            //Assert
            Assert.IsType <NotFoundResult>(r);
        }
Пример #3
0
        public async void DetailsNullPageTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new CoachesController(db);

            //Act
            var r = await c.Details(null);


            //Assert
            Assert.IsType <NotFoundResult>(r);
        }
Пример #4
0
        public async void IndexTest()
        {
            //Arrange
            var dbContext        = MockDb.CreateMockDb();
            CoachesController sc = new CoachesController(dbContext);
            //Act
            var r = await sc.Index();

            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <List <Coaches> >(result.ViewData.Model);

            Assert.Equal(1, model.Count());
        }
Пример #5
0
        public async void EditWrongIdTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new CoachesController(db);

            var coach = new Coaches {
                Coaches_Id = 2, FirstName = "Edwin", LastName = "Mar", Title = "Head", Team_Id = 2
            };
            //Act
            await c.Create(coach);

            var r = await c.Edit(db.Coaches.Find(1).Coaches_Id, coach);

            //Assert
            Assert.IsType <NotFoundResult>(r);
        }
Пример #6
0
        public async void CreateButtonTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new CoachesController(db);

            var coach = new Coaches {
                Coaches_Id = 2, FirstName = "Edwin", LastName = "Mar", Title = "Head", Team_Id = 2
            };

            //Act
            await c.Create(coach);

            var r = c.Create();

            //Assert
            Assert.IsType <ViewResult>(r);
        }
Пример #7
0
        public async void TestAddCoach()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new CoachesController(db);


            var coach = new Coaches {
                Coaches_Id = 2, FirstName = "Mike", LastName = "Mar", Title = "Head", Team_Id = 2
            };
            //Act
            var r = await c.Create(coach);

            //Assert
            var result = Assert.IsType <RedirectToActionResult>(r);

            Assert.Equal("Index", result.ActionName);
            Assert.Equal(1, db.Coaches.Where(x => x.Coaches_Id == coach.Coaches_Id && x.FirstName == coach.FirstName && x.LastName == coach.LastName && x.Title == coach.Title && x.Team_Id == coach.Team_Id).Count());
        }
Пример #8
0
        public async void DeleteConfirmTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new CoachesController(db);

            var coach = new Coaches {
                Coaches_Id = 2, LastName = "Mar", Title = "Head", Team_Id = 2
            };
            //Act
            var r = await c.Create(coach);

            //Finds the second element stores in a tmp variable
            var elementToDelete = db.Coaches.Find(2);

            await c.DeleteConfirmed(elementToDelete.Coaches_Id);

            Assert.DoesNotContain(elementToDelete, db.Coaches);
        }
Пример #9
0
        public void CreateMethodTest()
        {
            var options = new DbContextOptionsBuilder <MContext>()
                          .UseInMemoryDatabase(databaseName: "DB")
                          .Options;
            var controller = new CoachesController(new MContext(options));

            using (var context = new MContext(options))
            {
                context.Coaches.Add(new Coach());
                context.SaveChanges();
            }

            using (var context = new MContext(options))
            {
                var result = controller.Create(new Coach());
                Assert.AreEqual(true, result.IsCompletedSuccessfully);
            }
        }
Пример #10
0
        public async void EditTest()
        {
            //Arrange
            var    db       = MockDb.CreateMockDb();
            var    c        = new CoachesController(db);
            string tempName = "Micheal";

            var coach = new Coaches {
                Coaches_Id = 2, FirstName = "Edwin", LastName = "Mar", Title = "Head", Team_Id = 2
            };
            //Act
            await c.Create(coach);

            coach.FirstName = tempName;
            var r = await c.Edit(db.Coaches.Find(2).Coaches_Id, coach);

            //Assert
            Assert.IsType <RedirectToActionResult>(r);
            Assert.Equal(db.Coaches.Find(2).FirstName, tempName);
        }
Пример #11
0
        public async void DeletePageTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new CoachesController(db);

            var coach = new Coaches {
                Coaches_Id = 2, LastName = "Mar", Title = "Head", Team_Id = 2
            };
            //Act
            await c.Create(coach);

            var r = await c.Delete(db.Coaches.Find(2).Coaches_Id);


            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <Coaches>(result.ViewData.Model);

            Assert.Equal(db.Coaches.Find(2).Coaches_Id, model.Coaches_Id);
            Assert.Equal(db.Coaches.Find(2).FirstName + db.Coaches.Find(2).LastName, model.FirstName + model.LastName);
        }
Пример #12
0
        public async void TestAddInvalidCoach()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new CoachesController(db);


            var coach = new Coaches {
                Coaches_Id = 2, LastName = "Mar", Title = "Head", Team_Id = 2
            };

            c.ModelState.AddModelError("FirstName", "Required");
            //Act
            var r = await c.Create(coach);

            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <Coaches>(result.ViewData.Model);

            Assert.Equal(coach, model);
            Assert.IsType <SelectList>(result.ViewData["Team_Id"]);
        }
Пример #13
0
        public async void EditModelStateNotValidTest()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new CoachesController(db);

            var coach = new Coaches {
                Coaches_Id = 2, LastName = "Mar", Title = "Head", Team_Id = 2
            };


            //Act
            await c.Create(coach);

            c.ModelState.AddModelError("FirstName", "Required");

            var r = await c.Edit(db.Coaches.Find(2).Coaches_Id, coach);

            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <Coaches>(result.ViewData.Model);

            Assert.Equal(coach, model);
        }