/// <inheritdoc /> public IEnumerable<ITransition> AllowTransitions(IList<ITransition> transitions) { return from t in transitions.AsQueryable() join a in this.allowedTransitions.AsQueryable() on t.From equals a.From select t; }
public void SetupController() { resultsRows = Builder<AwsEc2Status>.CreateListOfSize(totalRows).Build(); repository = Substitute.For<IRepository<AwsEc2Status>>(); repository.All().Returns(resultsRows.AsQueryable()); RepositorySession.DefaultContainerType = typeof(FakeObjectContext); controller = new QuartzController(repository); }
private IForumSystemData SetupUnitOfWork(IGenericRepository<Article> articlesRepository, IList<Article> articles) { Mock.Arrange(() => articlesRepository.All()) .Returns(() => articles.AsQueryable()); var forumSystemData = Mock.Create<IForumSystemData>(); Mock.Arrange(() => forumSystemData.Articles) .Returns(() => articlesRepository); return forumSystemData; }
/// <summary></summary> protected IEnumerable<ITransition> TransitionsInCommonWithList(IList<ITransition> transitions) { var list = TransitionList(); list = list ?? EMPTY_TRANSITIONS; var result = from a in transitions.AsQueryable() join b in list.AsQueryable() on a.From equals b.From where object.Equals(a.To, b.To) && object.Equals(_workflowId, a.WorkflowId) select a; return result; }
public void SetupController() { resultsRows = Builder<NiceLittleForm>.CreateListOfSize(TotalRows).Build(); repository = Substitute.For<IRepository<NiceLittleForm>>(); session = Substitute.For<IRepositorySession>(); repository.All().Returns(resultsRows.AsQueryable()); RepositorySession.DefaultContainerType = typeof(FakeObjectContext); controller = new NiceLittleFormController(repository, session); }
public override void Given() { users = new List<User>() { new User("user1", "user1", "user", "one", "[email protected]").SetIdTo(1) as User, new User("user2", "user2", "user", "two", "[email protected]").SetIdTo(2) as User, new User("user3", "user3", "user", "three", "[email protected]").SetIdTo(3) as User }; repository.Setup(r => r.All<User>()).Returns(users.AsQueryable()); emailService.Setup(s => s.SendSystemEmail(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Callback(() => { emailAttempts++; }); ControllerHelper.CreateMockControllerContext(controller); Mock.Get(controller.ControllerContext.HttpContext.Request).Setup(r => r.Url).Returns(new Uri("http://host/users/unapproved")); }
public void SetupFixtures() { _fixtures = new List<Dummy> { new Dummy { Id = "1", FirstName = "Thomas", LastName = "Paine" }, new Dummy { Id = "2", FirstName = "Samuel", LastName = "Adams" }, new Dummy { Id = "3", FirstName = "George", LastName = "Washington"}, new Dummy { Id = "4", FirstName = "Thomas", LastName = "Jefferson" }, new Dummy { Id = "5", FirstName = "Martha", LastName = "Washington"}, new Dummy { Id = "6", FirstName = "Abraham", LastName = "Lincoln" }, new Dummy { Id = "7", FirstName = "Andrew", LastName = "Jackson" }, new Dummy { Id = "8", FirstName = "Andrew", LastName = "Johnson" }, new Dummy { Id = "9", FirstName = "William", LastName = "Harrison" } }; _fixturesQuery = _fixtures.AsQueryable(); }
public override void EstablishContext() { repository = new Mock<IRepository>(); controller = new ScoresheetController(repository.Object); teams = new List<Team>(); users = new List<User>(); var matchResults = new List<MatchResult>(); var matches = new List<Web.Models.Match>(); meets = new List<Meet>(); var divisions = new List<Division>(); season = DomainModelHelper.CreateTestSeason(users, divisions, teams, meets, matches, matchResults); repository.InitAll(users.AsQueryable(), null, new List<Season> { season }.AsQueryable()); foreach (var user in users) { user.UpdateSkillLevel(season.GameType, repository.Object); } adminUser = users[0]; }
public void Init() { _organizations = new List<Organization> { new Organization{ Id = 1, Name = "Pos #1", StatusId = (byte)Status.Approved, ParentId = 0, CreatedAt = DateTime.Now }, new Organization{ Id = 2, Name = "Pos #2", StatusId = (byte)Status.Approved, ParentId = 0, CreatedAt = DateTime.Now }, }; Organization pos1 = _organizations.OrderBy(x => x.Id).First(); Organization pos2 = _organizations.OrderBy(x => x.Id).Skip(1).First(); _categories = new List<Category> { new Category { Id = 2, Name = "Light alcohol", OrganizationId = pos1.Id, ParentId = 0, StatusId = (byte)Status.Approved, CategoryTypeId = 1 }, new Category { Id = 2, Name = "Food", OrganizationId = pos1.Id, ParentId = 0, StatusId = (byte)Status.Approved, CategoryTypeId = 1 }, new Category { Id = 3, Name = "Men shoes", OrganizationId = pos2.Id, ParentId = 0, StatusId = (byte)Status.Approved, CategoryTypeId = 1 }, new Category { Id = 4, Name = "Women shoes", OrganizationId = pos2.Id, ParentId = 0, StatusId = (byte)Status.Approved, CategoryTypeId = 1 }, new Category { Id = 5, Name = "Children shoes", OrganizationId = pos2.Id, ParentId = 0, StatusId = (byte)Status.Approved, CategoryTypeId = 1 } }; Category lightAlcohol = _categories.First(x => x.Name.Contains("Light alcohol")); Category food = _categories.First(x => x.Name.Equals("Food")); _products = new List<Product> { new Product { Id = 1, CategoryId = lightAlcohol.Id, InternalCode = "internal_001", Name = "Beer", PosId = pos1.Id, Price = 10m, StatusId = (byte)Status.Approved, Uid = "uid_0001", UserId = "TestUser", CreatedAt = DateTime.Now }, new Product { Id = 2, CategoryId = food.Id, InternalCode = "internal_002", Name = "Cheese", PosId = pos1.Id, Price = 15m, StatusId = (byte)Status.Approved, Uid = "uid_0002", UserId = "TestUser", CreatedAt = DateTime.Now }, new Product { Id = 3, CategoryId = lightAlcohol.Id, InternalCode = "internal_003", Name = "Beer light", PosId = pos1.Id, Price = 5m, StatusId = (byte)Status.Approved, Uid = "uid_0003", UserId = "TestUser", CreatedAt = DateTime.Now } }; _organizationRepository = new Mock<IOrganizationRepository>(); _organizationRepository.Setup(x => x.Organizations) .Returns(_organizations.AsQueryable()); _categoryMock = new Mock<ICategoryRepository>(); _categoryMock.Setup(x => x.Categories) .Returns(_categories.AsQueryable()); _productRepository = new Mock<IProductRepository>(); _productRepository.Setup(x => x.Products) .Returns(_products.AsQueryable()); _categoryController = new CategoryController( _categoryMock.Object, _organizationRepository.Object, _productRepository.Object); }
public override void EstablishContext() { base.EstablishContext(); users = new List<User>(); divisions = new List<Division>(); teams = new List<Team>(); matches = new List<ClubPool.Web.Models.Match>(); meets = new List<Meet>(); matchResults = new List<MatchResult>(); season = DomainModelHelper.CreateTestSeason(users, divisions, teams, meets, matches, matchResults); adminUser = users[0]; officerUser = users[1]; repository.Init<Division>(divisions.AsQueryable()); repository.Init<User>(users.AsQueryable(), true); repository.Init<Team>(teams.AsQueryable(), true); repository.Init<MatchResult>(matchResults.AsQueryable()); foreach (var user in users) { user.UpdateSkillLevel(season.GameType, repository.Object); } team = teams[0]; }
private IBugLoggerData MockUnitOfWorkForActionAll(IList<Bug> bugs) { var bugFakeRepository = Mock.Create<IBugRepository>(); Mock.Arrange(() => bugFakeRepository.All()) .Returns(() => bugs.AsQueryable()); Mock.Arrange(() => bugFakeRepository.Add(Arg.IsAny<Bug>())) .DoInstead<Bug>((b) => bugs.Add(b)); var bugLoggerData = Mock.Create<IBugLoggerData>(); Mock.Arrange(() => bugLoggerData.Bugs) .Returns(() => bugFakeRepository); return bugLoggerData; }
public IList<ListenTo.Shared.DTO.NewsItemSummary> GetPublishedNewsItemSummaryByIds(IList<Guid> ids) { return GetNewsItemSummary().IsPublished().WithID(ids.AsQueryable<Guid>()).ToList(); }
/// <summary> /// Convert và lưu dữ liệu import và o database. /// </summary> /// <param name="userID"></param> /// <param name="listImportData"></param> /// <returns></returns> public bool Save(Guid userID, IList listImportData, string userLogin) { bool result = false; if (!isDataSaved) { if (listImportData != null && listImportData.Count > 0) { using (var context = new VnrHrmDataContext()) { IUnitOfWork unitOfWork = new UnitOfWork(context); var objectType = listImportData[0].GetPropertyValue(Constant.ObjectType); IList listObj = new ArrayList(); var status = DataErrorCode.Success; if (objectType != null) { if (this.ImportMode == ImportDataMode.Update || this.ImportMode == ImportDataMode.Skip) { var listObjectID = listImportData.AsQueryable().Select(Constant.ID).GetList().OfType<Guid>().Distinct().ToArray(); listEntityResult = unitOfWork.CreateQueryable(Guid.Empty, (Type)objectType, "@0.Contains(outerIt." + Constant.ID + ")", listObjectID).GetList(); foreach (var importData in listImportData) { var objectID = importData.GetPropertyValue(Constant.ID).TryGetValue<Guid>(); var objectDuplicate = listEntityResult.AsQueryable().Where(Constant.ID + " = @0", objectID).FirstOrDefault(); if (objectDuplicate != null) { //Copy dữ liệu import và o dữ liệu trong database importData.CopyData(objectDuplicate, Constant.ID); } else if (this.ImportMode == ImportDataMode.Skip) { objectDuplicate = ((Type)objectType).CreateInstance(); importData.CopyData(objectDuplicate, Constant.ID); unitOfWork.AddObject((Type)objectType, objectDuplicate); } if (objectDuplicate != null) { listObj.Add(objectDuplicate); } var currentIndex = listImportData.IndexOf(importData); if ((currentIndex + 1) == listImportData.Count || (currentIndex > 0 && listImportData.IndexOf(importData) % 9999 == 0)) { status = unitOfWork.SaveChanges(userID, true); } if (ProgressChanged != null) { double percent = ((double)listImportData.IndexOf(importData) / (double)listImportData.Count) * 100; ProgressChanged(new ProgressEventArgs { ID = UserID, Name = "SaveData", Value = "SaveData".TranslateString(), Percent = (int)percent }); } } result = true; } else { listEntityResult = ((Type)objectType).CreateList(); foreach (var importData in listImportData) { var objectDuplicate = ((Type)objectType).CreateInstance(); importData.CopyData(objectDuplicate, Constant.ID); unitOfWork.AddObject((Type)objectType, objectDuplicate); var currentIndex = listImportData.IndexOf(importData); if ((currentIndex + 1) == listImportData.Count || (currentIndex > 0 && listImportData.IndexOf(importData) % 9999 == 0)) { status = unitOfWork.SaveChanges(userID, true); } if (ProgressChanged != null) { double percent = ((double)listImportData.IndexOf(importData) / (double)listImportData.Count) * 100; ProgressChanged(new ProgressEventArgs { ID = UserID, Name = "SaveData", Value = "SaveData".TranslateString(), Percent = (int)percent }); } } listObj = listEntityResult; result = true; } isDataSaved = true; //XỠlý task vụ sau khi import if (status == DataErrorCode.Success) { if ((Type)objectType == typeof(Rec_Candidate)) { if (listObj.Count > 0) { var listGuidID = new List<Guid>(); foreach (var item in listObj) { if (item != null) { listGuidID.Add((Guid)item.GetPropertyValue(Constant.ID)); } } DoActionAfterImport afterImport = new DoActionAfterImport(); afterImport.ImportRecruitmentHistory(listGuidID, userLogin); } } } else { result = false; } #region ImportCompleted if (ProgressChanged != null) { ProgressChanged(new ProgressEventArgs { ID = UserID, Name = "SaveData", Value = "SaveData".TranslateString(), Percent = 100 }); } #endregion } } } } return result; }
public override void Given() { users = new List<User>(); repository.Setup(r => r.All<User>()).Returns(users.AsQueryable()); }
public void Init() { var unitOfWorkNotify = new Mock<IUnitOfWork>(); _transportBidWinners = new List<BidWinner>() { new BidWinner() { SourceID= 1, DestinationID= 1, Tariff= 100, TransporterID = 1 } }; _reliefRequisitions = new List<ReliefRequisition>() { new ReliefRequisition() { RegionID = 1, ProgramID = 1, CommodityID = 1, ZoneID = 2, RequisitionNo = "REQ-001", Round = 1, RegionalRequestID = 1, RequisitionID = 1, Status = 4, ReliefRequisitionDetails=new List<ReliefRequisitionDetail>() { new ReliefRequisitionDetail { RequisitionID=1, RequisitionDetailID=1, FDPID=1, DonorID=1, CommodityID=1, Amount=10, BenficiaryNo=12, ReliefRequisition = new ReliefRequisition() { RequisitionID = 1, RegionalRequestID = 1, TransportRequisitionDetails = new List<TransportRequisitionDetail>() { new TransportRequisitionDetail() { RequisitionID = 1, TransportRequisitionDetailID = 1, TransportRequisitionID = 1 } } }, FDP=new FDP { Name="XYX", AdminUnitID=1, FDPID=1 }, } } } }; var _tranportRequisitionDetail = new List<TransportRequisitionDetail>() { new TransportRequisitionDetail { RequisitionID=1, TransportRequisitionID=1 } }; _transportOrders = new List<TransportOrder>() { new TransportOrder() { TransporterID=1, TransportOrderID=1, StatusID = 1, StartDate=DateTime.Today, EndDate=DateTime.Today, BidDocumentNo="xyz" } }; var _transportRequisitons = new List<TransportRequisition> { new TransportRequisition { TransportRequisitionID = 1, Status = 1, TransportRequisitionNo = "001" } }; var _hubAllocation = new List<HubAllocation> { new HubAllocation { RequisitionID = 1, HubID = 1 } }; var mockUnitOfWork = new Mock<IUnitOfWork>(); var mockReliefRequisitionRepository = new Mock<IGenericRepository<ReliefRequisition>>(); mockReliefRequisitionRepository.Setup( t => t.Get(It.IsAny<Expression<Func<ReliefRequisition, bool>>>(), It.IsAny<Func<IQueryable<ReliefRequisition>, IOrderedQueryable<ReliefRequisition>>>(), It.IsAny<string>())).Returns( (Expression<Func<ReliefRequisition, bool>> perdicate, Func<IQueryable<ReliefRequisition>, IOrderedQueryable<ReliefRequisition>> obrderBy, string prop) => { var result = _reliefRequisitions.AsQueryable(); return result; } ); mockReliefRequisitionRepository.Setup(t => t.FindById(It.IsAny<int>())).Returns((int id) => _reliefRequisitions .ToList(). Find (t => t. RequisitionID == id)); var mockReliefRequisionDetailRepository = new Mock<IGenericRepository<ReliefRequisitionDetail>>(); mockReliefRequisionDetailRepository.Setup( t => t.Get(It.IsAny<Expression<Func<ReliefRequisitionDetail, bool>>>(), It.IsAny<Func<IQueryable<ReliefRequisitionDetail>, IOrderedQueryable<ReliefRequisitionDetail>>>(), It.IsAny<string>())).Returns( (Expression<Func<ReliefRequisitionDetail, bool>> predicate, Func<IQueryable<ReliefRequisitionDetail>, IOrderedQueryable<ReliefRequisitionDetail>> filter, string str) => { return _reliefRequisitions.First().ReliefRequisitionDetails.AsQueryable(); } ); mockUnitOfWork.Setup(t => t.ReliefRequisitionDetailRepository).Returns( mockReliefRequisionDetailRepository.Object); var mockTransportBidWinnerDetailRepository = new Mock<IGenericRepository<BidWinner>>(); mockTransportBidWinnerDetailRepository.Setup(t => t.Get(It.IsAny<Expression<Func<BidWinner, bool>>>(), It.IsAny<Func<IQueryable<BidWinner>, IOrderedQueryable<BidWinner>>>(), It.IsAny<string>())).Returns(_transportBidWinners.AsQueryable()); mockUnitOfWork.Setup(t => t.BidWinnerRepository).Returns( mockTransportBidWinnerDetailRepository.Object); mockUnitOfWork.Setup(t => t.ReliefRequisitionRepository).Returns(mockReliefRequisitionRepository.Object); var hubAllocationRepository = new Mock<IGenericRepository<HubAllocation>>(); hubAllocationRepository.Setup(t => t.FindBy(It.IsAny<Expression<Func<HubAllocation, bool>>>())).Returns(_hubAllocation); mockUnitOfWork.Setup(t => t.HubAllocationRepository).Returns(hubAllocationRepository.Object); var transportOrderRepository = new Mock<IGenericRepository<TransportOrder>>(); transportOrderRepository.Setup( t => t.Get(It.IsAny<Expression<Func<TransportOrder, bool>>>(), It.IsAny<Func<IQueryable<TransportOrder>, IOrderedQueryable<TransportOrder>>>(), It.IsAny<string>())).Returns( _transportOrders.AsQueryable()); transportOrderRepository.Setup(t => t.Add(It.IsAny<TransportOrder>())).Returns(true); mockUnitOfWork.Setup(t => t.TransportOrderRepository).Returns(transportOrderRepository.Object); var transportOrderDetailRepository = new Mock<IGenericRepository<TransportOrderDetail>>(); transportOrderDetailRepository.Setup( t => t.Get(It.IsAny<Expression<Func<TransportOrderDetail, bool>>>(), It.IsAny<Func<IQueryable<TransportOrderDetail>, IOrderedQueryable<TransportOrderDetail>>>(), It.IsAny<string>())).Returns(new List<TransportOrderDetail>(){new TransportOrderDetail(){CommodityID=1,FdpID=1,DonorID = 1,RequisitionID = 1,QuantityQtl = 1,SourceWarehouseID=1, ReliefRequisition=new ReliefRequisition { ProgramID=1, Round=1, Month=1, RequisitionID=1, RequisitionNo= "1" }}}); mockUnitOfWork.Setup(t => t.TransportOrderDetailRepository).Returns(transportOrderDetailRepository.Object); var transportRequisition = new Mock<IGenericRepository<TransportRequisition>>(); transportRequisition.Setup( t => t.Get(It.IsAny<Expression<Func<TransportRequisition, bool>>>(), It.IsAny<Func<IQueryable<TransportRequisition>, IOrderedQueryable<TransportRequisition>>>(), It.IsAny<string>())).Returns(_transportRequisitons); mockUnitOfWork.Setup(t => t.TransportRequisitionRepository).Returns(transportRequisition.Object); mockUnitOfWork.Setup(t => t.Save()); var transportRequisitionDetailRepository = new Mock<IGenericRepository<TransportRequisitionDetail>>(); transportRequisitionDetailRepository.Setup(t => t.Get(It.IsAny<Expression<Func<TransportRequisitionDetail, bool>>>(), It.IsAny<Func<IQueryable<TransportRequisitionDetail>, IOrderedQueryable<TransportRequisitionDetail>>>(), It.IsAny<string>())).Returns( (Expression<Func<TransportRequisitionDetail, bool>> predicate, Func<IQueryable<TransportRequisition>, IOrderedQueryable<TransportRequisition>> filter, string includeProp) => { return _tranportRequisitionDetail; }); mockUnitOfWork.Setup(t => t.TransportRequisitionDetailRepository).Returns( transportRequisitionDetailRepository.Object); var applicationSettingRepository = new Mock<IGenericRepository<ApplicationSetting>>(); applicationSettingRepository.Setup(t=>t.FindBy(It.IsAny<Expression<Func<ApplicationSetting, bool>>>())).Returns(new List<ApplicationSetting>() { new ApplicationSetting() { SettingID=1, SettingName="CurrentBid", SettingValue = "1" } }); mockUnitOfWork.Setup(t => t.ApplicationSettingRepository).Returns(applicationSettingRepository.Object); ; var bidRepository = new Mock<IGenericRepository<Bid>>(); bidRepository.Setup(t => t.FindById(It.IsAny<int>())).Returns(new Bid() {BidID = 1, BidNumber = "Bid-001"}); mockUnitOfWork.Setup(t => t.BidRepository).Returns(bidRepository.Object); var transporterRepository = new Mock<IGenericRepository<Transporter>>(); transporterRepository.Setup(t => t.FindById(It.IsAny<int>())).Returns(new Transporter() { TransporterID = 1, Name = "TRANS" }); mockUnitOfWork.Setup(t => t.TransporterRepository).Returns(transporterRepository.Object); var dispatchAllocationRepository = new Mock<IGenericRepository<DispatchAllocation>>(); dispatchAllocationRepository.Setup(t => t.Add(It.IsAny<DispatchAllocation>())).Returns(true); mockUnitOfWork.Setup(t => t.DispatchAllocationRepository).Returns(dispatchAllocationRepository.Object); var sipcAllocationRepository = new Mock<IGenericRepository<SIPCAllocation>>(); sipcAllocationRepository.Setup(t => t.FindBy(It.IsAny<Expression<Func<SIPCAllocation, bool>>>())).Returns(new List<SIPCAllocation>()); mockUnitOfWork.Setup(t => t.SIPCAllocationRepository).Returns(sipcAllocationRepository.Object); var transporterService = new Mock<ITransporterService>(); transporterService.Setup(t => t.GetCurrentBidWinner(It.IsAny<int>(), It.IsAny<int>())).Returns(new TransportBidQuotation () { BidID = 1, DestinationID = 1, Position = 1, IsWinner = true, SourceID = 1, Tariff = 1, TransporterID = 1, TransportBidQuotationID = 1 }); _notificationService = new NotificationService(unitOfWorkNotify.Object); _transportOrderService = new TransportOrderService(mockUnitOfWork.Object, transporterService.Object, _notificationService); //Act }
public void Init() { _transportRequisitions = new List<TransportRequisition>(); _reliefRequisitions = new List<int> { 1 }; var unitOfWork = new Mock<IUnitOfWork>(); var unitOfWorkNotify = new Mock<IUnitOfWork>(); _transportRequisition = new TransportRequisition { Status = 1, RequestedDate = DateTime.Today, RequestedBy = 1, CertifiedBy = 1, CertifiedDate = DateTime.Today, Remark = "", TransportRequisitionNo = "REQ-001", TransportRequisitionID = 1, TransportRequisitionDetails = new List<TransportRequisitionDetail>() { new TransportRequisitionDetail { RequisitionID = 1, TransportRequisitionDetailID = 1, TransportRequisitionID = 1 } } }; reliefRequisitions = new List<ReliefRequisition>() { new ReliefRequisition() { RegionID = 1, ProgramID = 1, CommodityID = 1, ZoneID = 2, RequisitionNo = "REQ-001", Round = 1, RegionalRequestID = 1, RequisitionID = 1, Status = 4, AdminUnit = new AdminUnit { AdminUnitID = 2, Name = "Zone1" }, AdminUnit1 = new AdminUnit { AdminUnitID = 1, Name = "Region1" }, Commodity = new Commodity { CommodityID = 1, CommodityCode = "C1", Name = "CSB" }, //HubAllocations = new List<HubAllocation>(){new HubAllocation() // { // HubAllocationID = 1, // HubID = 1, // RequisitionID = 1, // Hub = new Hub // { // HubID = 1, // Name = "Test Hub", // } // }}, ReliefRequisitionDetails = new List<ReliefRequisitionDetail> { new ReliefRequisitionDetail() { RequisitionID = 1, RequisitionDetailID = 1, Amount = 100, CommodityID = 1, FDPID = 1, BenficiaryNo = 10, DonorID = 1, FDP=new FDP { AdminUnitID=1, FDPID=1, Name="FDP1" } }, new ReliefRequisitionDetail() { RequisitionID = 1, RequisitionDetailID = 2, Amount = 50, CommodityID = 1, FDPID = 2, BenficiaryNo = 10, DonorID = 1, FDP=new FDP { AdminUnitID=1, FDPID=2, Name="FDP2" } }, new ReliefRequisitionDetail() { RequisitionID = 1, RequisitionDetailID = 3, Amount = 60, CommodityID = 1, FDPID = 3, BenficiaryNo = 10, DonorID = 1, FDP=new FDP { AdminUnitID=1, FDPID=3, Name="FDP3" } }, new ReliefRequisitionDetail() { RequisitionID = 1, RequisitionDetailID = 4, Amount = 70, CommodityID = 1, FDPID = 2, BenficiaryNo = 10, DonorID = 1, FDP=new FDP { AdminUnitID=1, FDPID=4, Name="FDP4" } } } } }; var _workflowstatuses = new List<WorkflowStatus> { new WorkflowStatus { StatusID = 1, WorkflowID = 2, Description = "Approved", } }; var _hubAllocation = new List<HubAllocation> { new HubAllocation { RequisitionID = 1, HubID = 1, HubAllocationID = 1, Hub=new Models.Hub() { Name="Hub 1", HubID=1, } } }; _transportRequisition = new TransportRequisition() { Status = 1, AdminUnit = new AdminUnit { AdminUnitID = 2, Name = "Zone1"}, RequestedBy = 1, CertifiedBy = 1, CertifiedDate = DateTime.Today, RequestedDate = DateTime.Today, TransportRequisitionID = 1, TransportRequisitionNo = "T-001", Remark = "comment" }; var mockReliefRequisitionRepository = new Mock<IGenericRepository<ReliefRequisition>>(); mockReliefRequisitionRepository.Setup( t => t.Get(It.IsAny<Expression<Func<ReliefRequisition, bool>>>(), It.IsAny<Func<IQueryable<ReliefRequisition>, IOrderedQueryable<ReliefRequisition>>>(), It.IsAny<string>())).Returns( (Expression<Func<ReliefRequisition, bool>> perdicate, Func<IQueryable<ReliefRequisition>, IOrderedQueryable<ReliefRequisition>> obrderBy, string prop) => { var result = reliefRequisitions.AsQueryable(); return result; } ); mockReliefRequisitionRepository.Setup(t => t.FindById(It.IsAny<int>())).Returns((int id) => reliefRequisitions .ToList(). Find (t => t. RequisitionID == id)); unitOfWork.Setup(t => t.ReliefRequisitionRepository).Returns(mockReliefRequisitionRepository.Object); var transportRequisitionReqository = new Mock<IGenericRepository<TransportRequisition>>(); transportRequisitionReqository.Setup(t => t.Add(It.IsAny<TransportRequisition>())).Returns( (TransportRequisition transportRequisiton) => { _transportRequisitions.Add(transportRequisiton); return true; }); transportRequisitionReqository.Setup(t => t.FindById(It.IsAny<int>())).Returns((int id) => { return _transportRequisition; }); unitOfWork.Setup(t => t.TransportRequisitionRepository).Returns(transportRequisitionReqository.Object); unitOfWork.Setup(t => t.Save()); var workflowStatusRepository = new Mock<IGenericRepository<WorkflowStatus>>(); workflowStatusRepository.Setup( t => t.Get(It.IsAny<Expression<Func<WorkflowStatus, bool>>>(), It.IsAny<Func<IQueryable<WorkflowStatus>, IOrderedQueryable<WorkflowStatus>>>(), It.IsAny<string>())).Returns(_workflowstatuses); unitOfWork.Setup(t => t.WorkflowStatusRepository).Returns(workflowStatusRepository.Object); var hubAllocationRepository = new Mock<IGenericRepository<HubAllocation>>(); hubAllocationRepository.Setup( t => t.Get(It.IsAny<Expression<Func<HubAllocation, bool>>>(), It.IsAny<Func<IQueryable<HubAllocation>, IOrderedQueryable<HubAllocation>>>(), It.IsAny<string>())).Returns(_hubAllocation); unitOfWork.Setup(t => t.HubAllocationRepository).Returns(hubAllocationRepository.Object); var adminUnitRepository = new Mock<IGenericRepository<AdminUnit>>(); adminUnitRepository.Setup(t => t.FindById(It.IsAny<int>())).Returns(new AdminUnit() { AdminUnitID = 2, Name = "Zone1", AdminUnit2 = new AdminUnit { AdminUnitID = 1, Name = "Region1" } } ); unitOfWork.Setup(t => t.AdminUnitRepository).Returns(adminUnitRepository.Object); var programRepository = new Mock<IGenericRepository<Program>>(); programRepository.Setup(t => t.FindById(It.IsAny<int>())).Returns(new Program { ProgramID = 1, Name = "PSNP", Description = "PSNP Des." }); unitOfWork.Setup(t => t.ProgramRepository).Returns(programRepository.Object); _notificationService = new NotificationService(unitOfWorkNotify.Object); _transportRequisitionService = new TransportRequisitionService(unitOfWork.Object, _notificationService); }
public void SetupFixtures() { _fixtures = new List<Dummy> { #region StringField new Dummy { Id = "100", StringField = "String value 1" }, new Dummy { Id = "101", StringField = "String value 2" }, new Dummy { Id = "102", StringField = "String value 2", EnumField = SomeEnum.EnumValue3 }, #endregion #region DateTimeField new Dummy { Id = "110", DateTimeField = new DateTime(1930, 11, 7) }, new Dummy { Id = "111", DateTimeField = new DateTime(1980, 6, 2) }, #endregion #region NullableDateTimeField new Dummy { Id = "120", NullableDateTimeField = new DateTime(1961, 2, 18) }, #endregion #region DateTimeOffsetField new Dummy { Id = "130", DateTimeOffsetField = new DateTime(1991, 1, 3) }, new Dummy { Id = "131", DateTimeOffsetField = new DateTime(2004, 10, 31) }, #endregion #region NullableDateTimeOffsetField new Dummy { Id = "140", NullableDateTimeOffsetField = new DateTime(2014, 5, 5) }, #endregion #region EnumField new Dummy { Id = "150", EnumField = SomeEnum.EnumValue1 }, new Dummy { Id = "151", EnumField = SomeEnum.EnumValue2 }, #endregion #region NullableEnumField new Dummy { Id = "160", NullableEnumField = SomeEnum.EnumValue3 }, #endregion #region DecimalField new Dummy { Id = "170", DecimalField = (decimal) 4.03 }, new Dummy { Id = "171", DecimalField = (decimal) 6.37 }, #endregion #region NullableDecimalField new Dummy { Id = "180", NullableDecimalField = (decimal) 12.09 }, #endregion #region BooleanField new Dummy { Id = "190", BooleanField = true }, new Dummy { Id = "191", BooleanField = false }, #endregion #region NullableBooleanField new Dummy { Id = "200", NullableBooleanField = false }, #endregion #region SByteField new Dummy { Id = "210", SbyteField = 63 }, new Dummy { Id = "211", SbyteField = -89 }, #endregion #region NullableSByteField new Dummy { Id = "220", NullableSbyteField = 91 }, #endregion #region ByteField new Dummy { Id = "230", ByteField = 250 }, new Dummy { Id = "231", ByteField = 130 }, #endregion #region NullableByteField new Dummy { Id = "240", NullableByteField = 44 }, #endregion #region Int16Field new Dummy { Id = "250", Int16Field = 12345 }, new Dummy { Id = "251", Int16Field = -23456 }, #endregion #region NullableInt16Field new Dummy { Id = "260", NullableInt16Field = 32764 }, #endregion #region UInt16Field new Dummy { Id = "270", Uint16Field = 12345 }, new Dummy { Id = "271", Uint16Field = 45678 }, #endregion #region NullableUInt16Field new Dummy { Id = "280", NullableUint16Field = 65000 }, #endregion #region Int32Field new Dummy { Id = "290", Int32Field = 100000006 }, new Dummy { Id = "291", Int32Field = -234567890 }, #endregion #region NullableInt32Field new Dummy { Id = "300", NullableInt32Field = 345678901 }, #endregion #region UInt32Field new Dummy { Id = "310", Uint32Field = 123456789 }, new Dummy { Id = "311", Uint32Field = 234567890 }, #endregion #region NullableUInt32Field new Dummy { Id = "320", NullableUint32Field = 345678901 }, #endregion #region Int64Field new Dummy { Id = "330", Int64Field = 123453489012 }, new Dummy { Id = "331", Int64Field = -234067890123 }, #endregion #region NullableInt64Field new Dummy { Id = "340", NullableInt64Field = 345671901234 }, #endregion #region UInt64Field new Dummy { Id = "350", Uint64Field = 123456789012 }, new Dummy { Id = "351", Uint64Field = 234567890123 }, #endregion #region NullableUInt64Field new Dummy { Id = "360", NullableUint64Field = 345678901234 }, #endregion #region SingleField new Dummy { Id = "370", SingleField = 21.56901f }, new Dummy { Id = "371", SingleField = -34.789f }, #endregion #region NullableSingleField new Dummy { Id = "380", NullableSingleField = 1.3456f }, #endregion #region DoubleField new Dummy { Id = "390", DoubleField = 12.3453489012 }, new Dummy { Id = "391", DoubleField = -2340678.90123 }, #endregion #region NullableDoubleField new Dummy { Id = "400", NullableDoubleField = 34567.1901234 }, #endregion #region Unknown Type new Dummy { Id = "1000", UnknownTypeField = new SomeUnknownType() }, #endregion #region ToOneRelatedItem new Dummy { Id = "1100", ToOneRelatedItem = new RelatedItemWithId { Id = "1101", Name = "Related sample 1" } }, new Dummy { Id = "1102", ToOneRelatedItem = new RelatedItemWithId { Id = "1103", Name = "Related sample 2" } }, #endregion #region ToManyRelatedItems new Dummy { Id = "1110", ToManyRelatedItems = new List<RelatedItemWithId> { new RelatedItemWithId { Id = "1111", Name = "Related sample 3" }, new RelatedItemWithId { Id = "1112", Name = "Related sample 4" } } }, new Dummy { Id = "1120", ToManyRelatedItems = new List<RelatedItemWithId> { new RelatedItemWithId { Id = "1121", Name = "Related sample 5" }, new RelatedItemWithId { Id = "1122", Name = "Related sample 6" } } } #endregion }; _fixturesQuery = _fixtures.AsQueryable(); }
public void SetUp() { _posts = new List<Post>(); _users = new List<User>(); _repository = MockRepository.GenerateStub<IRepository>(); _resolver = MockRepository.GenerateStub<IUrlResolver>(); _blogPostCommentService = MockRepository.GenerateStub<IBlogPostCommentService>(); _userService = MockRepository.GenerateStub<IUserService>(); _controller = new BlogPostController(_repository, _resolver, _blogPostCommentService, _userService); _post = new Post { Slug = _testSlug }; _posts.Add(_post); _repository .Stub(r => r.Query<Post>(null)) .IgnoreArguments() .Return(_posts.AsQueryable()); _repository .Stub(r => r.Query<User>(null)) .IgnoreArguments() .Return(_users.AsQueryable()); _testSlug = "TESTSLUG"; _invalidInput = new BlogPostCommentViewModel {Slug = _testSlug}; _validInput = new BlogPostCommentViewModel { DisplayName = "username", Email = "email", Body = "body", Subscribed = true, Slug = _testSlug }; }
public override void Given() { users = new List<User>() { new User("user1", "user1", "user", "one", "[email protected]"), new User("user2", "user2", "user", "two", "use[email protected]"), new User("user3", "user3", "user", "three", "[email protected]") { IsApproved = true } }; repository.Setup(r => r.All<User>()).Returns(users.AsQueryable()); }
public void Init() { _reliefRequisitions = new List<ReliefRequisition>() { new ReliefRequisition() { RegionID = 1, ProgramID = 1, CommodityID = 1, ZoneID = 2, RequisitionNo = "REQ-001", Round = 1, RegionalRequestID = 1, RequisitionID = 1, Status = 1, AdminUnit = new AdminUnit { AdminUnitID = 2, Name = "Zone1" }, AdminUnit1 = new AdminUnit { AdminUnitID = 1, Name = "Region1" }, Commodity = new Commodity { CommodityID = 1, CommodityCode = "C1", Name = "CSB" }, HubAllocations = new List<HubAllocation>(){new HubAllocation() { HubAllocationID = 1, HubID = 1, RequisitionID = 1, Hub = new Hub { HubId = 1, Name = "Test Hub", } }}, ReliefRequisitionDetails = new Collection<ReliefRequisitionDetail> { new ReliefRequisitionDetail() { RequisitionID = 1, RequisitionDetailID = 1, Amount = 100, CommodityID = 1, FDPID = 1, BenficiaryNo = 10, DonorID = 1 }, new ReliefRequisitionDetail() { RequisitionID = 1, RequisitionDetailID = 2, Amount = 50, CommodityID = 1, FDPID = 2, BenficiaryNo = 10, DonorID = 1 }, new ReliefRequisitionDetail() { RequisitionID = 1, RequisitionDetailID = 3, Amount = 60, CommodityID = 1, FDPID = 1, BenficiaryNo = 10, DonorID = 1 }, new ReliefRequisitionDetail() { RequisitionID = 1, RequisitionDetailID = 4, Amount = 70, CommodityID = 1, FDPID = 2, BenficiaryNo = 10, DonorID = 1 } } } }; _transportOrders = new List<TransportOrder>(); //Arrange var mockUnitOfWork = new Mock<IUnitOfWork>(); var mockReliefRequisitionRepository = new Mock<IGenericRepository<ReliefRequisition>>(); mockReliefRequisitionRepository.Setup( t => t.Get(It.IsAny<Expression<Func<ReliefRequisition, bool>>>(), It.IsAny<Func<IQueryable<ReliefRequisition>, IOrderedQueryable<ReliefRequisition>>>(), It.IsAny<string>())).Returns( (Expression<Func<ReliefRequisition, bool>> perdicate, Func<IQueryable<ReliefRequisition>, IOrderedQueryable<ReliefRequisition>> obrderBy, string prop) => { var result = _reliefRequisitions.AsQueryable(); return result; } ); mockUnitOfWork.Setup(t => t.ReliefRequisitionRepository).Returns(mockReliefRequisitionRepository.Object); var transportOrderRepository = new Mock<IGenericRepository<TransportOrder>>(); transportOrderRepository.Setup( t => t.Get(It.IsAny<Expression<Func<TransportOrder, bool>>>(), null, It.IsAny<string>())).Returns( (Expression<Func<TransportOrder, bool>> perdicate, string prop) => { var result = _transportOrders . AsQueryable (); return result; } ); _transportOrderService = new TransportOrderService(mockUnitOfWork.Object); //Act }
private IList<Catalog> PreparedParentCatalogs(IList<Catalog> source, int duplicateCatalogId = 0) { var result = source.AsQueryable() as IQueryable<Catalog>; if (duplicateCatalogId != 0) { result = result.Where(c => c.Id != duplicateCatalogId && c.GenericCatalog.Catalogs .Any(cx => cx.Id == duplicateCatalogId)); } result = result.Where(c => !c.ParentCatalogId.HasValue || c.ParentCatalogId.HasValue && c.ParentCatalogId != duplicateCatalogId); return result.ToList(); }
public void SetUp() { _users = new List<User>(); _repository = MockRepository.GenerateStub<IRepository>(); _userService = new UserService(_repository); _curUser = null; _repository.Stub(r => r.Query<User>(null)).IgnoreArguments().Return(_users.AsQueryable()); GivenUserDisplayName = "username"; GivenUserEmail = "email"; GivenUserUrl = "www"; GivenTwitterUserName = "name"; _curUser = _userService.AddOrUpdateUser(GivenUserEmail, GivenUserDisplayName, GivenUserUrl, GivenTwitterUserName); }