Esempio n. 1
0
        public void PanelRepositoryTests()
        {
            var             dbMock          = new Mock <CrossSolarDbContext>();
            PanelRepository panelRepository = new PanelRepository(dbMock.Object);

            Assert.NotNull(panelRepository);
        }
        public async Task Register_ShouldGetDayResult()
        {
            Mock <DbSet <Panel> > mockPanel = MockPanelRepository();
            Mock <DbSet <OneHourElectricity> > mockOneHourElectricity = MockDayResult();

            var mockContext = new Mock <CrossSolarDbContext>();

            mockContext.Setup(c => c.Set <Panel>()).Returns(mockPanel.Object);
            mockContext.Setup(c => c.Set <OneHourElectricity>()).Returns(mockOneHourElectricity.Object);

            var entityRepository    = new PanelRepository(mockContext.Object);
            var analyticsRepository = new AnalyticsRepository(mockContext.Object);

            var _analyticsController = new AnalyticsController(analyticsRepository, entityRepository);

            // Act
            var result = await _analyticsController.DayResults("AAAA1111BBBB2222");

            // Assert
            Assert.NotNull(result);
            var createdResult = result as OkObjectResult;

            Assert.NotNull(createdResult);
            Assert.Equal(200, createdResult.StatusCode);
        }
        public DayAnalyticsRepositoryTest()
        {
            CrossSolarInMemoryDbContextProvider contextProvider = new CrossSolarInMemoryDbContextProvider();

            _repository = new DayAnalyticsRepository(contextProvider.GetInMemoryContext());

            _panelRepository = new PanelRepository(contextProvider.GetInMemoryContext());
        }
        public AlarmMonitorContext()
        {
            this.Events       = new EventList();
            this.Panels       = new PanelList();
            this.EventUnities = new EventUnitList();

            this.eventRepository     = new EventRepository(this.Events);
            this.eventUnitRepository = new EventUnitRepository(this.EventUnities);
            this.panelRepository     = new PanelRepository(this.Panels);

            this.CreateEventUnities();
        }
        public void GetAsync_WorksFine()
        {
            // Arrange
            Mock <CrossSolarDbContext> mock = new Mock <CrossSolarDbContext>();

            mock.Setup(a => a.FindAsync(null)).Returns(Task.FromResult <object>(new Panel()));

            // Act
            GenericRepository <Panel> genericRepository = new PanelRepository(mock.Object);
            var actual = genericRepository.GetAsync("123");

            Assert.IsAssignableFrom <Task <Panel> >(actual);
        }
        public void InsertAsync_WorksFine()
        {
            // Arrange
            Mock <CrossSolarDbContext> mock      = new Mock <CrossSolarDbContext>();
            Mock <DbSet <Panel> >      mockDbSet = new Mock <DbSet <Panel> >();

            mock.Setup(a => a.Set <Panel>()).Returns(() => mockDbSet.Object);
            mock.Setup(a => a.SaveChangesAsync(true, CancellationToken.None)).Returns(Task.FromResult(1));

            // Act
            GenericRepository <Panel> genericRepository = new PanelRepository(mock.Object);
            var actual = Record.ExceptionAsync(() => genericRepository.InsertAsync(new Panel()));

            Assert.Null(actual.Result);
        }
        public void Query_WorksFine()
        {
            // Arrange
            Mock <CrossSolarDbContext> mock      = new Mock <CrossSolarDbContext>();
            Mock <DbSet <Panel> >      mockDbSet = new Mock <DbSet <Panel> >();

            mock.Setup(a => a.Set <Panel>()).Returns(() => mockDbSet.Object);

            // Act
            GenericRepository <Panel> genericRepository = new PanelRepository(mock.Object);
            var actual = genericRepository.Query();

            // Assert
            Assert.IsAssignableFrom <IQueryable <Panel> >(actual);
        }
        public AnalyticsControllerTests()
        {
            var panelmockSet = new Mock <DbSet <Panel> >();

            panelmockSet.As <IAsyncEnumerable <Panel> >()
            .Setup(m => m.GetEnumerator())
            .Returns(new TestAsyncEnumerator <Panel>(_panels.GetEnumerator()));

            panelmockSet.As <IQueryable <Panel> >()
            .Setup(m => m.Provider)
            .Returns(new TestAsyncQueryProvider <Panel>(_panels.Provider));

            panelmockSet.As <IQueryable <Panel> >().Setup(m => m.Expression).Returns(_panels.Expression);
            panelmockSet.As <IQueryable <Panel> >().Setup(m => m.ElementType).Returns(_panels.ElementType);
            panelmockSet.As <IQueryable <Panel> >().Setup(m => m.GetEnumerator()).Returns(_panels.GetEnumerator());

            var electricitymockSet = new Mock <DbSet <OneHourElectricity> >();

            electricitymockSet.As <IAsyncEnumerable <OneHourElectricity> >()
            .Setup(m => m.GetEnumerator())
            .Returns(new TestAsyncEnumerator <OneHourElectricity>(_electricitys.GetEnumerator()));

            electricitymockSet.As <IQueryable <Panel> >()
            .Setup(m => m.Provider)
            .Returns(new TestAsyncQueryProvider <OneHourElectricity>(_electricitys.Provider));

            electricitymockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.Expression)
            .Returns(_electricitys.Expression);
            electricitymockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.ElementType)
            .Returns(_electricitys.ElementType);
            electricitymockSet.As <IQueryable <OneHourElectricity> >().Setup(m => m.GetEnumerator())
            .Returns(() => _electricitys.GetEnumerator());

            var contextOptions = new DbContextOptions <CrossSolarDbContext>();
            var mockContext    = new Mock <CrossSolarDbContext>(contextOptions);

            mockContext.Setup(c => c.Set <Panel>()).Returns(panelmockSet.Object);
            mockContext.Setup(c => c.Set <OneHourElectricity>()).Returns(electricitymockSet.Object);

            var panelsRepository    = new PanelRepository(mockContext.Object);
            var analyticsRepository = new AnalyticsRepository(mockContext.Object);


            _analyticsController = new AnalyticsController(analyticsRepository: analyticsRepository,
                                                           panelRepository: panelsRepository);
        }
