public async Task <IActionResult> PutEIAPoint(int id, EIAPoint eiaPoint)
        {
            if (id != eiaPoint.Id)
            {
                return(BadRequest());
            }

            _context.Entry(eiaPoint).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EIAPointExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <EIAPoint> > PostEIAPoint(EIAPoint eiaPoint)
        {
            _context.EIAPoints.Add(eiaPoint);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetEIAPoint", new { id = eiaPoint.Id }, eiaPoint));
        }
示例#3
0
        public void AddEIAPoint_WithInMemoryContext_SavesSuccessfully()
        {
            //create In Memory Database
            var options = new DbContextOptionsBuilder <TVAEnergyDataContext>()
                          .UseInMemoryDatabase(databaseName: "TVAEnergyData")
                          .Options;
            var context = new TVAEnergyDataContext(options);

            var point = new EIAPoint
            {
                SeriesId         = "EBA.TVA-ALL.D.H",
                Name             = "TVA_Load",
                Description      = "TVA System Load",
                CreatedDateTime  = DateTime.UtcNow,
                ModifiedDateTime = DateTime.UtcNow
            };

            context.EIAPoints.Add(point);
            context.SaveChanges();

            var savedPoint = context.EIAPoints.First(p => p.SeriesId == "EBA.TVA-ALL.D.H");

            Assert.True(savedPoint.Id > 0);
            Assert.Equal(point.SeriesId, savedPoint.SeriesId);
            Assert.Equal(point.Name, savedPoint.Name);
            Assert.Equal(point.Description, savedPoint.Description);
            Assert.Equal(point.CreatedDateTime, savedPoint.CreatedDateTime);
            Assert.Equal(point.ModifiedDateTime, savedPoint.ModifiedDateTime);
        }