public void GetEnergySourcesPaged_Success_Test() { // Arrange string searchTerm = ""; int pageIndex = 0; int pageSize = 10; // list IList <R_EnergySource> list = new List <R_EnergySource>(); for (int i = 1; i <= pageSize; i++) { list.Add(SampleEnergySource(i)); } // create mock for repository var mock = new Mock <IEnergySourceRepository>(); mock.Setup(s => s.GetEnergySources(Moq.It.IsAny <string>(), Moq.It.IsAny <int>(), Moq.It.IsAny <int>())).Returns(list); // service EnergySourceService energySourceService = new EnergySourceService(); EnergySourceService.Repository = mock.Object; // Act var resultList = energySourceService.GetEnergySources(searchTerm, pageIndex, pageSize); EnergySourceDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.EnergySourceId); Assert.AreEqual(10, resultList.Count); }
public void GetEnergySources_Success_Test() { // Arrange R_EnergySource energySource = SampleEnergySource(1); IList <R_EnergySource> list = new List <R_EnergySource>(); list.Add(energySource); // create mock for repository var mock = new Mock <IEnergySourceRepository>(); mock.Setup(s => s.GetEnergySources()).Returns(list); // service EnergySourceService energySourceService = new EnergySourceService(); EnergySourceService.Repository = mock.Object; // Act var resultList = energySourceService.GetEnergySources(); EnergySourceDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.EnergySourceId); }