public static object ApiPaySaveAddress(IRequest context) { var siteId = context.GetPostInt("siteId"); var sessionId = context.GetPostString("sessionId"); var deliveryId = context.GetPostInt("deliveryId"); var addressInfo = context.GetPostObject <AddressInfo>("addressInfo"); var isEdit = context.GetPostBool("isEdit"); addressInfo.UserName = context.UserName; addressInfo.SessionId = sessionId; if (isEdit) { AddressDao.Update(addressInfo); } else { addressInfo.Id = AddressDao.Insert(addressInfo); } AddressDao.SetDefault(context.UserName, sessionId, addressInfo.Id); var cartInfoList = CartDao.GetCartInfoList(siteId, context.UserName, sessionId); var deliveryInfo = DeliveryDao.GetDeliveryInfo(deliveryId); var deliveryFee = Utils.GetDeliveryFee(cartInfoList, addressInfo, deliveryInfo); return(new { addressInfo, deliveryFee }); }
public void IntegrationTest() { var connection = TestSession.GetConnection(); connection.Open(); #region good insertion and select by id test AddressModel inserted = new AddressModel(); inserted.AddressLine1 = TestSession.Random.RandomString(60); inserted.AddressLine2 = TestSession.Random.RandomString(60); inserted.City = TestSession.Random.RandomString(30); inserted.StateProvinceID = TestSession.Random.Next(); inserted.PostalCode = TestSession.Random.RandomString(15); inserted.SpatialLocation = TestSession.Random.RandomSqlGeography(); inserted.rowguid = Guid.NewGuid(); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Insert(connection, new[] { inserted }); var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new AddressModelPrimaryKey() { AddressID = inserted.AddressID, }); CollectionAssert.IsNotEmpty(selectedAfterInsertion); var selectedAfterInsert = selectedAfterInsertion.Single(); Assert.AreEqual(inserted.AddressID, selectedAfterInsert.AddressID); Assert.AreEqual(inserted.AddressLine1, selectedAfterInsert.AddressLine1); Assert.AreEqual(inserted.AddressLine2, selectedAfterInsert.AddressLine2); Assert.AreEqual(inserted.City, selectedAfterInsert.City); Assert.AreEqual(inserted.StateProvinceID, selectedAfterInsert.StateProvinceID); Assert.AreEqual(inserted.PostalCode, selectedAfterInsert.PostalCode); Assert.AreEqual(inserted.SpatialLocation, selectedAfterInsert.SpatialLocation); Assert.AreEqual(inserted.rowguid, selectedAfterInsert.rowguid); Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate); #endregion #region update and select by id test inserted.AddressLine1 = TestSession.Random.RandomString(60); inserted.AddressLine2 = TestSession.Random.RandomString(60); inserted.City = TestSession.Random.RandomString(30); inserted.StateProvinceID = TestSession.Random.Next(); inserted.PostalCode = TestSession.Random.RandomString(15); inserted.SpatialLocation = TestSession.Random.RandomSqlGeography(); inserted.rowguid = Guid.NewGuid(); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Update(connection, new[] { inserted }); var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new AddressModelPrimaryKey() { AddressID = inserted.AddressID, }); CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss); var selectedAfterUpdate = selectedAfterUpdateAddresss.Single(); Assert.AreEqual(inserted.AddressID, selectedAfterUpdate.AddressID); Assert.AreEqual(inserted.AddressLine1, selectedAfterUpdate.AddressLine1); Assert.AreEqual(inserted.AddressLine2, selectedAfterUpdate.AddressLine2); Assert.AreEqual(inserted.City, selectedAfterUpdate.City); Assert.AreEqual(inserted.StateProvinceID, selectedAfterUpdate.StateProvinceID); Assert.AreEqual(inserted.PostalCode, selectedAfterUpdate.PostalCode); Assert.AreEqual(inserted.SpatialLocation, selectedAfterUpdate.SpatialLocation); Assert.AreEqual(inserted.rowguid, selectedAfterUpdate.rowguid); Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate); #endregion #region delete test _tested.Delete(connection, new[] { inserted }); var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new AddressModelPrimaryKey() { AddressID = inserted.AddressID, }); CollectionAssert.IsEmpty(selectedAfterDeleteAddresss); #endregion connection.Close(); }