public void GetById_ProductWithId1IsRequested_ProductIsReturnedFromDbNameIsEqual() { var testProduct = new Product("Kildevand", 18, true); using (var context = new CashRegisterContext()) { context.Products.Add(testProduct); context.SaveChanges(); } using (var context = new CashRegisterContext()) { var uut = new Repository<Product>(context); var result = uut.GetById((long)1); Assert.That(result.Name, Is.EqualTo("Kildevand")); } }
public void Delete_ProductIsDeleted_NoProductsInDatabase() { var testProduct = new Product("Kildevand", 18, true); using (var context = new CashRegisterContext()) { context.Products.Add(testProduct); context.SaveChanges(); } using (var context = new CashRegisterContext()) { var uut = new Repository<Product>(context); uut.Delete(testProduct); context.SaveChanges(); var result = context.Products.AsEnumerable(); Assert.That(result, Is.Empty); } }
private static void Main(string[] args) { _logger = LogFactory.GetLogger(typeof (Program)); IDatabaseInitializer<CashRegisterContext> seed; // Empty // seed = new EmptyInitializer(); // Kalle Seed //seed = new CashProductInitializer(); // Lærke Seed seed = new FullProductInitializer(); using (var contex = new CashRegisterContext(seed)) { Console.WriteLine("FLAF"); contex.Database.Initialize(true); contex.SaveChanges(); } IDalFacade dalFacade = new DalFacade(); IProductDao pd = new ProductDao(dalFacade); IProductController pc = new ProductController(pd); SalesOrder o; using (var uow = dalFacade.UnitOfWork) { var d = new Discount { Description = "Discount", Percent = 0, }; uow.DiscountRepository.Insert(d); uow.Save(); o = new SalesOrder { Date = DateTime.Now, Status = OrderStatus.Created, }; uow.SalesOrderRepository.Insert(o); } using (var uow = dalFacade.UnitOfWork) { var t = new Transaction { Date = DateTime.Now, Description = "Flaf", PaymentType = PaymentType.Cash, Price = 20, SalesOrder = o, Status = TransactionStatus.Created }; uow.TransactionRepository.Insert(t); uow.Save(); } Console.WriteLine("ProductTabs"); foreach (var productTab in pc.ProductTabs) { Console.WriteLine(productTab.Priority + ": " + productTab.Name); foreach (var productType in productTab.ProductTypes) { Console.WriteLine("\t" + productType.Name); foreach (var productGroup in productType.ProductGroups) { Console.WriteLine("\t\t" + productGroup.Name); foreach (var product in productGroup.Products) { Console.WriteLine("\t\t\t" + product.Name); } } } } _logger.Fatal("Fatal"); _logger.Err("Error"); _logger.Warn("Warn"); _logger.Info("Info"); _logger.Debug("Debug"); }
public void Update_ProductIsUpdated_UpdatedProductCanBeFoundInDb() { var testProduct = new Product("Kildevand", 18, true); using (var context = new CashRegisterContext()) { context.Products.Add(testProduct); context.SaveChanges(); } using (var context = new CashRegisterContext()) { var uut = new Repository<Product>(context); var modifiedProduct = context.Products.FirstOrDefault(p => p.Id == 1); modifiedProduct.Price = 20; uut.Update(modifiedProduct); context.SaveChanges(); } using (var context = new CashRegisterContext()) { var modifiedProduct = context.Products.FirstOrDefault(p => p.Id == 1); var result = context.Products.FirstOrDefault(p => p.Id == 1); Assert.That(modifiedProduct.Price, Is.EqualTo(20)); } }
public void Insert_ProductIsInserted_ProductCanBeFoundInDb() { var product = new Product("Øl", 20, true); using (var context = new CashRegisterContext()) { var uut = new Repository<Product>(context); uut.Insert(product); context.SaveChanges(); var result = context.Products.FirstOrDefault(p => p.Id == 1); Assert.That(result, Is.EqualTo(product)); } }
public void Get_ProductsIsRequested_ProductPriceIsInCollectionFromDb() { var testProduct = new Product("Kildevand", 18, true); using (var context = new CashRegisterContext()) { context.Products.Add(testProduct); context.SaveChanges(); } using (var context = new CashRegisterContext()) { var uut = new Repository<Product>(context); var result = uut.Get().ElementAt(0); Assert.That(result.Price, Is.EqualTo(18)); } }
public void Get_ProductIsRequestedWithWhereClause_ProductId2IsReturned() { var testProduct1 = new Product("Kildevand", 18, true); var testProduct2 = new Product("Øl", 20, false); using (var context = new CashRegisterContext()) { context.Products.Add(testProduct1); context.Products.Add(testProduct2); context.SaveChanges(); } using (var context = new CashRegisterContext()) { var uut = new Repository<Product>(context); var result = uut.Get(x => x.Id == 2).ElementAt(0); Assert.That(result.Name, Is.EqualTo("Øl")); } }
public void Get_ProductIsRequestedWithFilteredClauseWithoutLazyLoading_ProductCollectionContainsNoProductList() { var testProduct1 = new Product("Kildevand", 18, true); var testProduct2 = new Product("Øl", 20, false); var testProductGroup = new ProductGroup() { Name = "Drikkevarer" }; testProductGroup.Products.Add(testProduct1); testProductGroup.Products.Add(testProduct2); using (var context = new CashRegisterContext()) { context.ProductGroups.Add(testProductGroup); context.SaveChanges(); } using (var context = new CashRegisterContext()) { context.Configuration.LazyLoadingEnabled = false; var uut = new Repository<ProductGroup>(context); var result = uut.Get().ElementAt(0); Assert.That(result.Products.Count, Is.EqualTo(0)); } }
public void Get_ProductIsRequestedWithEmptyFilteredClause_ArgumentExceptionIsThrown() { var testProduct1 = new Product("Kildevand", 18, true); var testProduct2 = new Product("Øl", 20, false); var testProductGroup = new ProductGroup() { Name = "Drikkevarer" }; testProductGroup.Products.Add(testProduct1); testProductGroup.Products.Add(testProduct2); using (var context = new CashRegisterContext()) { context.ProductGroups.Add(testProductGroup); context.SaveChanges(); } using (var context = new CashRegisterContext()) { var uut = new Repository<ProductGroup>(context); var filter = new[] { "" }; Assert.That(() => uut.Get(null, null, filter).ElementAt(0), Throws.ArgumentException); } }