private static void FillAllTables() { CategoryRepository categoryRepository = new CategoryRepository(); categoryRepository.Add(firstCategory); categoryRepository.Add(secondCategory); ItemRepository itemRepository = new ItemRepository(); itemRepository.Add(firstItem); itemRepository.Add(secondItem); itemRepository.Add(thirdItem); itemRepository.Add(fourthItem); itemRepository.Add(fifthItem); UserRepository userRepository = new UserRepository(); userRepository.Add(firstUser); userRepository.Add(secondUser); UsersItemsRepository usersItemsRepository = new UsersItemsRepository(); usersItemsRepository.Add(firstUsersItems); usersItemsRepository.Add(secondUsersItems); usersItemsRepository.Add(thirdUsersItems); usersItemsRepository.Add(fourthUsersItems); usersItemsRepository.Add(fifthUsersItems); }
public Receipt SetupReceipt() { var testItemRepository = new ItemRepository(); testItemRepository.Add("Milk", 2.49); testItemRepository.Add("Rotini", 5.49); testItemRepository.Add("TomatoSoup", .49); testItemRepository.Add("PeanutButter", 1.25); testItemRepository.Add("Bread", 2.50); testItemRepository.Add("GroundBeef", 1.99, 1); testItemRepository.Add("Salmon", 9.99, 1); testItemRepository.Add("Soda", 5.69); testItemRepository.Add("OysterCrackers", 2.09); testItemRepository.Add("Pork", 2, 1); testItemRepository.Markdown("Salmon", 1.99); testItemRepository.BuyNumberGetNumberAtDiscountPercentLimitNumber("PeanutButter", 2, 1, 1, 3); testItemRepository.BuyNumberGetNumberAtDiscountPercentLimitNumber("Soda", 2, 1, 1, 6); testItemRepository.BuyNumberGetNumberAtDiscountPercentLimitNumber("Bread", 4, 2, .50, 12); testItemRepository.BuyGroupAtReducedPrice("OysterCrackers", 3, 5); testItemRepository.BuyNumberGetNumberAtDiscountPercentLimitNumber("Pork", 4, 1, .5, 5); testItemRepository.SetEqualOrLesserAmount("Pork"); return(new Receipt(testItemRepository)); }
public void CanFindMultipleItemsByPredicate() { var item = GenerateItem(); var item2 = GenerateItem(); var item3 = GenerateItem(); item2.Price = 25.00; item3.Price = 15.00; using (var context = new ApiContext(Options)) { var itemRepository = new ItemRepository(context); itemRepository.Add(item); itemRepository.Add(item2); itemRepository.Add(item3); itemRepository.Commit(); var items = itemRepository.FindBy(i => i.Price >= 11.00); Assert.NotNull(items); Assert.Equal(2, items.Count()); Assert.DoesNotContain(item, items); Assert.Contains(item2, items); Assert.Contains(item3, items); } }
public void ItemAddedTwiceUpdatesToNewPriceAndDoesNotAddASecondItem() { var itemRepository = new ItemRepository(); decimal expectedPrice = 1.49m; int expectedItemCount = 1; itemRepository.Add("TomatoSoup", .49); itemRepository.Add("TomatoSoup", 1.49); Assert.AreEqual(expectedPrice, itemRepository.PriceCheck("TomatoSoup")); Assert.AreEqual(expectedItemCount, itemRepository.Count); }
public JsonResult Publish(string html, string image) { var item = _itemRepository.Add(new Item { Text = html, Ip = Request.UserHostAddress, Image = image, Description = String.Empty // reserved }); return(Json(item)); }
public HttpResponseMessage UpsertItem(HttpRequestMessage request, tbItem tbItem) { ItemRepository itemRepo = new ItemRepository(); StockRepository stockRepo = new StockRepository(); tbItem UpdatedEntity = null; tbStock tbstock = new tbStock(); if (tbItem.ID > 0) { UpdatedEntity = itemRepo.update(tbItem); } else { tbItem.UniqueID = Guid.NewGuid(); tbItem.IsDeleted = false; tbItem.Accesstime = DateTime.UtcNow.ToLocalTime(); UpdatedEntity = itemRepo.Add(tbItem); tbstock.ItemGUID = tbItem.UniqueID; tbstock.CinemaID = 0; tbstock.IsDeleted = false; tbstock.Accesstime = DateTime.UtcNow.ToLocalTime(); tbstock.StockStatus = "Stock Register"; tbstock.StockQty = 0; tbstock.ThresholdQty = 0; stockRepo.Add(tbstock); } return(request.CreateResponse <tbItem>(HttpStatusCode.OK, UpdatedEntity)); }
public void Add_Returns_1_When_Adding_Valid_RentalOrder() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var userRepository = new UserRepository(context); var rentalOrderRepository = new RentalOrderRepository(context); var rentalOrderLineRepository = new RentalOrderLineRepository(context); //Act var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItem); var user = UserFactory.CreateValidEntity(); userRepository.Add(user); var rentalOrder = RentalOrderFactory.CreateValidEntity(user); rentalOrderRepository.Add(rentalOrder); var rentalOrderLine = RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem); rentalOrderLineRepository.Add(rentalOrderLine); var result = context.SaveChanges(); //Assert Assert.AreEqual(5, result); //Because we added five entities } }
public async Task should_add_new_item() { var testItem = new Item { Name = "Test album", Description = "Description", LabelName = "Label name", Price = new Price { Amount = 13, Currency = "EUR" }, PictureUri = "https://mycdn.com/pictures/32423423", ReleaseDate = DateTimeOffset.Now, Format = "Vinyl 33g", AvailableStock = 6, GenreId = new Guid("c04f05c0-f6ad-44d1-a400-3375bfb5dfd6"), ArtistId = new Guid("f08a333d-30db-4dd1-b8ba-3b0473c7cdab") }; _sut.Add(testItem); await _sut.UnitOfWork.SaveEntitiesAsync(); _context.Items .FirstOrDefault(item => item.Id == testItem.Id) .ShouldNotBeNull(); }
public void Remove_Deletes_Item() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItemToAdd = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItemToAdd); var rentalItemId = rentalItemToAdd.Id; context.SaveChanges(); //Act rentalItemRepository.Remove(rentalItemToAdd); context.SaveChanges(); var rentalItem = rentalItemRepository.Get(rentalItemId); //Assert Assert.IsNull(rentalItem); } }
public bool TryAddItem(Item item, Expression <Func <Item, bool> > searchExpression) { ResolveLocker(typeof(Item)).EnterWriteLock(); try { var searchedItem = GetEntity(searchExpression, ItemRepository); if (searchedItem != null) { return(false); } ItemRepository.Add(new EF.Item { Name = item.Name }); ItemRepository.Save(); return(true); } catch (Exception) { throw new ObjectAdditionException(item); } finally { ResolveLocker(typeof(Item)).ExitWriteLock(); } }
public void Get_Returns_RentalOrder_When_Found() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var userRepository = new UserRepository(context); var rentalOrderRepository = new RentalOrderRepository(context); var rentalOrderLineRepository = new RentalOrderLineRepository(context); var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItem); var user = UserFactory.CreateValidEntity(); userRepository.Add(user); var rentalOrder = RentalOrderFactory.CreateValidEntity(user); rentalOrderRepository.Add(rentalOrder); var rentalOrderLineToAdd = RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem); rentalOrderLineRepository.Add(rentalOrderLineToAdd); context.SaveChanges(); //Act var rentalOrderLine = rentalOrderLineRepository.Get(rentalOrderLineToAdd.Id); //Assert Assert.IsNotNull(rentalOrderLine); } }
public async Task should_add_new_item(string jsonEntity) { var entity = JsonConvert.DeserializeObject <Item>(jsonEntity); var options = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: "should_add_new_items") .Options; using (var context = new TestCatalogContext(options)) { context.Database.EnsureCreated(); } using (var context = new TestCatalogContext(options)) { var sut = new ItemRepository(context); sut.Add(entity); await sut.UnitOfWork.SaveEntitiesAsync(); } using (var context = new TestCatalogContext(options)) { context.Items .FirstOrDefault(_ => _.Id == entity.Id) .ShouldNotBeNull(); } }
public void Remove_Throws_Exception_When_Not_Found() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var userRepository = new UserRepository(context); var rentalOrderRepository = new RentalOrderRepository(context); var rentalOrderLineRepository = new RentalOrderLineRepository(context); var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItem); var user = UserFactory.CreateValidEntity(); userRepository.Add(user); var rentalOrder = RentalOrderFactory.CreateValidEntity(user); rentalOrderRepository.Add(rentalOrder); var rentalOrderLineToAdd = RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem); rentalOrderLineRepository.Add(rentalOrderLineToAdd); context.SaveChanges(); //Act rentalOrderLineRepository.Remove(RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem)); context.SaveChanges(); //Assert } }
public async Task should_add_new_item() { var testItem = new Item { Name = "Test album", Description = "Description", LabelName = "Label name", Price = new Price { Amount = 13, Currency = "EUR" }, PictureUri = "https://mycdn.com/pictures/32423423", ReleaseDate = DateTimeOffset.Now, AvailableStock = 6, GenreId = new Guid("c04f05c0-f6ad-44d1-a400-3375bfb5dfd6"), ArtistId = new Guid("f08a333d-30db-4dd1-b8ba-3b0473c7cdab") }; var options = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase("should_add_new_items") .Options; await using var context = new TestCatalogContext(options); context.Database.EnsureCreated(); var sut = new ItemRepository(context); sut.Add(testItem); await sut.UnitOfWork.SaveEntitiesAsync(); context.Items .FirstOrDefault(_ => _.Id == testItem.Id) .ShouldNotBeNull(); }
public void GetAll_Returns_10_RentalOrders() { using (var context = new VivesRentalDbContext()) { //Arrange var itemRepository = new ItemRepository(context); var rentalItemRepository = new RentalItemRepository(context); var userRepository = new UserRepository(context); var rentalOrderRepository = new RentalOrderRepository(context); var rentalOrderLineRepository = new RentalOrderLineRepository(context); for (int i = 0; i < 10; i++) { var item = ItemFactory.CreateValidEntity(); itemRepository.Add(item); var rentalItem = RentalItemFactory.CreateValidEntity(item); rentalItemRepository.Add(rentalItem); var user = UserFactory.CreateValidEntity(); userRepository.Add(user); var rentalOrder = RentalOrderFactory.CreateValidEntity(user); rentalOrderRepository.Add(rentalOrder); var rentalOrderLineToAdd = RentalOrderLineFactory.CreateValidEntity(rentalOrder, rentalItem); rentalOrderLineRepository.Add(rentalOrderLineToAdd); } context.SaveChanges(); //Act var rentalOrderLines = rentalOrderLineRepository.GetAll(); //Assert Assert.AreEqual(10, rentalOrderLines.Count()); } }
public ActionResult Create(ItemSubmissionModel Model) { //Set unique ID for this item String id = (new IdGenerator().GenerateUniqueID(20)); Console.WriteLine($"Generated id: {id}"); Model.Internal.ID = id; //Is going to change later on Console.WriteLine($"Id: {Model.Internal.ID}"); Console.WriteLine($"Name: {Model.Internal.Name}"); Console.WriteLine($"Description: {Model.Internal.Description}"); Console.WriteLine($"Price: {Model.Internal.Price}"); //Check that required ItemModel fields were filled with valid values if (!IsValidItem(Model.Internal) || Model.Photo == null) { return(View()); } Image.ImageUpload(Model.Internal, Model.Photo); if (null != Repo.Add(Model.Internal)) { Console.WriteLine("Submited Succeslfully!"); } return(Redirect("~/My_Items/")); }
public static void ManageItem(Item item, EntityState entityState) { IItemRepository itemRepository = new ItemRepository(); if (entityState == EntityState.Added) { item.EntityState = EntityState.Added; itemRepository.Add(item); } else { item.EntityState = entityState; if (entityState == EntityState.Modified) { item.IsActive = true; } if (entityState == EntityState.Deleted) { item.IsActive = false; item.EntityState = EntityState.Modified; } itemRepository.Update(item); } }
public IActionResult MongoDb() { var itemRepository = new ItemRepository(); var random = new Random(); var now = DateTime.Now; var item = new Item { Id = Guid.NewGuid().ToString(), Property1 = random.Next(1000), Property2 = random.Next(10000, 100000), Property3 = random.Next(100000, 10000000), Property4 = GenerateCoupon(20), Property5 = GenerateCoupon(1000), Property6 = GenerateCoupon(10000), Property7 = now.AddDays(random.Next(100)), Property8 = now.AddDays(random.Next(10, 1000)), Property9 = now.AddDays(random.Next(50, 500)) }; itemRepository.Add(item); return(Ok()); }
public static void AddItemToDbTest(Item item) { using (var iRepo = new ItemRepository(new InventoryContext())) { iRepo.Add(item); iRepo.Complete(); } }
public void CheckSaleInformationReturnsAnItemOBject() { var itemRepository = new ItemRepository(); itemRepository.Add("Milk", 2.49); Assert.IsInstanceOfType(itemRepository.CheckSaleInfo("Milk"), typeof(Item)); }
public void WhenItemAddedToRepositoryCollectionGrowsBy1() { var itemRepository = new ItemRepository(); itemRepository.Add("TomatoSoup", .49); Assert.AreEqual(1, itemRepository.Count); }
public IActionResult Post(Item item) { var currentUser = GetCurrentUser(); item.UserId = currentUser.Id; _itemRepository.Add(item); return(CreatedAtAction("Get", new { id = item.Id }, item)); }
public void ItemAddedToRepositoryCanBeRecalledForPriceCheck() { var itemRepository = new ItemRepository(); decimal expectedPrice = .49m; itemRepository.Add("TomatoSoup", .49); Assert.AreEqual(expectedPrice, itemRepository.PriceCheck("TomatoSoup")); }
public void ItemAddedWithPricePerUnitQualificationProperlyAddsItem() { var itemRepository = new ItemRepository(); decimal expectedPrice = 1.99m; itemRepository.Add("GroundBeef", 1.99, 1); Assert.AreEqual(expectedPrice, itemRepository.PriceCheck("GroundBeef")); }
public void MarkdownCausesPriceCheckToReturnPriceAsChangedByMarkdownAmount() { var itemRepository = new ItemRepository(); decimal expectedPrice = 2; itemRepository.Add("Milk", 2.49); itemRepository.Markdown("Milk", .49); Assert.AreEqual(expectedPrice, itemRepository.PriceCheck("Milk")); }
//Add Data public bool Add(Item objItem, HttpPostedFileBase file) { var isAdded = false; isAdded = _itemRepository.Add(objItem, file); if (isAdded) { return(true); } return(isAdded); }
public IHttpActionResult NewItem() { using (var context = new GameDatabaseContext()) { var repo = new ItemRepository(context); var item = repo.Add(new ItemTemplate(0, "New Item", "", ItemType.FieldItem , 0, true, 0)); return Ok(item); } }
public bool Add(Item item) { if (item == null && item.Name.Length < 3) { throw new Exception("Sorry, Invalid Name Inserted!"); } bool isAdded = _repository.Add(item); return(isAdded); }
public void BuyRoundsToNearest2DecimalPlacesDownFromPoint4Below() { var testItemRepository = new ItemRepository(); testItemRepository.Add("RoundDown", 2.454); var testReceipt = new Receipt(testItemRepository); decimal expectedRoundDown = 2.45m; testReceipt.Buy("RoundDown"); Assert.AreEqual(expectedRoundDown, testReceipt.Total()); }
public void BuyRoundsToNearest2DecimalPlacesUpfromPoint5() { var testItemRepository = new ItemRepository(); testItemRepository.Add("RoundUp", 2.455); var testReceipt = new Receipt(testItemRepository); decimal expectedRoundUp = 2.46m; testReceipt.Buy("RoundUp"); Assert.AreEqual(expectedRoundUp, testReceipt.Total()); }
public void Alta(Item Item) { try { _ItemRepository.Add(Item); _ItemRepository.Save(); } catch (Exception ex) { Log.Error(ex.ToString()); } }
public void ItemRepository_Add_IsNotNullWhenGet() { var dbData = new DalItem() { Id = 100, Comment = "adfaf", Completed = true, Title = "sfsdf" }; var dbSetMock = new Mock<DbSet<OrmItem>>(); var dbContextMock = new Mock<EntityModelContext>(); dbContextMock.Setup(x => x.Set<OrmItem>()).Returns(dbSetMock.Object); var repo = new ItemRepository(dbContextMock.Object); repo.Add(dbData); Assert.IsNotNull(repo.Get(100)); }
/// <summary> /// Adds a game object to the database. /// </summary> /// <param name="gameObject">The game object to add to the database. This will be type-converted and added to the correct table when run.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public GameObjectBase AddToDatabase(GameObjectBase gameObject, string connectionString = "") { GameObjectBase resultGameObject; try { if (gameObject.GameObjectType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Area); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository()) { resultGameObject = repo.Add(gameObject as Conversation); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Creature); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Item); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Placeable); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Script); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Tileset); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.GameModule) { using (GameModuleRepository repo = new GameModuleRepository()) { resultGameObject = repo.Add(gameObject as GameModule); } } else { throw new NotSupportedException(); } } catch { throw; } return resultGameObject; }