// TODO: could be made for specific repositories so its not that bulky
 // for example most of the cases i use are entities add then X type model with that entity ID
 public UnitOfWork(GeocachingContext context)
 {
     _context         = context;
     Users            = new UserRepository(_context);
     Treasures        = new TreasureRepository(_context);
     ChainedTreasures = new ChainedTreasureRepository(_context);
     FoundTreasures   = new FoundTreasuresRepostitory(_context);
     TreasureComments = new TreasureCommentsRepository(_context);
     Markers          = new MarkersRepository(_context);
 }
Exemplo n.º 2
0
        public GeocacheControllerTests()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkInMemoryDatabase()
                                  .BuildServiceProvider();

            var optionsBuilder = new DbContextOptionsBuilder <GeocachingContext>();

            optionsBuilder.UseInMemoryDatabase("TestDB");
            optionsBuilder.UseInternalServiceProvider(serviceProvider);
            context = new GeocachingContext(optionsBuilder.Options);

            geocacheController = new GeocacheController(context);
            SeedData.PopulateTestData(context);
        }
 public FoundTreasuresRepostitory(GeocachingContext context) : base(context)
 {
 }
Exemplo n.º 4
0
 public ItemController(GeocachingContext context)
 {
     client = new ItemClient(context);
 }
Exemplo n.º 5
0
 public MarkersRepository(GeocachingContext context) : base(context)
 {
 }
Exemplo n.º 6
0
        public static void PopulateTestData(GeocachingContext dbContext)
        {
            // create and add 3 new geocaches
            var geocache = new GeocacheEntity
            {
                Name      = "Test Geocache 1",
                Latitude  = 0,
                Longitude = 0
            };

            dbContext.Geocache.Add(geocache);
            geocache = new GeocacheEntity
            {
                Name      = "Test Geocache 2",
                Latitude  = 0,
                Longitude = 0
            };
            dbContext.Geocache.Add(geocache);
            geocache = new GeocacheEntity
            {
                Name      = "Test Geocache 3",
                Latitude  = 0,
                Longitude = 0
            };
            dbContext.Geocache.Add(geocache);
            var startDate = DateTime.Today;
            var endDate   = DateTime.Today.AddDays(2);

            // create and add 3 items that are not past their active end date (active)
            var item = new ItemEntity
            {
                Name            = "Test Item 1",
                CacheId         = null,
                ActiveStartDate = startDate,
                ActiveEndDate   = endDate
            };

            dbContext.Item.Add(item);

            item = new ItemEntity
            {
                Name            = "Test Item 2",
                CacheId         = null,
                ActiveStartDate = startDate,
                ActiveEndDate   = endDate
            };
            dbContext.Item.Add(item);

            item = new ItemEntity
            {
                Name            = "Test Item 3",
                CacheId         = null,
                ActiveStartDate = startDate,
                ActiveEndDate   = endDate
            };
            dbContext.Item.Add(item);

            // create and add an item that is past its active end date (no longer active)
            endDate = endDate.AddDays(-4);
            item    = new ItemEntity
            {
                Name            = "Test Item 3",
                CacheId         = null,
                ActiveStartDate = startDate,
                ActiveEndDate   = endDate
            };
            dbContext.Item.Add(item);
            dbContext.SaveChanges();
        }
 public ChainedTreasureRepository(GeocachingContext context) : base(context)
 {
 }
Exemplo n.º 8
0
 public ItemClient(GeocachingContext context)
 {
     _context = context;
 }
Exemplo n.º 9
0
 public GeocacheController(GeocachingContext context)
 {
     client = new GeocacheClient(context);
 }
 public UserRepository(GeocachingContext context) : base(context)
 {
 }
Exemplo n.º 11
0
 public TreasureCommentsRepository(GeocachingContext context) : base(context)
 {
 }
Exemplo n.º 12
0
 public GeocacheClient(GeocachingContext context)
 {
     _context = context;
 }