public TravelDataServiceContext()
 {
     // 获得分区连接字符串.
     // PartitionKey代表当前用户.
     this._entityFrameworkContext = new TravelModelContainer(
         this.GetConnectionString(this.SetPartitionKey()));
 }
Пример #2
0
 public void DeleteFromTravelTest()
 {
     TravelModelContainer ctx = new TravelModelContainer();
     Travel travel = ctx.Travels.First();
     ctx.Travels.DeleteObject(travel);
     int result = ctx.SaveChanges();
     Assert.AreEqual(result, 1);
     Travel returnedTravel = this.QueryTravelItemTest(travel.PartitionKey, travel.RowKey, true);
     Assert.IsNull(returnedTravel);
     ctx.Dispose();
 }
Пример #3
0
 public void InsertIntoTravelTest()
 {
     TravelModelContainer ctx = new TravelModelContainer();
     var travel = CreateTravelViewTest();
     ctx.Travels.AddObject(travel);
     int result = ctx.SaveChanges();
     Assert.AreEqual(result, 1);
     ctx.Dispose();
 }
Пример #4
0
 public void UpdateTravelTest()
 {
     TravelModelContainer ctx = new TravelModelContainer();
     Travel travel = ctx.Travels.First();
     travel.Place = "New York";
     int result = ctx.SaveChanges();
     Assert.AreEqual(result, 1);
     Travel returnedTravel = this.QueryTravelItemTest(travel.PartitionKey, travel.RowKey);
     Assert.AreEqual(returnedTravel.Place, "New York");
     ctx.Dispose();
 }
Пример #5
0
 public Travel QueryTravelItemTest(string partitionKey, Guid rowKey, bool allowNull = false)
 {
     TravelModelContainer ctx = new TravelModelContainer();
     var query = from t in ctx.Travels where t.PartitionKey == partitionKey && t.RowKey == rowKey select t;
     Travel travelView = query.FirstOrDefault();
     if (!allowNull)
     {
         Assert.IsNotNull(travelView);
     }
     ctx.Dispose();
     return travelView;
 }
Пример #6
0
 public void QueryFirstTravelItemTest()
 {
     TravelModelContainer ctx = new TravelModelContainer();
     var query = from t in ctx.Travels select t;
     Travel travelView = query.FirstOrDefault();
     Assert.IsNotNull(travelView);
     ctx.Dispose();
 }