Skip to content

Instantly share code, notes, and snippets.

@tucaz
Created February 2, 2010 23:31
Show Gist options
  • Save tucaz/293171 to your computer and use it in GitHub Desktop.
Save tucaz/293171 to your computer and use it in GitHub Desktop.
[TestMethod]
public void CanSaveAndDeleteAFunctionButNotTheApplication()
{
//Arrange
Application myApp = new Application()
{
Description = "MyApp",
KeyName = "MyApp",
Name = "My App",
Url = "http://www.myapp.com"
};
Function myFunc = new Function()
{
Application = myApp,
Code = "MyFuncCode",
Description = "My Func Desc"
};
//Act
//Create the function with and Application
_session.Save(myFunc);
int myNewFuncId = myFunc.Id;
_session.Flush();
_session.Clear();
//Retrieve the function and the Id of the application
var myOldFunc = _session.Load<Function>(myNewFuncId);
var myOldAppId = myOldFunc.Application.Id;
//Now deletes the Function
_session.Delete(myOldFunc);
_session.Flush();
_session.Clear();
//And tries to load the application to make sure that
//it was not deleted by cascade
var myOldApp = _session.Load<Application>(myOldAppId);
//The function must be null because I deleted it
var myReallyOldFunc = _session.Get<Function>(myNewFuncId);
//Assert
Assert.IsNotNull(myOldApp);
Assert.AreEqual<int>(myOldAppId, myOldApp.Id);
Assert.IsNull(myReallyOldFunc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment