public void Setup() { _farms = new List <FarmEntity> { new FarmEntity { AmountOfAnimals = Faker.NumberFaker.Number(0, 100), DelitingDate = null, Id = 44, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName() } }; var mockedDbContext = new Mock <FarmContext>(); _db = mockedDbContext.Object; var dbset = new FakeDbSet <FarmEntity>(_farms); mockedDbContext.Setup(x => x.FarmEntities) .Returns(() => dbset); _unitOfWork = new UnitOfWork(_db); _farmRepository = new FarmRepository(_db); }
public static async Task SeedAsync(FarmContext farmContext, ILoggerFactory loggerFactory) { try { if (!farmContext.Farms.Any()) { var farmData = File.ReadAllText("../Infrastructure/SeedData/farms.json"); var farms = JsonConvert.DeserializeObject <List <Farm> >(farmData); farmContext.Farms.AddRange(farms); await farmContext.SaveChangesAsync(); } if (!farmContext.Cows.Any()) { var cowsData = File.ReadAllText("../Infrastructure/SeedData/cows.json"); var cows = JsonConvert.DeserializeObject <List <Cow> >(cowsData); farmContext.Cows.AddRange(cows); await farmContext.SaveChangesAsync(); } if (!farmContext.Sensors.Any()) { var sensorsData = File.ReadAllText("../Infrastructure/SeedData/sensors.json"); var sensors = JsonConvert.DeserializeObject <List <Sensor> >(sensorsData); farmContext.Sensors.AddRange(sensors); await farmContext.SaveChangesAsync(); } } catch (Exception ex) { var logger = loggerFactory.CreateLogger <FarmContextSeed>(); logger.LogError(ex, "Failed while seeding"); } }
/* * CR-1 * Implement private ctor, that receives FarmContext * Call it from public constructors * Implement right away initializing of repositories - it is not costly operation * Target code here: * * public EFUnitOfWork(string connectionString) * this(new FarmContext(connectionString)) { } * * public EFUnitOfWork() * this(new FarmContext()) { } * * private EFUnitOfWork(FarmContext context) * { * _context = context; * Farms = new EFRepository<Farm>(_context); * } * * Add comments to ctor */ public EFUnitOfWork(string connectionString) { /* * CR-1 - check argument for null */ context = new FarmContext(connectionString); }
// Конструктор с параметрами. public ChickenViewModel(Chicken chicken, FarmContext context) { _farmContext = context; _chicken = chicken; Reports = new ObservableCollection <Report>(chicken.Reports); WindowTitle = $"Курица породы \"{_chicken.Breed.Title}\""; } // ctorf.
// Конструктор с параметрами. public CellViewModel(Cell cell, FarmContext context) { _farmContext = context; _cell = cell; WindowTitle = $"Клетка (ряд {cell.RowNumber}, номер {cell.CellNumber}) "; Chickens = new ObservableCollection <Chicken>(cell.Chickens); } // ctorf.
private void AddBindings() { IFarmContext farmContext = new FarmContext(); kernel.Bind <IFarmService>().To <FarmService>(); kernel.Bind <IFarmRepository>().To <FarmRepository>(); kernel.Bind <IUnitOfWork>().To <UnitOfWork>(); // kernel.Bind<IFarmContext>().To<FarmContext>(); }
// Конструктор с параметрами. public ShopViewModel(Shop shop, FarmContext context) { _farmContext = context; _shop = shop; var temp = new ObservableCollection <Employee>(); foreach (var item in _shop.Cells) { temp.Add(item.Employee); } Employees = new ObservableCollection <Employee>(temp.Distinct()); WindowTitle = $"Цех №{_shop.Id}"; } // ctorf.
// Ансамбль конструкторов. // Конструктор по умолчанию. public ApplicationViewModel() { try { Database.SetInitializer(new DbInitializer()); _farmContext = new FarmContext(); _farmContext.Database.Initialize(false); //_farmContext.Directors.Add(new Director //{ // Person = new Person("sasasa", "sasasa", "sasasa", "sasasa", 2) // { // Status = new Status("Работает"), // Login = new Login("Director"), // PasswordHash = new PasswordHash(PasswordHash.GetHash("Director")) // } //}); //_farmContext. //_farmContext.SaveChanges(); //MessageBox.Show("Сделано"); //_farmContext.Dispose(); //Database.SetInitializer(new DbInitializer()); JsonConvert.SerializeObject(_farmContext.Shops.Local, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); //Task.Run(_controller.ClientsListening); //_controller.ClientsListening(); } catch (Exception e) { MessageBox.Show(e.Message); } }
public AnimalRepository() { Context = new FarmContext(); }
// Конструктор с параметрами. public AdminViewModel(FarmContext context) { _farmContext = context; } // ctorf.
public AdminWindow(FarmContext context) : this() { DataContext = new AdminViewModel(context); }
public MainWindow(FarmContext context) { InitializeComponent(); DataContext = new LoginViewModel(context); } // ctorf.
// Ансамбль конструкторов. // Конструктор по умолчанию. public LoginViewModel() { Database.SetInitializer(new DbInitializer()); _farmContext = new FarmContext("farmContext"); _farmContext.Database.Initialize(false); } // ctor.
public UnitOfWork(FarmContext farmContext) { _farmContext = farmContext; }
public AccessoireRepository() { Context = new FarmContext(); }
public ShopWindow(Shop shop, FarmContext context) : this() { DataContext = new ShopViewModel(shop, context); }
// Конструктор с параметрами. public DirectorViewModel(FarmContext context, Person director) { _farmContext = context; _director = director; } // ctorf.
public DirectorWindow(FarmContext context, Person director) : this() { DataContext = new DirectorViewModel(context, director); } // ctorf.
public void Setup() { _farms = new List <FarmEntity> { new FarmEntity { AmountOfAnimals = 15, DelitingDate = null, Id = 1, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName(), Cost = 1500 }, new FarmEntity { AmountOfAnimals = 20, DelitingDate = null, Id = 2, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName(), Cost = 400 }, new FarmEntity { AmountOfAnimals = 1, DelitingDate = null, Id = 3, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName(), Cost = 100 }, new FarmEntity { AmountOfAnimals = 100, DelitingDate = null, Id = 4, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName(), Cost = 500 }, new FarmEntity { AmountOfAnimals = 50, DelitingDate = null, Id = 5, IsDelete = false, Name = Faker.CompanyFaker.Name(), OwnerName = Faker.NameFaker.MaleName(), Cost = 500 } }; var mockedDbContext = new Mock <FarmContext>(); _db = mockedDbContext.Object; var dbset = new FakeDbSet <FarmEntity>(_farms); mockedDbContext.Setup(x => x.FarmEntities) .Returns(() => dbset); _unitOfWork = new UnitOfWork(_db); _farmRepository = new FarmRepository(_db); _farmService = new FarmService(_unitOfWork); _farmController = new FarmController(_farmService); }
public CellWindow(Cell cell, FarmContext context) : this() { DataContext = new CellViewModel(cell, context); } // ctorf.
public ChickenWindow(Chicken chicken, FarmContext context) : this() { DataContext = new ChickenViewModel(chicken, context); } // ctorf.
//этот конструктор не нужен public EFUnitOfWork(string connectionString) { context = new FarmContext(connectionString); }
// Конструктор с параметрами. public LoginController(FarmContext farmContext, string login, string password) { _farmContext = farmContext; _login = login; _password = PasswordHash.GetHash(password); } // ctorf.
public GenericRepository(FarmContext context) { _context = context; }
public EFUnitOfWork() { context = new FarmContext(); }
public BookingRepository() { Context = new FarmContext(); }