public void TestCreateUpdateDelete() { Guid aggId = Guid.NewGuid(); Aggregation createdAgg = new Aggregation { Id = aggId, Name = "Test Agg Entry", Type = "SUM" }; dbContext.Aggregation.Add(createdAgg); dbContext.SaveChanges(); Aggregation agg = dbContext.Aggregation.Find(aggId); Assert.AreEqual(agg.Id, aggId); Assert.AreEqual(agg.Name, createdAgg.Name); agg.Name = "BarBar"; dbContext.Aggregation.Update(agg); dbContext.SaveChanges(); Aggregation updatedAgg = dbContext.Aggregation.Find(aggId); dbContext.Aggregation.Find(agg.Id); Assert.AreEqual(updatedAgg.Name, "BarBar"); dbContext.Aggregation.Remove(updatedAgg); dbContext.SaveChanges(); Assert.AreEqual(dbContext.Aggregation.Find(aggId), null); }
/// <summary> /// Inserts the passed entity into the database /// </summary> /// <param name="entity">The entity to be inserted</param> /// <returns></returns> public T Insert(T entity) { dbContext.Add(entity); dbContext.SaveChanges(); T insertedRecord = this.GetOne(entity); return(insertedRecord); }
public void TestCreate() { Aggregation createdAgg = new Aggregation { Id = testId, Name = "Test Agg Entry", Type = "SUM" }; Aggregation aggregation = repo.Insert(createdAgg); Aggregation agg = dbContext.Aggregation.Find(testId); Assert.AreEqual(agg.Id, testId); // Cleanup the inserted record dbContext.Aggregation.Remove(agg); dbContext.SaveChanges(); }
public void TestUpdate() { Aggregation createdAgg = new Aggregation { Id = testId, Name = "Test Agg Entry", Type = "SUM" }; dbContext.Aggregation.Add(createdAgg); dbContext.SaveChanges(); createdAgg.Name = "Entry"; dbContext.Dispose(); repo.Update(createdAgg); dbContext = new ResearcherProfilerRepositoryContext(); // Retrieve record from database Aggregation updatedAgg = dbContext.Aggregation.Find(testId); dbContext.Aggregation.Find(testId); Assert.AreEqual(updatedAgg.Id, testId); Assert.AreEqual(updatedAgg.Name, "Entry"); // Cleanup the inserted record dbContext.Aggregation.Remove(updatedAgg); dbContext.SaveChanges(); }