public static RefoodUserDTO SampleRefoodUserDTO(int id = 1) { RefoodUserDTO refoodUser = new RefoodUserDTO(); // int refoodUser.RefoodUserId = id; // string refoodUser.Username = "******"; // string refoodUser.Fullname = "FullnameTestValue"; // string refoodUser.Email = "EmailTestValue"; // bool refoodUser.Active = false; // bool refoodUser.IsDeleted = false; // int? refoodUser.CreateBy = 1; // System.DateTime? refoodUser.CreateOn = new System.DateTime(); // int? refoodUser.UpdateBy = 1; // System.DateTime? refoodUser.UpdateOn = new System.DateTime(); return(refoodUser); }
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 RefoodUserDTO GetRefoodUser(int refoodUserId) { try { //Requires.NotNegative("refoodUserId", refoodUserId); log.Debug("refoodUserId: " + refoodUserId + " "); // get R_RefoodUser t = Repository.GetRefoodUser(refoodUserId); RefoodUserDTO dto = new RefoodUserDTO(t); log.Debug(RefoodUserDTO.FormatRefoodUserDTO(dto)); return(dto); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
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 int AddRefoodUser(RefoodUserDTO dto) { int id = 0; try { log.Debug(RefoodUserDTO.FormatRefoodUserDTO(dto)); R_RefoodUser t = RefoodUserDTO.ConvertDTOtoEntity(dto); // add id = Repository.AddRefoodUser(t); dto.RefoodUserId = id; log.Debug("result: 'success', id: " + id); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } return(id); }
public RefoodUserViewModel(RefoodUserDTO t) { RefoodUserId = t.RefoodUserId; Username = t.Username; Fullname = t.Fullname; Email = t.Email; Active = t.Active; IsDeleted = t.IsDeleted; CreateBy = t.CreateBy; CreateOn = t.CreateOn; UpdateBy = t.UpdateBy; UpdateOn = t.UpdateOn; }
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); }
private RefoodUserDTO Update(RefoodUserViewModel viewModel) { try { log.Debug(RefoodUserViewModel.FormatRefoodUserViewModel(viewModel)); // get log.Debug("_refoodUserService.GetRefoodUser - refoodUserId: " + viewModel.RefoodUserId + " "); var existingRefoodUser = _refoodUserService.GetRefoodUser(viewModel.RefoodUserId); log.Debug("_refoodUserService.GetRefoodUser - " + RefoodUserDTO.FormatRefoodUserDTO(existingRefoodUser)); if (existingRefoodUser != null) { // copy values existingRefoodUser.Username = viewModel.Username; existingRefoodUser.Fullname = viewModel.Fullname; existingRefoodUser.Email = viewModel.Email; existingRefoodUser.Active = viewModel.Active; existingRefoodUser.IsDeleted = viewModel.IsDeleted; // audit //existingRefoodUser.UpdateBy = UserInfo.UserID; existingRefoodUser.UpdateOn = DateTime.UtcNow; // update log.Debug("_refoodUserService.UpdateRefoodUser - " + RefoodUserDTO.FormatRefoodUserDTO(existingRefoodUser)); _refoodUserService.UpdateRefoodUser(existingRefoodUser); log.Debug("result: 'success'"); } else { log.Error("existingRefoodUser: null, RefoodUserId: " + viewModel.RefoodUserId); } return(existingRefoodUser); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
public RefoodUserDTO UpdateDTO(RefoodUserDTO dto, int?updateBy) { if (dto != null) { dto.RefoodUserId = this.RefoodUserId; dto.Username = this.Username; dto.Fullname = this.Fullname; dto.Email = this.Email; dto.Active = this.Active; dto.IsDeleted = this.IsDeleted; dto.UpdateBy = updateBy; dto.UpdateOn = System.DateTime.UtcNow; } return(dto); }
private RefoodUserDTO Create(RefoodUserViewModel viewModel) { try { log.Debug(RefoodUserViewModel.FormatRefoodUserViewModel(viewModel)); RefoodUserDTO refoodUser = new RefoodUserDTO(); // copy values refoodUser.RefoodUserId = viewModel.RefoodUserId; refoodUser.Username = viewModel.Username; refoodUser.Fullname = viewModel.Fullname; refoodUser.Email = viewModel.Email; refoodUser.Active = viewModel.Active; refoodUser.IsDeleted = viewModel.IsDeleted; // audit //refoodUser.CreateBy = UserInfo.UserID; //refoodUser.UpdateBy = UserInfo.UserID; refoodUser.CreateOn = DateTime.UtcNow; refoodUser.UpdateOn = DateTime.UtcNow; // add log.Debug("_refoodUserService.AddRefoodUser - " + RefoodUserDTO.FormatRefoodUserDTO(refoodUser)); int id = _refoodUserService.AddRefoodUser(refoodUser); refoodUser.RefoodUserId = id; log.Debug("result: 'success', id: " + id); return(refoodUser); } catch (Exception e) { // error log.Error(e.ToString()); throw; } }
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 DeleteRefoodUser(RefoodUserDTO dto) { try { log.Debug(RefoodUserDTO.FormatRefoodUserDTO(dto)); R_RefoodUser t = RefoodUserDTO.ConvertDTOtoEntity(dto); // delete Repository.DeleteRefoodUser(t); dto.IsDeleted = t.IsDeleted; log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
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); }
public void UpdateRefoodUser(RefoodUserDTO dto) { try { //Requires.NotNull(t); //Requires.PropertyNotNegative(t, "RefoodUserId"); log.Debug(RefoodUserDTO.FormatRefoodUserDTO(dto)); R_RefoodUser t = RefoodUserDTO.ConvertDTOtoEntity(dto); // update Repository.UpdateRefoodUser(t); log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }