Example #1
0
        public CrossSolarInMemoryDbContextProvider()
        {
            var options = new DbContextOptionsBuilder <CrossSolarDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            _context = new CrossSolarDbContext(options);

            Random rnd = new Random(DateTime.Now.Millisecond);

            List <OneHourElectricity> list = new List <OneHourElectricity>();

            for (int i = 0; i < 10; i++)
            {
                Panel p = CreateRandom(rnd);

                list = new List <OneHourElectricity>();

                for (int e = 0; e < rnd.Next(10); e++)
                {
                    OneHourElectricity el = CreateRandomOneHourElectricity(p.Id);
                    list.Add(el);
                }

                p.OneHourElectricitys = list;

                _context.Panels.Add(p);
            }

            _context.SaveChanges();
        }
        private static AnalyticsController MockPanelAndAnalyticsImplementation(Panel panel, OneHourElectricity OneHourElectricity)
        {
            var oneHourElectricitys = new List <OneHourElectricity>();

            oneHourElectricitys.Add(OneHourElectricity);
            IQueryable <OneHourElectricity> queryableElectricities = oneHourElectricitys.AsQueryable();

            // Force DbSet to return the IQueryable members of our converted list object as its data source
            var mockSet = new Mock <DbSet <OneHourElectricity> >();

            mockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.Provider).Returns(queryableElectricities.Provider);
            mockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.Expression).Returns(queryableElectricities.Expression);
            mockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.ElementType).Returns(queryableElectricities.ElementType);
            mockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.GetEnumerator()).Returns(queryableElectricities.GetEnumerator());

            var crossSolarDbContext = new CrossSolarDbContext();

            crossSolarDbContext.OneHourElectricitys = mockSet.Object;

            var mockAnalyticsRepository        = new Mock <IAnalyticsRepository>();
            var mockPanelRepository            = new Mock <IPanelRepository>();
            var mockPanelGenericRepository     = new Mock <GenericRepository <Panel> >();
            var mockAnalyticsGenericRepository = new Mock <GenericRepository <OneHourElectricity> >();

            var mockController = new AnalyticsController(mockAnalyticsRepository.Object, mockPanelRepository.Object);

            mockPanelRepository.Setup(x => x.GetAsync("AAAA1111BBBB2222")).Returns(Task.FromResult(panel));
            mockAnalyticsRepository.Setup(x => x.Query()).Returns(queryableElectricities);
            return(mockController);
        }
Example #3
0
        public RepositoryTestBase()
        {
            var options = new DbContextOptionsBuilder <CrossSolarDbContext>()
                          .UseInMemoryDatabase(databaseName: "CrossSolarDbContext")
                          .Options;

            _crossSolarDbContext = new CrossSolarDbContext(options);
        }
Example #4
0
        public PanelControllerTests() : base()
        {
            var builder = new DbContextOptionsBuilder <CrossSolarDbContext>().UseSqlServer(ConnectionString);
            var context = new CrossSolarDbContext(builder.Options);

            _panelRepository = new PanelRepository(context);
            _panelController = new PanelController(_panelRepository);
        }
Example #5
0
        private CrossSolarDbContext InMemoryContext()
        {
            var options = new DbContextOptionsBuilder <CrossSolarDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var context = new CrossSolarDbContext(options);

            return(context);
        }
Example #6
0
        public AnalyticsControllerTests() : base()
        {
            var contextOpions = new DbContextOptionsBuilder <CrossSolarDbContext>().UseSqlServer(ConnectionString).Options;
            var context       = new CrossSolarDbContext(contextOpions);

            _anlticsReposiitory = new AnalyticsRepository(context);
            _panelRepository    = new PanelRepository(context);
            _anlyticsController = new AnalyticsController(_anlticsReposiitory, _panelRepository);
            _panelController    = new PanelController(_panelRepository);
        }
        public void Get_RecordsPanelInserted()
        {
            var optionsBuilder = new DbContextOptionsBuilder <CrossSolarDbContext>();

            optionsBuilder.UseSqlServer("Server=.\\SQLEXPRESS;Database=CrossSolarDb;Trusted_Connection=True;");

            CrossSolarDbContext _context = new CrossSolarDbContext(optionsBuilder.Options);

            Repository.PanelRepository _pruebas = new Repository.PanelRepository(_context);

            var _res = _pruebas.Query();

            Assert.NotNull(_res);
        }
Example #8
0
        /// <summary>
        /// Constructor of the class.
        /// </summary>
        public AnalyticsControllerTests()
        {
            // Using 'UseInMemoryDatabase' instead of throwing the repository, avoiding EF limitations and asynchronous returns.
            options = new DbContextOptionsBuilder <CrossSolarDbContext>()
                      .UseInMemoryDatabase(databaseName: "CrossSolarDbInMemory").Options;

            context = new CrossSolarDbContext(options);

            _panelRepository        = new PanelRepository(context);
            _analyticsRepository    = new AnalyticsRepository(context);
            _dayAnalyticsRepository = new DayAnalyticsRepository(context);

            _analyticsController = new AnalyticsController(_analyticsRepository, _dayAnalyticsRepository, _panelRepository);
        }
        public void Eval_TypeModelDayAnalyticsRepository()
        {
            var optionsBuilder = new DbContextOptionsBuilder <CrossSolarDbContext>();

            optionsBuilder.UseSqlServer("Server=.\\SQLEXPRESS;Database=CrossSolarDb;Trusted_Connection=True;");

            CrossSolarDbContext _context = new CrossSolarDbContext(optionsBuilder.Options);

            Repository.DayAnalyticsRepository _pruebas = new Repository.DayAnalyticsRepository(_context);

            var _res = _pruebas.Query();


            Assert.NotNull(_res);
        }
Example #10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CrossSolarDbContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseHttpStatusCodeExceptionMiddleware();
            }
            else
            {
                app.UseHttpStatusCodeExceptionMiddleware();
                app.UseExceptionHandler();
            }

            app.UseMvc();
        }
Example #11
0
 public DayAnalyticsRepository(CrossSolarDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Example #12
0
 public PanelRepository(CrossSolarDbContext dbContext)
 {
     DbContext = dbContext;
 }
Example #13
0
 public PanelRepositoryTests()
 {
     _testDBContext   = InMemoryContext();
     _panelRepository = new PanelRepository(_testDBContext);
 }