public void Constructor_Must_Fail_When_Valid_Context_Invalid_Factory() { // // Arrange, Act // var mockContext = new Mock<EFDbContext>(); var uow = new UoW(mockContext.Object, null); }
public void Constructor_Must_Fail_When_Valid_RepositoryFactory_Invalid_Context() { // // Arrange, Act // var mockRepoFactory = new Mock<IRepositoryFactory>(); var uow = new UoW(null, mockRepoFactory.Object); }
// GET: /License/Create public ActionResult Create() { Log.Debug("GET/Create"); using (var uow = new UoW()) { ViewBag.CustomerId = JsonConvert.SerializeObject(uow.Customers.GetAll().ToList()); // new SelectList(uow.Customers.GetAll().ToList(), "Id", "FirstName"); ViewBag.ProductId = JsonConvert.SerializeObject(uow.Products.GetAll().ToList());//new SelectList(uow.Products.GetAll().ToList(), "Id", "Name"); } return View(); }
// GET: /Product/ #region Methods public ActionResult Index() { Log.Debug("GET/Index"); using (var uow = new UoW()) { var productsRepo = uow.GetRepository<IProductRepository>(); var products = productsRepo.GetQuery().Include(p => p.Creator).ToList(); return View("Index", (object)JsonConvert.SerializeObject(products)); } }
// GET: /License/ #region Methods public ActionResult Index() { Log.Debug("GET/Index"); using (var uow = new UoW()) { var licensesRepo = uow.GetRepository<ILicensePocoRepository>(); var licenses = licensesRepo.GetQuery().Include(l => l.Creator).Include(l => l.Customer).Include(l => l.Product).ToList(); return View("Index", (object)JsonConvert.SerializeObject(licenses)); } }
public void Constructor_Must_Accept_Valid_Context_And_Factory() { // // Arrange, Act // var mockContext = new Mock<EFDbContext>(); var mockRepoFactory = new Mock<IRepositoryFactory>(); var uow = new UoW(mockContext.Object, mockRepoFactory.Object); // // Assert // Assert.IsNotNull(uow.Context); Assert.IsNotNull(uow.repositoryFactory); }
public void Repo_Audiences_DeleteV1_Success() { var data = new TestDataFactory(UoW); data.Destroy(); data.CreateAudiences(); var audience = UoW.Audiences.Get(QueryExpressionFactory.GetQueryExpression <tbl_Audience>() .Where(x => x.Name == TestDefaultConstants.AudienceName).ToLambda()) .Single(); UoW.Audiences.Delete(audience); UoW.Commit(); }
public void Repo_Claims_DeleteV1_Success() { var data = new TestDataFactory(UoW); data.Destroy(); data.CreateClaims(); var claim = UoW.Claims.Get(QueryExpressionFactory.GetQueryExpression <tbl_Claim>() .Where(x => x.Type == TestDefaultConstants.ClaimName).ToLambda()) .Single(); UoW.Claims.Delete(claim); UoW.Commit(); }
public async void GivenModelId_ManagerFindsEntity() { // Arrange var manager = new GenericManager <Word>(UoWFactoryMock.Object); UoW.Setup(m => m.CreateRepository <IGenericRepository <Word> >().FindByIdAsync(It.IsAny <int>())) .Returns(Task.FromResult(word)).Verifiable(); // Act await manager.FindByIdAsync(betId).ConfigureAwait(false); // Assert UoW.Verify(m => m.CreateRepository <IGenericRepository <Word> >().FindByIdAsync(It.Is <int>(it => it == word.Id))); }
public async Task <ActionResult> AddMultiple(IEnumerable <Purchase> purchases) { if (purchases != null) { UoW.Purchases.AddRange(purchases); await UoW.Complete(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Index")); } }
public async Task <ActionResult> Delete(int id) { var purchase = await UoW.Purchases.GetAsync(id); if (purchase != null) { var items = await UoW.Ingredients.GetItems(id); UoW.Purchases.Remove(purchase); UoW.Ingredients.RemoveRange(items); await UoW.Complete(); } return(RedirectToAction("Index")); }
public void Repo_Issuers_DeleteV1_Success() { var data = new TestDataFactory(UoW); data.Destroy(); data.CreateIssuers(); var issuer = UoW.Issuers.Get(QueryExpressionFactory.GetQueryExpression <uvw_Issuer>() .Where(x => x.Name == TestDefaultConstants.IssuerName).ToLambda()) .Single(); UoW.Issuers.Delete(issuer); UoW.Commit(); }
public void Repo_Roles_DeleteV1_Success() { var data = new TestDataFactory(UoW); data.Destroy(); data.CreateRoles(); var role = UoW.Roles.Get(QueryExpressionFactory.GetQueryExpression <uvw_Role>() .Where(x => x.Name == TestDefaultConstants.RoleName).ToLambda()) .Single(); UoW.Roles.Delete(role); UoW.Commit(); }
protected void OnButtonRemoveClicked(object sender, EventArgs e) { var row = ytreeviewItems.GetSelectedObject <PremiumItem>(); if (row.Id > 0) { UoW.Delete(row); if (row.WageOperation != null) { UoW.Delete(row.WageOperation); } } Entity.ObservableItems.Remove(row); }
public async Task <ActionResult> Create(MeasurementUnit unit) { if (unit.UnitID != 0) { UoW.Units.Update(unit); } else { UoW.Units.Add(unit); } await UoW.Complete(); return(RedirectToAction("ViewUnits")); }
public void ChangeDeadlineDate(object[] selectedObjs, DateTime date) { var nodes = selectedObjs.OfType <BusinessTaskJournalNode>().ToLookup(key => key.EntityType, val => val.Id); foreach (var tasks in nodes) { foreach (int task in tasks) { Type type = tasks.Key; var obj = UoW.GetById(type, task); } } }
public OrderJournalFilterViewModel( ICounterpartyJournalFactory counterpartyJournalFactory, IDeliveryPointJournalFactory deliveryPointJournalFactory) { Organisations = UoW.GetAll <Organization>(); PaymentsFrom = UoW.GetAll <PaymentFrom>(); _deliveryPointJournalFilterViewModel = new DeliveryPointJournalFilterViewModel(); deliveryPointJournalFactory?.SetDeliveryPointJournalFilterViewModel(_deliveryPointJournalFilterViewModel); DeliveryPointSelectorFactory = deliveryPointJournalFactory?.CreateDeliveryPointByClientAutocompleteSelectorFactory() ?? throw new ArgumentNullException(nameof(deliveryPointJournalFactory)); CounterpartySelectorFactory = counterpartyJournalFactory?.CreateCounterpartyAutocompleteSelectorFactory() ?? throw new ArgumentNullException(nameof(counterpartyJournalFactory)); GeographicGroups = UoW.Session.QueryOver <GeographicGroup>().List <GeographicGroup>().ToList(); }
public async Task <ActionResult> Create(Customer customer) { if (!ModelState.IsValid) { return(View()); } else { UoW.Customers.Add(customer); await UoW.Complete(); return(RedirectToAction("Index")); } }
public void Repo_Logins_DeleteV1_Success() { var data = new TestDataFactory(UoW); data.Destroy(); data.CreateLogins(); var login = UoW.Logins.Get(QueryExpressionFactory.GetQueryExpression <E_Login>() .Where(x => x.Name == TestDefaultConstants.LoginName).ToLambda()) .Single(); UoW.Logins.Delete(login); UoW.Commit(); }
public async Task <ActionResult> AddMultiple(IEnumerable <Customer> customers) { if (customers != null) { UoW.Customers.AddRange(customers); await UoW.Complete(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Index")); } }
public void Repo_MOTDs_DeleteV1_Success() { var data = new TestDataFactory(UoW); data.Destroy(); data.CreateMOTDs(); var MOTD = UoW.MOTDs.Get(QueryExpressionFactory.GetQueryExpression <uvw_MOTD>() .Where(x => x.Author == TestDefaultConstants.MOTDAuthor).ToLambda()) .First(); UoW.MOTDs.Delete(MOTD); UoW.Commit(); }
public async Task<ActionResult> AddMultiple(IEnumerable<SalesInvoice> invoices) { if (invoices != null) { UoW.SalesInvoices.AddRange(invoices); await UoW.Complete(); return RedirectToAction("Index"); } else { return RedirectToAction("Index"); } }
public void CompleteSelectedTasks(object[] selectedObjs) { var nodes = selectedObjs.OfType <BusinessTaskJournalNode>().ToLookup(key => key.EntityType, val => val.Id); foreach (var tasks in nodes) { foreach (int task in tasks) { Type type = tasks.Key; var obj = UoW.GetById(type, task); } } }
public void ExceptionErrorIsReturned() { // Assemble var request = TestData.GetDeleteCompanyProductRequest(); UoW.Setup(m => m.Save()) .Throws <Exception>(); // Act var result = Subject.DeleteCompanyProduct(request); // Assert Assert.Contains(typeof(ExceptionError), result.Errors.Select(e => e.GetType()).ToList()); }
public ProjectDTO Update(int id, ProjectDTO projectDto) { using (UoW) { Project project = UoW.Projects.Get(id); if (project == null) { throw new ApplicationOperationException(string.Format("Project with id {0} not found", id), HttpStatusCode.NotFound); } UoW.Projects.Update(project, projectDto); UoW.Complete(); return(Mapper.Map <ProjectDTO>(project)); } }
public CashFlow(ISubdivisionRepository subdivisionRepository, ICommonServices commonServices) { this.Build(); this.subdivisionRepository = subdivisionRepository ?? throw new ArgumentNullException(nameof(subdivisionRepository)); this.commonServices = commonServices ?? throw new ArgumentNullException(nameof(commonServices)); UoW = UnitOfWorkFactory.CreateWithoutRoot(); comboPart.ItemsEnum = typeof(ReportParts); comboIncomeCategory.ItemsList = CategoryRepository.IncomeCategories(UoW); comboExpenseCategory.Sensitive = comboIncomeCategory.Sensitive = false; var now = DateTime.Now; dateStart.Date = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0); dateEnd.Date = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59); var filterCasher = new EmployeeFilterViewModel(); filterCasher.SetAndRefilterAtOnce(x => x.RestrictCategory = EmployeeCategory.office); filterCasher.Status = EmployeeStatus.IsWorking; yentryrefCasher.RepresentationModel = new EmployeesVM(filterCasher); yentryrefEmployee.RepresentationModel = new EmployeesVM(); var recurciveConfig = OrmMain.GetObjectDescription <ExpenseCategory>().TableView.RecursiveTreeConfig; var list = CategoryRepository.ExpenseCategories(UoW); list.Insert(0, allItem); var model = recurciveConfig.CreateModel((IList)list); comboExpenseCategory.Model = model.Adapter; comboExpenseCategory.PackStart(new CellRendererText(), true); comboExpenseCategory.SetCellDataFunc(comboExpenseCategory.Cells[0], HandleCellLayoutDataFunc); comboExpenseCategory.SetActiveIter(model.IterFromNode(allItem)); UserSubdivisions = GetSubdivisionsForUser(); specialListCmbCashSubdivisions.SetRenderTextFunc <Subdivision>(s => s.Name); specialListCmbCashSubdivisions.ItemsList = UserSubdivisions; ylblOrganisations.Visible = specialListCmbOrganisations.Visible = false; Organisations = UoW.GetAll <Organization>(); specialListCmbOrganisations.SetRenderTextFunc <Organization>(s => s.Name); specialListCmbOrganisations.ItemsList = Organisations; int currentUserId = commonServices.UserService.CurrentUserId; bool canCreateCashReportsForOrganisations = commonServices.PermissionService.ValidateUserPresetPermission("can_create_cash_reports_for_organisations", currentUserId); checkOrganisations.Visible = canCreateCashReportsForOrganisations; checkOrganisations.Toggled += CheckOrganisationsToggled; }
public async Task <List <Dish> > GetDishListFromFilter(bool isFav, decimal maxPrice, int minLikes, string searchBy, IList <long> categoryIdList, long userId) { var includeList = new List <string> { "DishCategory", "DishCategory.IdCategoryNavigation", "DishIngredient", "DishIngredient.IdIngredientNavigation", "IdImageNavigation" }; var result = await UoW.Repository <Dish>().GetAllIncludeAsync(includeList); if (isFav && userId >= 0) { //var dishes = result; if (result != null) { var favourites = result.SelectMany(f => f.UserFavourite).Select(f => f.Id).ToList(); if (favourites.Any()) { result = result.Where(r => favourites.Contains(r.Id)).ToList(); } } } if (categoryIdList.Any()) { result = result.Where(r => r.DishCategory.Any(a => categoryIdList.Contains(a.IdCategory))).ToList(); } if (!string.IsNullOrEmpty(searchBy)) { var criteria = searchBy.ToLower(); result = result.Where(d => d.Name.ToLower().Contains(criteria) || d.Description.ToLower().Contains(criteria)).ToList(); } //todo twitter if (minLikes > 0) { } if (maxPrice > 0) { result = result.Where(r => r.Price <= maxPrice).ToList(); } var c = result.ToList(); //PopulateDishReferences(ref c); return(result.ToList()); }
private void CreateOrderExtraIngredient(IList <KeyValuePair <OrderLine, List <Extra> > > orderLinesItems) { foreach (var orderLine in orderLinesItems) { foreach (var extra in orderLine.Value) { UoW.Repository <OrderDishExtraIngredient>().Create(new OrderDishExtraIngredient { IdIngredient = extra.id, IdOrderLine = orderLine.Key.Id }); } } UoW.Commit(); }
public bool AddOrUpdateTransaction(TRANSACTION transaction) { if (transaction.PK_ID_TRANSACTION != 0) { UoW.TRANSACTION_Repository.Update(transaction); UoW.Save(); return(true); } else { UoW.TRANSACTION_Repository.Insert(transaction); UoW.Save(); return(true); } }
public async Task <ActionResult> Create(ProductionModel production) { if (!ModelState.IsValid) { return(View()); } else { UoW.Productions.Add(production.Production); UoW.Ingredients.AddRange(production.Items); await UoW.Complete(); return(RedirectToAction("Index")); } }
public LinkModel Add(LinkModel entity) { try { _repo.Add(_mapper.Map <Link>(entity)); UoW.Commit(); return(entity); } catch (Exception) { UoW.RollBack(); return(null); } }
void CompleteAllocation() { var distributedPayments = PaymentsRepository.GetAllDistributedPayments(UoW); if (distributedPayments.Any()) { foreach (var payment in distributedPayments) { payment.Status = PaymentState.completed; UoW.Save(payment); } UoW.Commit(); } }
public bool AddOrUpdateUser(USER user) { if (user.PK_ID_USER != 0) { UoW.USER_Repository.Update(user); UoW.Save(); return(true); } else { UoW.USER_Repository.Insert(user); UoW.Save(); return(true); } }
public override void Destroy() { logger.Debug("OrmReference #{0} Destroy() called.", number); IOrmObjectMapping map = OrmMain.GetObjectDescription(objectType); if (map != null) { map.ObjectUpdated -= OnRefObjectUpdated; } if (isOwnerUow) { UoW.Dispose(); } base.Destroy(); }
public override bool Save() { var valid = new QSValidator <Subdivision>(UoWGeneric.Root); if (valid.RunDlgIfNotValid((Gtk.Window) this.Toplevel)) { return(false); } UoWGeneric.Save(); subdivisionentitypermissionwidget.ViewModel.SavePermissions(UoW); presetPermissionVM.SaveCommand.Execute(); UoW.Commit(); return(true); }
public NormViewModel( IEntityUoWBuilder uowBuilder, IUnitOfWorkFactory unitOfWorkFactory, EmployeeIssueRepository employeeIssueRepository, INavigationManager navigation, IInteractiveQuestion interactive, IValidator validator = null) : base(uowBuilder, unitOfWorkFactory, navigation, validator) { this.employeeIssueRepository = employeeIssueRepository ?? throw new ArgumentNullException(nameof(employeeIssueRepository)); employeeIssueRepository.RepoUow = UoW; this.interactive = interactive; NormConditions = UoW.GetAll <NormCondition>().ToList(); NormConditions.Insert(0, null); }
public void GenerateLicenseValue(LicensePoco licensepoco) { var tempProduct = licensepoco.Product; var tempCustomer = licensepoco.Customer; if (tempProduct == null) { using (var uow = new UoW()) { tempProduct = uow.Products.GetByKey(licensepoco.ProductId); } } if (tempCustomer == null) { using (var uow = new UoW()) { tempCustomer = uow.Customers.GetByKey(licensepoco.CustomerId); } } var license = License.New(); var productFeatures = new Dictionary<string, string> { {"FirstName", tempCustomer.FirstName}, {"LastName", tempCustomer.LastName}, {"Email", tempCustomer.Email} }; if (licensepoco.ExpireDate != null) { license = license.ExpiresAt((DateTime) licensepoco.ExpireDate); } if (licensepoco.ExpireVersion != null) { productFeatures.Add("Version", licensepoco.ExpireVersion.ToString()); } var finalLicense = license.WithUniqueIdentifier(Guid.NewGuid()) .As(LicenseType.Standard) .WithMaximumUtilization(1) .WithProductFeatures(productFeatures) .CreateAndSignWithPrivateKey(tempProduct.PrivateKey, tempProduct.PassPhrase); licensepoco.Value = finalLicense.ToString(); }
public void For_An_Invalid_Type_Must_Return_NULL_Repository() { // // Arrange // var mockContext = new Mock<EFDbContext>(); var mockRepoFactory = new Mock<IRepositoryFactory>(); mockRepoFactory.Setup(x => x.GetRepository<IModel>()).Returns((IRepository<IModel>) null); var uow = new UoW(mockContext.Object, mockRepoFactory.Object); // // Act // var result = uow.GetRepository<IModel>(); // // Assert // Assert.IsNull(result); }
// GET: /Product/Details/5 public ActionResult Details(int? id) { Log.Debug("GET/Details id: {0}", id.ToString()); if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Product product = null; using (var uow = new UoW()) { var productsRepo = uow.GetRepository<IProductRepository>(); product = productsRepo.GetByKey((System.Int32) id); } if (product == null) { return HttpNotFound(); } return View(product); }
// GET: /License/Details/5 public ActionResult Details(int? id) { Log.Debug("GET/Details id: {0}", id.ToString()); if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } LicensePoco licensepoco = null; using (var uow = new UoW()) { var licensesRepo = uow.GetRepository<ILicensePocoRepository>(); // licensepoco = licensesRepo.GetByKey((System.Int32) id); // Geert mayby add include? licensepoco = licensesRepo.GetQuery().Include(x=>x.Customer).Include(x=>x.Product).FirstOrDefault(x => x.Id == (System.Int32) id); } if (licensepoco == null) { return HttpNotFound(); } return View(licensepoco); }
public void For_A_Valid_Type_Must_Return_Repository_With_UoW() { // // Arrange // var mockRepository = new Mock<IRepository<IModel>>(); var mockContext = new Mock<EFDbContext>(); var mockRepoFactory = new Mock<IRepositoryFactory>(); mockRepoFactory.Setup(x => x.GetRepository<IModel>()).Returns(mockRepository.Object); var uow = new UoW(mockContext.Object, mockRepoFactory.Object); // // Act // var result = uow.GetRepository<IModel>(); // // Assert // Assert.IsNotNull(result); mockRepository.VerifySet(x=>x.UoW = It.IsAny<IUoW>(), Times.Once()); }
public ActionResult Create([Bind(Include = "Id,Name,PassPhrase,PrivateKey,PublicKey,CreationDate,CreatorId")] Product product) { Log.Debug("POST/Create"); if (ModelState.IsValid) { using (var uow = new UoW()) { var productsRepo = uow.GetRepository<IProductRepository>(); _licenseGenerationService.GeneratePassPhraseForProduct(product); _licenseGenerationService.GenerateKeysForProduct(product); productsRepo.Add(product); uow.SaveChanges(); } return RedirectToAction("Index"); } return View(product); }
public void When_Exception_Occured_Must_Return_DataResult_With_Exception() { // // Arrange // var mockContext = new Mock<EFDbContext>(); var mockRepoFactory = new Mock<IRepositoryFactory>(); Action action = () => { throw new Exception(); }; var uow = new UoW(mockContext.Object, mockRepoFactory.Object); // // Act // var result = uow.Commit(action); // // Assert // mockContext.Verify(x=>x.SaveChanges(), Times.Never); Assert.IsNotNull(result); Assert.IsNotNull(result.Exception); }
public ActionResult DeleteConfirmed(int id) { Log.Debug("POST/DeleteConfirmed Id:{0}", id.ToString()); using (var uow = new UoW()) { var productsRepo = uow.GetRepository<IProductRepository>(); var product = productsRepo.GetByKey((System.Int32) id); productsRepo.Delete(product); uow.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Edit([Bind(Include = "Id,Name,PassPhrase,PrivateKey,PublicKey,CreationDate,CreatorId")] Product product) { Log.Debug("POST/Edit"); if (ModelState.IsValid) { using (var uow = new UoW()) { var productsRepo = uow.GetRepository<IProductRepository>(); var modifyproduct = productsRepo.GetByKey(product.Id); modifyproduct.Name = product.Name; productsRepo.Update(modifyproduct); uow.SaveChanges(); return RedirectToAction("Details", new { @id = product.Id}); } } return View(product); }
// GET: /License/Edit/5 //public ActionResult Edit(int? id) //{ // Log.Debug("GET/Edit id:{0}", id.ToString()); // if (id == null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } // LicensePoco licensepoco = null; // using (var uow = new UoW()) // { // var licensesRepo = uow.GetRepository<ILicensePocoRepository>(); // licensepoco = licensesRepo.GetByKey((System.Int32) id); // } // if (licensepoco == null) // { // return HttpNotFound(); // } // using (var uow = new UoW()) // { // ViewBag.CustomerId = new SelectList(uow.Customers.GetAll().ToList(), "Id", "FirstName"); // ViewBag.ProductId = new SelectList(uow.Products.GetAll().ToList(), "Id", "Name"); // } // return View(licensepoco); //} //// POST: /License/Edit/5 //// To protect from overposting attacks, please enable the specific properties you want to bind to, for //// more details see http://go.microsoft.com/fwlink/?LinkId=317598. //[HttpPost] //[ValidateAntiForgeryToken] //public ActionResult Edit([Bind(Include = "Id,Value,ExpireVersion,ExpireDate,CustomerId,ProductId,CreatorId,ModificationDate,CreationDate")] LicensePoco licensepoco) //{ // Log.Debug("POST/Edit"); // if (ModelState.IsValid) // { // using (var uow = new UoW()) // { // var licensesRepo = uow.GetRepository<ILicensePocoRepository>(); // licensesRepo.Update(licensepoco); // uow.SaveChanges(); // } // } // using (var uow = new UoW()) // { // ViewBag.CustomerId = new SelectList(uow.Customers.GetAll().ToList(), "Id", "FirstName"); // ViewBag.ProductId = new SelectList(uow.Products.GetAll().ToList(), "Id", "Name"); // } // return View(licensepoco); //} // GET: /License/Delete/5 public ActionResult Delete(int? id) { Log.Debug("GET/Delete Id:{0}, id.ToString()"); if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } LicensePoco licensepoco = null; using (var uow = new UoW()) { var licensesRepo = uow.GetRepository<ILicensePocoRepository>(); licensepoco = licensesRepo.GetByKey((System.Int32) id); } if (licensepoco == null) { return HttpNotFound(); } return View(licensepoco); }
public ActionResult Create([Bind(Include = "Id,Value,ExpireVersion,ExpireDate,CustomerId,ProductId,CreatorId,ModificationDate,CreationDate")] LicensePoco licensepoco) { Log.Debug("POST/Create"); if (ModelState.IsValid) { _licenseGenerationService.GenerateLicenseValue(licensepoco); using (var uow = new UoW()) { var licensesRepo = uow.GetRepository<ILicensePocoRepository>(); licensesRepo.Add(licensepoco); uow.SaveChanges(); } return RedirectToAction("Index"); } using (var uow = new UoW()) { ViewBag.CustomerId = JsonConvert.SerializeObject(uow.Customers.GetAll().ToList()); // new SelectList(uow.Customers.GetAll().ToList(), "Id", "FirstName"); ViewBag.ProductId = JsonConvert.SerializeObject(uow.Products.GetAll().ToList());//new SelectList(uow.Products.GetAll().ToList(), "Id", "Name"); } return View(licensepoco); }
public void Get_For_A_NULL_Filter_Must_Return_All() { // // Arrange // var mockedList = Enumerable.Range(1, 10).Select(x => { var mockModel = new Mock<IModel>(); mockModel.Setup(y => y.Id).Returns(x); return mockModel.Object; }).AsQueryable(); var mockRepository = new Mock<IRepository<IModel>>(); mockRepository.Setup(x => x.GetAll()).Returns(mockedList); var mockContext = new Mock<EFDbContext>(); var mockRepoFactory = new Mock<IRepositoryFactory>(); mockRepoFactory.Setup(x => x.GetRepository<IModel>()).Returns(mockRepository.Object); var mockedUoW = new UoW(mockContext.Object, mockRepoFactory.Object); Expression<Func<IModel, bool>> filterExpression = null; // // Act // var results = mockedUoW.Get(filterExpression); // // Assert // Assert.IsNotNull(results); Assert.AreEqual(results.Count(), 10); Assert.AreEqual(results.First().Id, 1); }
public ActionResult DeleteConfirmed(int id) { Log.Debug("POST/DeleteConfirmed Id:{0}", id.ToString()); using (var uow = new UoW()) { var licensesRepo = uow.GetRepository<ILicensePocoRepository>(); var licensepoco = licensesRepo.GetByKey((System.Int32) id); licensesRepo.Delete(licensepoco); uow.SaveChanges(); } return RedirectToAction("Index"); }
public void Get_For_Invalid_Repository_Must_Return_NULL() { // // Arrange // var mockedList = Enumerable.Range(1, 10).Select(x => { var mockModel = new Mock<IModel>(); mockModel.Setup(y => y.Id).Returns(x); return mockModel.Object; }).AsQueryable(); var mockRepository = new Mock<IRepository<IModel>>(); mockRepository.Setup(x => x.GetAll()).Returns(mockedList); var mockContext = new Mock<EFDbContext>(); var mockRepoFactory = new Mock<IRepositoryFactory>(); mockRepoFactory.Setup(x => x.GetRepository<IModel>()).Returns<IModel>(null); var mockedUoW = new UoW(mockContext.Object, mockRepoFactory.Object); Expression<Func<IModel, bool>> filterExpression = x => x.Id == 1; // // Act // var results = mockedUoW.Get(filterExpression); // // Assert // Assert.IsNull(results); }
public void When_Passed_An_Action_To_Commit_That_Action_Must_Execute() { // // Arrange // var mockContext = new Mock<EFDbContext>(); var mockRepoFactory = new Mock<IRepositoryFactory>(); var mockAction = new Mock<Action>(); var uow = new UoW(mockContext.Object, mockRepoFactory.Object); // // Act // uow.Commit(mockAction.Object); // // Assert // mockAction.Verify(x => x(), Times.Once); }