public void GetRefoodUsersPaged_Success_Test() { // Arrange string searchTerm = ""; int pageIndex = 0; int pageSize = 10; // list IList <R_RefoodUser> list = new List <R_RefoodUser>(); for (int i = 1; i <= pageSize; i++) { list.Add(SampleRefoodUser(i)); } // create mock for repository var mock = new Mock <IRefoodUserRepository>(); mock.Setup(s => s.GetRefoodUsers(Moq.It.IsAny <string>(), Moq.It.IsAny <int>(), Moq.It.IsAny <int>())).Returns(list); // service RefoodUserService refoodUserService = new RefoodUserService(); RefoodUserService.Repository = mock.Object; // Act var resultList = refoodUserService.GetRefoodUsers(searchTerm, pageIndex, pageSize); RefoodUserDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.RefoodUserId); Assert.AreEqual(10, resultList.Count); }
public void GetRefoodUsers_Success_Test() { // Arrange R_RefoodUser refoodUser = SampleRefoodUser(1); IList <R_RefoodUser> list = new List <R_RefoodUser>(); list.Add(refoodUser); // create mock for repository var mock = new Mock <IRefoodUserRepository>(); mock.Setup(s => s.GetRefoodUsers()).Returns(list); // service RefoodUserService refoodUserService = new RefoodUserService(); RefoodUserService.Repository = mock.Object; // Act var resultList = refoodUserService.GetRefoodUsers(); RefoodUserDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.RefoodUserId); }
public void GetRefoodUserListAdvancedSearch_Success_Test() { // Arrange string username = null; string fullname = null; string email = null; bool? active = null; //int pageIndex = 0; int pageSize = 10; // list IList <R_RefoodUser> list = new List <R_RefoodUser>(); for (int i = 1; i <= pageSize; i++) { list.Add(SampleRefoodUser(i)); } // create mock for repository var mock = new Mock <IRefoodUserRepository>(); mock.Setup(s => s.GetRefoodUserListAdvancedSearch( Moq.It.IsAny <string>() // username , Moq.It.IsAny <string>() // fullname , Moq.It.IsAny <string>() // email , Moq.It.IsAny <bool?>() // active )).Returns(list); // service RefoodUserService refoodUserService = new RefoodUserService(); RefoodUserService.Repository = mock.Object; // Act var resultList = refoodUserService.GetRefoodUserListAdvancedSearch( username , fullname , email , active ); RefoodUserDTO result = resultList.FirstOrDefault(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.RefoodUserId); }
public void DeleteRefoodUserById_Success_Test() { // Arrange int id = 1; // create mock for repository var mock = new Mock <IRefoodUserRepository>(); mock.Setup(s => s.DeleteRefoodUser(Moq.It.IsAny <int>())).Verifiable(); // service RefoodUserService refoodUserService = new RefoodUserService(); RefoodUserService.Repository = mock.Object; // Act refoodUserService.DeleteRefoodUser(id); // Assert Assert.IsTrue(true); }
public void UpdateRefoodUser_Success_Test() { // Arrange RefoodUserDTO dto = SampleRefoodUserDTO(1); // create mock for repository var mock = new Mock <IRefoodUserRepository>(); mock.Setup(s => s.UpdateRefoodUser(Moq.It.IsAny <R_RefoodUser>())).Verifiable(); // service RefoodUserService refoodUserService = new RefoodUserService(); RefoodUserService.Repository = mock.Object; // Act refoodUserService.UpdateRefoodUser(dto); // Assert Assert.IsNotNull(dto); }
public void AddRefoodUser_Success_Test() { // Arrange RefoodUserDTO dto = SampleRefoodUserDTO(1); // create mock for repository var mock = new Mock <IRefoodUserRepository>(); mock.Setup(s => s.AddRefoodUser(Moq.It.IsAny <R_RefoodUser>())).Returns(1); // service RefoodUserService refoodUserService = new RefoodUserService(); RefoodUserService.Repository = mock.Object; // Act int id = refoodUserService.AddRefoodUser(dto); // Assert Assert.AreEqual(1, id); Assert.AreEqual(1, dto.RefoodUserId); }
public void GetRefoodUser_Success_Test() { // Arrange int id = 1; R_RefoodUser refoodUser = SampleRefoodUser(id); // create mock for repository var mock = new Mock <IRefoodUserRepository>(); mock.Setup(s => s.GetRefoodUser(Moq.It.IsAny <int>())).Returns(refoodUser); // service RefoodUserService refoodUserService = new RefoodUserService(); RefoodUserService.Repository = mock.Object; // Act RefoodUserDTO result = refoodUserService.GetRefoodUser(id); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.RefoodUserId); }