public void InsertAsync()
        {
            var sample = CreateRandomEntity(1);

            int res = _repository.InsertAsync(sample).Result;

            Assert.NotEqual(default(int), sample.Id);

            var r = _repository.Query().Where(p => p.Id == sample.Id).FirstOrDefault();

            FullCompare(sample, r);
        }
Exemple #2
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);
        }