public async void TestDelete() { ConnectionFactory connectionFactory = new ConnectionFactory(Environment.Testing); ILocationDao locationDao = new LocationDao(connectionFactory); Location location = await InsertLocation(connectionFactory); Assert.NotNull(await locationDao.FindById(location.Id)); await locationDao.Delete(location.Id); Assert.Null(await locationDao.FindById(location.Id)); }
public void IntegrationTest() { var connection = TestSession.GetConnection(); connection.Open(); #region good insertion and select by id test LocationModel inserted = new LocationModel(); inserted.Name = TestSession.Random.RandomString(50); inserted.CostRate = TestSession.Random.RandomDecimal(10, 4); inserted.Availability = TestSession.Random.RandomDecimal(8, 2); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Insert(connection, new[] { inserted }); var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new LocationModelPrimaryKey() { LocationID = inserted.LocationID, }); CollectionAssert.IsNotEmpty(selectedAfterInsertion); var selectedAfterInsert = selectedAfterInsertion.Single(); Assert.AreEqual(inserted.LocationID, selectedAfterInsert.LocationID); Assert.AreEqual(inserted.Name, selectedAfterInsert.Name); Assert.AreEqual(inserted.CostRate, selectedAfterInsert.CostRate); Assert.AreEqual(inserted.Availability, selectedAfterInsert.Availability); Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate); #endregion #region update and select by id test inserted.Name = TestSession.Random.RandomString(50); inserted.CostRate = TestSession.Random.RandomDecimal(10, 4); inserted.Availability = TestSession.Random.RandomDecimal(8, 2); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Update(connection, new[] { inserted }); var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new LocationModelPrimaryKey() { LocationID = inserted.LocationID, }); CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss); var selectedAfterUpdate = selectedAfterUpdateAddresss.Single(); Assert.AreEqual(inserted.LocationID, selectedAfterUpdate.LocationID); Assert.AreEqual(inserted.Name, selectedAfterUpdate.Name); Assert.AreEqual(inserted.CostRate, selectedAfterUpdate.CostRate); Assert.AreEqual(inserted.Availability, selectedAfterUpdate.Availability); Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate); #endregion #region delete test _tested.Delete(connection, new[] { inserted }); var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new LocationModelPrimaryKey() { LocationID = inserted.LocationID, }); CollectionAssert.IsEmpty(selectedAfterDeleteAddresss); #endregion connection.Close(); }