How to use Microsoft built in Tests with NHibernate For Repository Layer(DAL)? - mstest

Can any body tell me how to use Microsoft built in Tests with NHibernate For Repository Layer(DAL)?

I'm using NUNIT tests to test NH mappings.
you create test (regular) that create objects, updates them and delete them.
Just like any other test - you assert for the results by checking the DB after the operation.
(if you delete an object, you should be able to "get" it... ect...)
I create a session in the beginning of each test, and close it at the end.
same goes to any other function the dal has...
NUnit website

Related

Query for Test plan Children

Is there a way in Visual Studio to query for work items by specifying the name or id of the test plan of which they're part?
I have multiple test plans in a single team project so querying on team project alone does not suffice.
As it's not possible to query for all tests by test plan in VS, how are test case linked at database level?
TFS does allow execution of SQL queries using the the MS client libraries using a WorkItemStore instance.
$wiStore = $Collection.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
$workitems = $wiStore.Query("")
Ultimately I'm attempting to iterate all attachments contained in a test project. Right now this is achieved by retrieving all tests and their (shared) steps and listing their attachments.
Unfortunately,there is no this option in work item queries for now. Example work item queries
Can't find the association between the test plan and test suite (children). The simplest way to query all test suit childrens, you may specify the test suite parent ID {usually =(Test Plan ID+1)}
Update:
I'm not sure if I understood it correctly. If you want to list all tests including the child suite as below. This can be achieved as below.
And it can't be achieved by query for work items in Visual Studio.

VS2013 migrating automátically my db even when AutomaticMigrationsEnabled = false;

I have an application with several code based migrations (EF5 code first) and an initializer that inherits from CreateDatabaseIfNotExists then I install that application on a production machine for the first time leting CodeFirst create the database from scratch. After that I add another code based migration and generate the migration script on my development machine and apply that script on the production machine. Then when I run my app on the production machine I'm getting errors. Those errors were generated because the code on my migrations are not being executed and there are code on those migrations that must be executed (for instance I have File Stream on my db).
Then, to solve that I changed my initializer to MigrateDatabaseToLatestVersion with AutomaticMigrationsEnabled = false. That solution solved the problem of executing all migrations code on first create but now I have this problem: VS2013 migrates the database automaticaly (if I add another migration) what I expect is to have an exception because AutomaticMigrationsEnabled = false in VS2012 that is happening BUT VS2013 IS MIGRATING AUTOMATICALLY.
Why is that happening? What I'm doing wrong?
Thanks
Automatic Migrations Enabled refers to the process of trying to automatically migrate your database to match your DbContext. For example, say you create your DbContext and run it once. Then you add a new table. With Automatic Migrations, you don't need to run Add-Migration, you can just run your app again and EF will automagically modify your database (note: it doesn't do this for all schema changes, but it makes a good effort. Sometimes you will still need to use Add-Migration).
Since your initializer is set to MigrateDatabaseToLatestVersion, any time the DbContext initialized it will run all of the migrations that are available. If there is any mismatch between your DbContext and the schema your migrations generate, you'll get an exception.
It sounds like the scenario you're expecting is when there is a mismatch between your DbContext and your database, you should get an exception. If this is what you want, you should not set your initializer to MigrateDatabaseToLatestVersion.

Is there a way to find test cases that are not part of any test suite?

The way that we use Microsoft Test Manager means that we want every test case to be included in at least one test suite. However, we have (manually) discovered some test cases that are not part of any test suite. Finding these by hand is very time consuming.
Therefore: Is there any way to find all test cases that are not part of any test suite?
(We're using Microsoft Test Manager 2012/2013.)
You can't do it using MTM (no matter which version you are using).
Using TFS 2012 the only way is to use TFS-API, here a short example how to check if a particular Test Case is a part of any Test Suite:
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
// Current user credentials will be used to access to TFS
TfsTeamProjectCollection tfsCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(<TFS Url>));
tfsCollection.EnsureAuthenticated();
ITestManagementService testManagementService = tfsCollection.GetService<ITestManagementService>();
ITestManagementTeamProject teamProject = testManagementService.GetTeamProject(<team project name>);
// Get all Test Suites your Test Case belongs to
// (Across all Test Plans in the Team Project)
ITestSuiteCollection testSuites = teamProject.TestSuites.ReferencingTestCase(<test case id>);
bool doesItBelongToAnyTestSuite = testSuites.Any();
If you would use TFS 2013 it will be possible to achieve this using Work Item queries since Test Plan and Test Suite become Work Items with TFS 2013 Update 3 (RC was released on 2. July 2014).

Something similar to NUnit TestCaseSource in Visual Studio unit testing

Is there anything similar to NUnit TestCaseSource attribute in Visual Studio unit testing? The closest solution I found was to use a DataSource. But I don't want to store my test case parameters in a data source.
Datasource is one option to take the test input. You can save your test data in many file format (xml, xls or in sql db)
But if you don't want to store your test data, then use TestInitialize() attribute in any method that will execute before any of your test cases. Save all your test data run time in xml,xls or in sql db through this method and then using datasource use it in your test cases.
Here is msdn link for VSTS unit test. Hope this will help you.

Can MSTest run a specific method each time it startsup?

Question
Is there a way to have a method that will always run anytime that test assembly is run through MSTest?
Similar to how the [TestInitialize] and [ClassInitialize] attributes work, but for the entire assembly. I do not want to have to add code to every test class's [ClassInitialize] method.
Reasoning
Some of my tests interact with the database. They delete data and other things that would be very harmful to a production database. There is only a configuration file that tells my unit test project to run against the non-production database.
I would feel better if there was a method that would run on startup that would say "Okay Database name is not 'production'"
Ideas
Log4Net uses an assembly attribute to configure itself.
using log4net.Config;
[assembly: XmlConfigurator()]
Perhaps I can do something simliar?
[assembly: CheckDatabaseNameNot("production")]
Have you tried [AssemblyInitialize]?

Resources