public void UserToProduct_Crud_Test() { //Arrange var userToProduct = new UserToProduct { Amount=125, CreatedDate=DateTime.Now, UserId=Guid.NewGuid(), ProductId=Guid.NewGuid() }; //Act var addedItem= _userToProductRepository.Save(userToProduct); //Assert Assert.AreEqual(userToProduct.Amount, addedItem.Amount); Assert.AreEqual(userToProduct.CreatedDate, userToProduct.CreatedDate); Assert.AreEqual(userToProduct.UserId, userToProduct.UserId); Assert.AreEqual(userToProduct.ProductId, userToProduct.ProductId); //Act var item = _userToProductRepository.FindById(addedItem.Id); //Assert Assert.IsNotNull(item); Assert.AreEqual(userToProduct.UserId, item.UserId); Assert.AreEqual(userToProduct.ProductId, item.ProductId); Assert.AreEqual(addedItem.Id, item.Id); //Arrange item.Amount = 250; //Act var updatedItem = _userToProductRepository.Save(item); //Assert Assert.AreEqual(item.Id, updatedItem.Id); Assert.AreEqual(item.Amount, updatedItem.Amount); //Act _userToProductRepository.Remove(item.Id); var removedItem = _userToProductRepository.FindById(item.Id); //Assert Assert.IsNull(removedItem); Assert.AreNotEqual(item.Id, removedItem?.Id); }
public UserToProductDTO GetById(Guid id) { var entity = _userToProductRepository.FindById(id); return(Mapper.Map <UserToProductDTO>(entity)); }