public void UpdateSupplier_UpdateExisting() { var existingSupplier = new Supplier {Id = 1}; var updatedSupplier = new Supplier {Id = 1}; Mock<IDataRepositoryFactory> mockDataRepositoryFactory = new Mock<IDataRepositoryFactory>(); mockDataRepositoryFactory.Setup(mock => mock.GetDataRepository<ISupplierRepository>().Update(existingSupplier)).Returns(updatedSupplier); SupplierManager manager = new SupplierManager(mockDataRepositoryFactory.Object); var resultedSupplier = manager.UpdateSupplier(existingSupplier); Assert.AreEqual(updatedSupplier, resultedSupplier); }
public void UpdateSupplier_AddNew() { var newSupplier = new Supplier(); var addedSupplier = new Supplier { Id = 1 }; Mock<IDataRepositoryFactory> mockDataRepositoryFactory = new Mock<IDataRepositoryFactory>(); mockDataRepositoryFactory.Setup(mock => mock.GetDataRepository<ISupplierRepository>().Add(newSupplier)).Returns(addedSupplier); SupplierManager manager = new SupplierManager(mockDataRepositoryFactory.Object); var resultedSupplier = manager.UpdateSupplier(newSupplier); Assert.AreEqual(addedSupplier, resultedSupplier); }
// [PrincipalPermission(SecurityAction.Demand, Role = Security.BomAdminRole)] public Supplier UpdateSupplier(Supplier supplier) { return ExecuteFaultHandledOperation(() => { ISupplierRepository supplierRepository = _dataRepositoryFactory.GetDataRepository<ISupplierRepository>(); Supplier updatedEntity = null; if (supplier.Id == 0) updatedEntity = supplierRepository.Add(supplier); else updatedEntity = supplierRepository.Update(supplier); return updatedEntity; }); }