コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
//        [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;
            });
        }