예제 #1
0
        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);
        }
예제 #2
0
        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");
            }
        }
예제 #3
0
 /*
  * 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);
 }
예제 #4
0
        // Конструктор с параметрами.
        public ChickenViewModel(Chicken chicken, FarmContext context)
        {
            _farmContext = context;
            _chicken     = chicken;

            Reports     = new ObservableCollection <Report>(chicken.Reports);
            WindowTitle = $"Курица породы \"{_chicken.Breed.Title}\"";
        } // ctorf.
예제 #5
0
        // Конструктор с параметрами.
        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>();
        }
예제 #7
0
        // Конструктор с параметрами.
        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.
예제 #8
0
        // Ансамбль конструкторов.
        // Конструктор по умолчанию.
        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();
 }
예제 #10
0
 // Конструктор с параметрами.
 public AdminViewModel(FarmContext context)
 {
     _farmContext = context;
 } // ctorf.
예제 #11
0
 public AdminWindow(FarmContext context) : this()
 {
     DataContext = new AdminViewModel(context);
 }
예제 #12
0
        public MainWindow(FarmContext context)
        {
            InitializeComponent();

            DataContext = new LoginViewModel(context);
        } // ctorf.
예제 #13
0
 // Ансамбль конструкторов.
 // Конструктор по умолчанию.
 public LoginViewModel()
 {
     Database.SetInitializer(new DbInitializer());
     _farmContext = new FarmContext("farmContext");
     _farmContext.Database.Initialize(false);
 } // ctor.
예제 #14
0
 public UnitOfWork(FarmContext farmContext)
 {
     _farmContext = farmContext;
 }
예제 #15
0
 public AccessoireRepository()
 {
     Context = new FarmContext();
 }
예제 #16
0
 public ShopWindow(Shop shop, FarmContext context) : this()
 {
     DataContext = new ShopViewModel(shop, context);
 }
예제 #17
0
 // Конструктор с параметрами.
 public DirectorViewModel(FarmContext context, Person director)
 {
     _farmContext = context;
     _director    = director;
 } // ctorf.
예제 #18
0
 public DirectorWindow(FarmContext context, Person director) : this()
 {
     DataContext = new DirectorViewModel(context, director);
 } // ctorf.
예제 #19
0
        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);
        }
예제 #20
0
 public CellWindow(Cell cell, FarmContext context) : this()
 {
     DataContext = new CellViewModel(cell, context);
 } // ctorf.
예제 #21
0
 public ChickenWindow(Chicken chicken, FarmContext context) : this()
 {
     DataContext = new ChickenViewModel(chicken, context);
 } // ctorf.
예제 #22
0
 //этот конструктор не нужен
 public EFUnitOfWork(string connectionString)
 {
     context = new FarmContext(connectionString);
 }
예제 #23
0
 // Конструктор с параметрами.
 public LoginController(FarmContext farmContext, string login, string password)
 {
     _farmContext = farmContext;
     _login       = login;
     _password    = PasswordHash.GetHash(password);
 } // ctorf.
예제 #24
0
 public GenericRepository(FarmContext context)
 {
     _context = context;
 }
예제 #25
0
 public EFUnitOfWork()
 {
     context = new FarmContext();
 }
 public BookingRepository()
 {
     Context = new FarmContext();
 }