public void GetContractorByName() { Mock<IContractorRepository> mock = new Mock<IContractorRepository>(); mock.Setup(a => a.Contractors).Returns(new Contractor[] { new Contractor { id = 1, name = "Firma1" }, new Contractor { id = 2, name = "Firma2" }, new Contractor { id = 3, name = "Firma3" }, new Contractor { id = 4, name = "Firma4" }, new Contractor { id = 5, name = "Firma5" }, new Contractor { id = 6, name = "Firma6" }, new Contractor { id = 7, name = "Firma4" } }.AsQueryable()); ContractorController ctrl = new ContractorController(mock.Object); Object [] temp = ctrl.GetContractorsByName("Firma4"); Assert.AreEqual(temp.Length, 2); Assert.AreEqual(((Contractor)temp[1]).name, "Firma4"); temp = ctrl.GetContractorsByName("Firma2"); Assert.AreEqual(temp.Length, 1); Assert.AreEqual(((Contractor)temp[0]).name, "Firma2"); temp = ctrl.GetContractorsByName("Firma8"); Assert.AreEqual(temp.Length, 0); }