public void RemoveGoodReservation() { try { var options = CreateNewContextOptions(); using (var db = new PersonalStoreContext(options)) { var repository = new PersonalStoreRepository(db); StoreTestHelper.PopulateDefaultPersonalStoreData(db); var user = db.Set <User>().First(it => it.UserName == "Andrew"); var item = db.Set <StoreM>().First(); var good = db.Set <Good>().First(); var reserved = 0; Assert.DoesNotThrow(() => reserved = repository.ReserveGood(item, good, user, 10)); Assert.True(reserved == 1); int unreserved = 0; Assert.DoesNotThrow(() => unreserved = repository.RemoveGoodReservation(item, good, user, 10)); Assert.True(unreserved == 1); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void Get() { try { var options = CreateNewContextOptions(); using (var db = new PersonalStoreContext(options)) { var repository = new PersonalStoreRepository(db); StoreTestHelper.PopulateDefaultPersonalStoreData(db); IEnumerable <StoreM> result = null; var user = db.Set <User>().First(it => it.UserName == "Andrew"); var filter = new UserStoreFilter <int> { UserId = user.Id, IsOnlyActive = false }; Assert.DoesNotThrow(() => result = repository.Get(filter)); Assert.True(result != null && result.Any() && result.Count() == 1); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void RemoveStore() { try { var options = CreateNewContextOptions(); using (var db = new PersonalStoreContext(options)) { StoreTestHelper.PopulateDefaultPersonalStoreData(db); } using (var db = new PersonalStoreContext(options)) { var repository = new PersonalStoreRepository(db); var user = db.Set <User>().First(it => it.UserName == "Andrew"); var item = db.Set <StoreM>().First(); Assert.DoesNotThrow(() => repository.RemoveStore(item, user)); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void AddStore() { try { var options = CreateNewContextOptions(); using (var db = new PersonalStoreContext(options)) { var repository = new PersonalStoreRepository(db); StoreTestHelper.PopulateDefaultPersonalStoreData(db); var user = db.Set <User>().First(it => it.UserName == "Andrew"); var item = GenerateModel(); var goods = db.Set <Good>().ToList().Select(it => new Tuple <Good, int>(it, 1)); Assert.DoesNotThrow(() => repository.AddStore(item, user, goods)); var filter = new UserStoreFilter <int> { UserId = user.Id, IsOnlyActive = false }; Assert.DoesNotThrow(() => item = repository.Get(filter).FirstOrDefault()); Assert.NotNull(item); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void GetGoodByArticul() { try { var options = CreateNewContextOptions(); using (var db = new PersonalStoreContext(options)) { var repository = new PersonalStoreRepository(db); StoreTestHelper.PopulateDefaultPersonalStoreData(db); var item = db.Set <Good>().First(); var store = db.Set <StoreM>().First(); var user = db.Set <User>().First(it => it.UserName == "Andrew"); Assert.DoesNotThrow(() => item = repository.GetGoodByArticul(user.Id, store.Id, item.Articul)); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void DecreaseGoodQuantity() { try { var options = CreateNewContextOptions(); using (var db = new PersonalStoreContext(options)) { var repository = new PersonalStoreRepository(db); StoreTestHelper.PopulateDefaultPersonalStoreData(db); var user = db.Set <User>().First(it => it.UserName == "Andrew"); var item = db.Set <StoreM>().First(); var good = db.Set <Good>().First(); Assert.DoesNotThrow(() => repository.IncreaseGoodQuantity(item, good, user, 10)); Assert.DoesNotThrow(() => repository.DecreaseGoodQuantity(item, good, user, 11)); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void GetGoods() { try { var options = CreateNewContextOptions(); using (var db = new PersonalStoreContext(options)) { var repository = new PersonalStoreRepository(db); StoreTestHelper.PopulateDefaultPersonalStoreData(db); IEnumerable <Good> result = null; var filter = new UserStoreGoodsFilter <int, int, int>() { UserId = 1, StoreId = 1 }; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodCategoryIds = db.Set <GoodCategory>().Select(it => it.CategoryId).Distinct().ToList(); Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 1); filter.GoodCategoryIds = null; filter.GoodTypeIds = db.Set <GoodType>().Select(it => it.TypeId).Distinct().ToList(); Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 1); filter.GoodTypeIds = null; filter.GoodDesignerIds = db.Set <GoodDesigner>().Select(it => it.DesignerId).Distinct().ToList(); Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 1); filter.GoodDesignerIds = null; filter.GoodColorIds = db.Set <GoodColor>().Select(it => it.ColorId).Distinct().ToList(); Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 1); filter.GoodColorIds = null; filter.GoodMaterialsIds = db.Set <GoodMaterial>().Select(it => it.MaterialId).Distinct().ToList(); Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 1); filter.GoodColorIds = null; filter.GoodMaterialsIds = null; filter.GoodDepthInterval.End = 100; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodDepthInterval.End = null; filter.GoodDepthInterval.Start = 20; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodDepthInterval.End = 100; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodDepthInterval.Start = null; filter.GoodDepthInterval.End = null; filter.GoodHeightInterval.End = 100; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodHeightInterval.End = null; filter.GoodHeightInterval.Start = 20; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodHeightInterval.End = 100; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodHeightInterval.End = null; filter.GoodHeightInterval.Start = null; filter.GoodWidthInterval.End = 100; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodWidthInterval.End = null; filter.GoodWidthInterval.Start = 20; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodWidthInterval.End = 100; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodHeightInterval.Start = 20; filter.GoodHeightInterval.End = 100; filter.GoodDepthInterval.Start = 20; filter.GoodDepthInterval.End = 100; Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 3); filter.GoodCategoryIds = db.Set <GoodCategory>().Select(it => it.CategoryId).Distinct().ToList(); filter.GoodTypeIds = db.Set <GoodType>().Select(it => it.TypeId).Distinct().ToList(); filter.GoodDesignerIds = db.Set <GoodDesigner>().Select(it => it.DesignerId).Distinct().ToList(); filter.GoodColorIds = db.Set <GoodColor>().Select(it => it.ColorId).Distinct().ToList(); filter.GoodColorIds = null; filter.GoodMaterialsIds = db.Set <GoodMaterial>().Select(it => it.MaterialId).Distinct().ToList(); Assert.DoesNotThrow(() => result = repository.GetGoods(filter)); Assert.True(result != null && result.Any() && result.Count() == 1); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }