public void Add_DLAddIsInvoked() { Skill skill = new Skill() { SkillName = "C#" }; var mockSkillsRepo = MockRepository.GenerateMock<DL.Interfaces.IRepository<Skill>>(); ISkillsBL skillsBl = new BL.SkillsBL(mockSkillsRepo); skillsBl.Add(skill); mockSkillsRepo.AssertWasCalled(x => x.Add(skill)); }
public void FindAll_DLFindAllIsInvoked_ReturnsValues() { IQueryable<Skill> expectedValue = new List<Skill>().AsQueryable(); var mockSkillsRepo = MockRepository.GenerateMock<DL.Interfaces.IRepository<Skill>>(); mockSkillsRepo.Stub(x => x.FindAll()).Return(expectedValue); ISkillsBL skillBL = new BL.SkillsBL(mockSkillsRepo); IQueryable<Skill> actualValue = skillBL.FindAll(); mockSkillsRepo.AssertWasCalled(m => m.FindAll()); Assert.AreEqual(expectedValue, actualValue); }
private void InitializeDatabase() { string skills = "C#, Python, C++, Ruby, JavaScript, C, PHP, Go, Scala, Perl, Objective C"; using (System.Data.Entity.DbContext skillsDbContext = new DL.DataStore((new ConfigurationReader()).GetConnectionString("DefaultConnection"))) { BL.SkillsBL skillsManager = new BL.SkillsBL(new DL.SkillsRepository(skillsDbContext)); if (skillsManager.FindAll().Count() == 0) { skills.Split(',').ToList().ForEach(s => skillsManager.Add(new BusinessObjects.Skill() { SkillName = s.Trim() })); } } }
public void FindById_DLFindByIdIsInvoked_ReturnsValue() { int id1 = 1; int id2 = 2; Skill skill1 = new Skill { Id = id1, SkillName = "C#" }; Skill skill2 = new Skill { Id = id2, SkillName = "JavaScript" }; Skill expectedValue = skill1; var mockSkillsRepo = MockRepository.GenerateMock<DL.Interfaces.IRepository<Skill>>(); mockSkillsRepo.Stub(x => x.FindById(id1)).Return(skill1); ISkillsBL skillBL = new BL.SkillsBL(mockSkillsRepo); Skill actualValue = skillBL.FindById(id1); mockSkillsRepo.AssertWasCalled(m => m.FindById(id1)); Assert.AreEqual(expectedValue, actualValue); }
public void Find_DLFindIsInvoked_ReturnsValue() { int id1 = 1; int id2 = 2; Skill skill1 = new Skill { Id = id1, SkillName = "C#" }; Skill skill2 = new Skill { Id = id2, SkillName = "JavaScript" }; IQueryable<Skill> skills = new List<Skill>() { skill1, skill2 }.AsQueryable(); IQueryable<Skill> expectedValue = skills.Where(x => x.SkillName == "C#"); Expression<Func<Skill, bool>> queryExpression = (x => x.SkillName == "C#"); var mockSkillsRepo = MockRepository.GenerateMock<DL.Interfaces.IRepository<Skill>>(); mockSkillsRepo.Stub(x => x.Find(queryExpression)).Return(skills.Where(x => x.SkillName == "C#")); ISkillsBL skillBL = new BL.SkillsBL(mockSkillsRepo); IQueryable<Skill> actualValue = skillBL.Find(queryExpression); mockSkillsRepo.AssertWasCalled(m => m.Find(queryExpression)); Assert.AreEqual(expectedValue.Count(), actualValue.Count()); }