public void Init() { var unitOfWork = new Mock<IUnitOfWork>(); var receive = new List<Receive>() { new Receive() { ReceiveID = Guid.NewGuid(), PartitionID = 0, GRN = "001", CommodityTypeID = 1, SourceDonorID = 1, ResponsibleDonorID = 1, TransporterID = 1, PlateNo_Prime = "00001", PlateNo_Trailer = "00002", DriverName = "Dawit", WeightBridgeTicketNumber = "012", WeightBeforeUnloading = 1200, WeightAfterUnloading = 0, ReceiptDate = DateTime.Today, UserProfileID = 1, CreatedDate = DateTime.Today, WayBillNo = "001", CommoditySourceID = 1, Remark = "this a a test receive", VesselName = "002", ReceivedByStoreMan = "Abebe", PortName = "Dire Dawa", PurchaseOrder = "002", SupplierName = "WFP", ReceiptAllocationID = Guid.NewGuid(), CommoditySource = new CommoditySource() { CommoditySourceID = 1, Name = "Donatiion" }, CommodityType = new CommodityType() { CommodityTypeID = 1, Name = "FOOD" }, Hub = new Models.Hubs.Hub() { HubID = 1, Name = "Kombelcha" }, ReceiveDetails = new Collection<ReceiveDetail>() { new ReceiveDetail() { ReceiveDetailID = Guid.NewGuid(), PartitionID = 0, ReceiveID = Guid.NewGuid(), //should be given the TransactionGroupID = null, CommodityID = 1, SentQuantityInUnit = 1200, UnitID = 1, SentQuantityInMT = 1200, Description = "this is a test", Commodity = new Commodity() { CommodityID = 1, Name = "Pulse" }, Unit = new Unit() { UnitID = 1, Name = "kg" } } } } }; var reieveRepository = new Mock<IGenericRepository<Receive>>(); reieveRepository.Setup( t => t.Get(It.IsAny<Expression<Func<Receive, bool>>>(), It.IsAny<Func<IQueryable<Receive>, IOrderedQueryable<Receive>>>(), It.IsAny<string>())).Returns(receive); var commodity = new List<Commodity>() { new Commodity() { CommodityID = 1, Name = "Pulse" }, new Commodity() { CommodityID = 2, Name = "Cereal" } }; var CommodityRepository = new Mock<IGenericRepository<Commodity>>(); CommodityRepository.Setup(t => t.FindById(It.IsAny<int>())).Returns( (int id) => commodity.FirstOrDefault(t => t.CommodityID == id)); var commodityType = new List<CommodityType>() { new CommodityType() { CommodityTypeID = 1, Name = "Food" }, new CommodityType() { CommodityTypeID = 2, Name = "Non-Food" } }; var commodityTypeRepository =new Mock<IGenericRepository<CommodityType>>(); commodityTypeRepository.Setup(t => t.FindById(It.IsAny<int>())).Returns((int id) => commodityType. FirstOrDefault(t => t.CommodityTypeID == id)); commodityTypeRepository.Setup(t => t.Get(It.IsAny<Expression<Func<CommodityType, bool>>>(), It.IsAny<Func<IQueryable<CommodityType>, IOrderedQueryable<CommodityType>>>(), It.IsAny<string>())).Returns(commodityType); var shippingInstructioncodes = new List<ShippingInstruction>() { new ShippingInstruction() { ShippingInstructionID = 1, Value = "si-0002", }, new ShippingInstruction() { ShippingInstructionID = 2, Value = "si-003", } }; Mock<IShippingInstructionService> MockShippingInstructionService = new Mock<IShippingInstructionService>(); MockShippingInstructionService.Setup(s => s.GetSINumberIdWithCreate("si-0002")).Returns(shippingInstructioncodes.FirstOrDefault()); var shippingInstructionRepository = new Mock<IGenericRepository<ShippingInstruction>>(); shippingInstructionRepository.Setup( t => t.Get(It.IsAny<Expression<Func<ShippingInstruction, bool>>>(), It.IsAny<Func<IQueryable<ShippingInstruction>, IOrderedQueryable<ShippingInstruction>>>(), It.IsAny<string>())).Returns(shippingInstructioncodes); var account = new List<Account>() { new Account() { AccountID = 1, EntityID = 1, EntityType = "Sample Entity" } }; var accountRepository = new Mock<IGenericRepository<Account>>(); var MockAccountService = new Mock<IAccountService>(); MockAccountService.Setup(a => a.GetAccountIdWithCreate("Sample Entity", 1)).Returns(1); var projectCodes = new List<ProjectCode>() { new ProjectCode() { ProjectCodeID = 1, Value = "pro-001" }, new ProjectCode() { ProjectCodeID = 1, Value = "0001246" }, }; var MockProjectCodeService = new Mock<IProjectCodeService>(); MockProjectCodeService.Setup(p => p.GetProjectCodeIdWIthCreate("pro-001")).Returns(projectCodes.FirstOrDefault()); var projectCodeRepositoy = new Mock<IGenericRepository<ProjectCode>>(); projectCodeRepositoy.Setup( t => t.Get(It.IsAny<Expression<Func<ProjectCode, bool>>>(), It.IsAny<Func<IQueryable<ProjectCode>, IOrderedQueryable<ProjectCode>>>(), It.IsAny<string>())).Returns(projectCodes); shippingInstructionService = MockShippingInstructionService.Object; unitOfWork.Setup(t => t.ReceiveRepository).Returns(reieveRepository.Object); unitOfWork.Setup(t => t.CommodityTypeRepository).Returns(commodityTypeRepository.Object); unitOfWork.Setup(t => t.CommodityRepository).Returns(CommodityRepository.Object); _accountTransactionService = new TransactionService(unitOfWork.Object, MockAccountService.Object, shippingInstructionService, MockProjectCodeService.Object); }
public void Init() { var unitOfWork = new Mock<IUnitOfWork>(); var dispatches = new List<Dispatch>() { new Dispatch() { DispatchID = Guid.NewGuid(), PartitionID = 1, HubID = 1, GIN = "GIN-123", FDPID = 1, WeighBridgeTicketNumber = "", RequisitionNo = "REQ-123", BidNumber = "00000", TransporterID = 1, DriverName = "Abebe", PlateNo_Prime = "3-123456", PlateNo_Trailer = "3-123457", PeriodYear = 2014, PeriodMonth = 12, Round = 1, UserProfileID = 1, DispatchDate = DateTime.Now, CreatedDate = DateTime.Now, Remark = "Sample Remark", DispatchedByStoreMan = "Kebede", } }; var dispatchRepositoy = new Mock<IGenericRepository<Dispatch>>(); dispatchRepositoy.Setup( t => t.Get(It.IsAny<Expression<Func<Dispatch, bool>>>(), It.IsAny<Func<IQueryable<Dispatch>, IOrderedQueryable<Dispatch>>>(), It.IsAny<string>())).Returns(dispatches); dispatchRepositoy.Setup(t => t.FindById(It.IsAny<Guid>())).Returns((Guid id) => dispatches. FirstOrDefault(t => t.DispatchID == id)); var commodityTypes = new List<CommodityType>() { new CommodityType() { CommodityTypeID = 1, Name = "Cereal" }, new CommodityType() { CommodityTypeID = 2, Name = "CSB" } }; var commodityTypeRepositoy = new Mock<IGenericRepository<CommodityType>>(); commodityTypeRepositoy.Setup( t => t.Get(It.IsAny<Expression<Func<CommodityType, bool>>>(), It.IsAny<Func<IQueryable<CommodityType>, IOrderedQueryable<CommodityType>>>(), It.IsAny<string>())).Returns(commodityTypes); commodityTypeRepositoy.Setup(t => t.FindById(It.IsAny<int>())).Returns((int id) => commodityTypes. FirstOrDefault(t => t.CommodityTypeID == id)); var transactionRepository = new Mock<IGenericRepository<Transaction>>(); transactionRepository.Setup(t => t.Add(It.IsAny<Transaction>())).Returns(true); var transactionGroupRepository = new Mock<IGenericRepository<TransactionGroup>>(); transactionGroupRepository.Setup(t => t.Add(It.IsAny<TransactionGroup>())).Returns(true); unitOfWork.Setup(t => t.DispatchRepository).Returns(dispatchRepositoy.Object); unitOfWork.Setup(t => t.CommodityTypeRepository).Returns(commodityTypeRepositoy.Object); unitOfWork.Setup(t => t.TransactionRepository).Returns(transactionRepository.Object); unitOfWork.Setup(t => t.TransactionGroupRepository).Returns(transactionGroupRepository.Object); unitOfWork.Setup(t => t.Save()); _hubTransactionService = new TransactionService(unitOfWork.Object,null,null,null); }