Esempio n. 9
0
        public void TestPanelRepository()
        {
            IPanelRepository panelRepository = new PanelRepository(new CrossSolarDbContext());

            var panel = new Panel
            {
                Brand     = "Areva",
                Latitude  = 12.345678,
                Longitude = 98.7655432,
                Serial    = "AAAA1111BBBB27657"
            };

            panelRepository.InsertAsync(panel);

            var result = panelRepository.GetBySerialNumAsync("AAAA1111BBBB27657");

            Assert.NotNull(result);
        }
Esempio n. 10
0
        public void Constructor_WorksFine()
        {
            PanelRepository panelRepository = new PanelRepository(new CrossSolarDbContext());

            Assert.NotNull(panelRepository);
        }
Esempio n. 11
0
 public PanelRepositoryTest()
 {
     _repository = new PanelRepository(_crossSolarDbContext);
 }
Esempio n. 12
0
        public async Task GetTest()
        {
            var panels = new List <Panel>
            {
                new Panel {
                    Id        = 1,
                    Brand     = "Areva",
                    Latitude  = 12.345678,
                    Longitude = 98.7655432,
                    Serial    = "AAAA1111BBBB2222"
                }
            }.AsQueryable();

            var onehourelectricity = Enumerable.Empty <OneHourElectricity>().AsQueryable();

            var panelmockset = new Mock <DbSet <Panel> >();
            var onehourelectricitymockset = new Mock <DbSet <OneHourElectricity> >();

            panelmockset.As <IAsyncEnumerable <Panel> >()
            .Setup(m => m.GetEnumerator())
            .Returns(new TestAsyncEnumerator <Panel>(panels.GetEnumerator()));

            panelmockset.As <IQueryable <Panel> >()
            .Setup(m => m.Provider)
            .Returns(new TestAsyncQueryProvider <Panel>(panels.Provider));

            onehourelectricitymockset.As <IAsyncEnumerable <OneHourElectricity> >()
            .Setup(m => m.GetEnumerator())
            .Returns(new TestAsyncEnumerator <OneHourElectricity>(onehourelectricity.GetEnumerator()));

            onehourelectricitymockset.As <IQueryable <OneHourElectricity> >()
            .Setup(m => m.Provider)
            .Returns(new TestAsyncQueryProvider <OneHourElectricity>(onehourelectricity.Provider));



            panelmockset.As <IQueryable <Panel> >().Setup(m => m.Expression).Returns(panels.Expression);
            panelmockset.As <IQueryable <Panel> >().Setup(m => m.ElementType).Returns(panels.ElementType);
            panelmockset.As <IQueryable <Panel> >().Setup(m => m.GetEnumerator()).Returns(() => panels.GetEnumerator());



            onehourelectricitymockset.As <IQueryable <OneHourElectricity> >().Setup(m => m.Expression).Returns(onehourelectricity.Expression);
            onehourelectricitymockset.As <IQueryable <OneHourElectricity> >().Setup(m => m.ElementType).Returns(onehourelectricity.ElementType);
            onehourelectricitymockset.As <IQueryable <OneHourElectricity> >().Setup(m => m.GetEnumerator())
            .Returns(() => onehourelectricity.GetEnumerator());


            var contextOptions   = new DbContextOptions <CrossSolarDbContext>();
            var mockPanelContext = new Mock <CrossSolarDbContext>(contextOptions);

            mockPanelContext.Setup(c => c.Set <Panel>()).Returns(panelmockset.Object);

            var panelRepository = new PanelRepository(mockPanelContext.Object);

            var mockHourElectricityContext = new Mock <CrossSolarDbContext>(contextOptions);

            mockHourElectricityContext.Setup(c => c.Set <OneHourElectricity>()).Returns(onehourelectricitymockset.Object);

            var panelService = new PanelRepository(mockPanelContext.Object);
            var elecService  = new AnalyticsRepository(mockHourElectricityContext.Object);

            _panelRepositoryMock.Setup(x => x.Query()).Returns(panelService.Query());
            _analyticsRepositoryMock.Setup(x => x.Query()).Returns(elecService.Query());



            var result = await _analyticsController.Get("1");

            // Assert
            Assert.NotNull(result);
        }
Esempio n. 13
0
 public void PanelRepository()
 {
     //CrossSolarDbContext dbContext = new CrossSolarDbContext();
     var result = new PanelRepository(dbContext);
 }
 public PanelRepositoryTests()
 {
     _panelRepository = new PanelRepository(_crossSolarDbContextMock.Object);
 }