public void Orderlines_OrderlinesIsCalled_IsTypeOfDbSetOrderlines() { using (var uut = new CashRegisterContext()) { Assert.That(uut.OrderLines, Is.TypeOf<DbSet<OrderLine>>()); } }
public void Orderlines_OrderlinesIsCalled_RepositoryIsEmpty() { using (var uut = new CashRegisterContext()) { Assert.That(uut.OrderLines, Is.Empty); } }
public void Discounts_DiscountsIsCalled_IsTypeOfDbSetDiscount() { using (var uut = new CashRegisterContext()) { Assert.That(uut.Discounts, Is.TypeOf<DbSet<Discount>>()); } }
public void Products_ProductsIsCalled_IsTypeOfDbSetProducts() { using (var uut = new CashRegisterContext()) { Assert.That(uut.Products, Is.TypeOf<DbSet<Product>>()); } }
public void Products_ProductsIsCalled_RepositoryIsEmpty() { using (var uut = new CashRegisterContext()) { Assert.That(uut.Products, Is.Empty); } }
public InitHelper(CashRegisterContext context) { _context = context; _groups = new List <ProductGroup>(); _tabs = new List <ProductTab>(); _products = new List <Product>(); _types = new List <ProductType>(); }
public void SetUp() { using (var uut = new CashRegisterContext()) { if (uut.Database.Exists()) uut.Database.Delete(); } }
public void GetById_ProductWithId1IsRequestedWithNoProductsInDb_NoProductIsReturnedFromDb() { using (var context = new CashRegisterContext()) { var uut = new Repository<Product>(context); var result = uut.GetById((long)1); Assert.That(result, Is.EqualTo(null)); } }
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); } }
protected override void Seed(CashRegisterContext context) { var s = new InitHelper(context); s.AddTab("Øl fane", 0, "Green"); s.AddType("Billig Øl", 12, "Yellow"); s.AddGroup("Billig Øl Gruppe"); s.AddProduct("Top"); s.AddGroup("Billig Øl Gruppe 2"); s.AddProduct("Classic"); s.AddTab("Drinks", 1, "Blue"); s.AddType("Billig Drinks", 20, "Orange"); s.AddGroup("Billig Drinks"); s.AddProduct("Tequilla Sunrise"); s.AddProduct("Vodka Juice", 20, false); s.Save(); base.Seed(context); }
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_ProductsIsRequestedWhenNoProductsInDb_ProductPriceIsInCollectionFromDb() { using (var context = new CashRegisterContext()) { var uut = new Repository<Product>(context); var result = uut.Get(); Assert.That(result, Is.Empty); } }
public void Transactions_TransactionsIsCalled_RepositoryIsEmpty() { using (var uut = new CashRegisterContext()) { Assert.That(uut.Transactions, Is.Empty); } }
public void Transactions_TransactionsIsCalled_IsTypeOfDbSetTransaction() { using (var uut = new CashRegisterContext()) { Assert.That(uut.Transactions, Is.TypeOf<DbSet<Transaction>>()); } }
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 SalesOrders_SalesOrdersIsCalled_RepositoryIsEmpty() { using (var uut = new CashRegisterContext()) { Assert.That(uut.SalesOrders, Is.Empty); } }
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)); } }
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"); }
/// <summary> /// Constructor /// </summary> /// <param name="context">The database context to work on</param> /// <param name="controller">The facade that owns this unit of work</param> public UnitOfWork(CashRegisterContext context, IDalFacade controller) { _context = context; _controller = controller; }
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 SalesOrders_SalesOrdersIsCalled_IsTypeOfDbSetSalesOrder() { using (var uut = new CashRegisterContext()) { Assert.That(uut.SalesOrders, Is.TypeOf<DbSet<SalesOrder>>()); } }
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); } }
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)); } }