Exclude Certain Database Objects from the Build Depending on Configuration Settings - visual-studio-2012

I have a database project in Visual Studio 2012 with SSDT (latest as of this writing). In the database project, I have a schema called "UNITTEST" which contains tons of stored procedures that create, destroy, and provide other helper functionality for the unit tests. We do this because it gives us the ability to control our test data centrally rather than inside each unit test. Now that's fine and all however, I don't want to publish this schema or any of the objects inside of this schema to production.
So my question.. Is there a way to stop SSDT/VS2012 from including the UNITTEST schema in the production build deployment script?
I'm thinking there should be a way to do it depending on the solution configuration settings and publish profiles. If my configuration is set to "Release" then I want the build to perform a bit differently.
Builds are very new to me. I found this question: build-different-scripts-depending-on-build-configuration but I can't seem to get the answer to fulfill my problem. This question also doesn't help although it's very similar: bind-the-deploy-and-publish-destination.
Is anyone else managing something like this? The other developers in my team are just modifying the published script to remove these objects but I HATE manual work, there HAS to be a solution! :)
Thanks all!

One of my schemas references a lot of sys.* objects which created a lot of errors in the build. I created another project in the solution and moved that schema to the new project.
Luckily you can build and publish at the project level.
This allows me to keep the other schema in change control at least.
(It may also help to set the Properties on the SQL files to Build Action: None)

Partial/Composite projects might be useful here. Main project contains all of your necessary DB objects for your apps to run. The partial project references the main project, but then contains all of the "Test" code.
Here are a couple of options from Jamie Thomson:
http://sqlblog.com/blogs/jamie_thomson/archive/2013/03/10/deployment-of-client-specific-database-code-using-ssdt.aspx --This may be the simplest way to handle this
http://sqlblog.com/blogs/jamie_thomson/archive/2012/01/01/implementing-sql-server-solutions-using-visual-studio-2010-database-projects-a-compendium-of-project-experiences.aspx --Lots of good information in this post and most of it also applies to SSDT SQL Projects.
http://msdn.microsoft.com/en-us/library/dd193415.aspx - Composite projects for larger DBs. This could potentially work for you as well.

Related

SSIS Shared database connection strings between parent and child packages

I want to be able to build 30+ packages in SSIS and be able to test/develop them in isolation. I also want to be able to run these from a Master/Parent package.
When it comes to delivering the SSIS parent package I want to be able to change the connection string once and have this trickle down to all child packages. Other developers will be building and testing without using the master package and want to be able to develop these in isolation.
I've seen many articles on XML config/parameter mappings etc. but I've not seen any definitive guide on how this should be done & what is best practice.
The project we have created also only allows packages to be linked in the solution as an external reference rather than as project links (is this the legacy format?). I'm wondering if this type of project could hamper the ability to achieve shared connection strings.
Answering this myself for reference. Basically there is no streamlined way of doing this in the Package Deployment model. It is much easier to achieve this using the Project Deployment model which is the default in VS2012. However, we don't have this luxury.
I had to create some parent variables contained in the master package. These are then set to the XML config. The child packages then have direct config links to the parent variables, with the target properties mapped to the connection string properties of the connection managers.

How to turn off Entity Framework CF Migrations for an environment

Is it possible to turn off Entity Framework using the web.config? In the application I'm developing we have the following environments
Development
Continuous Integration
Integration Testing
Production
The Integration Testing and Production databases are managed by a database administrator, so we have to send them a script to make changes to the database.
I've spent hours Googling and looking through old projects, and I can't find how to do this or remember if we ever turned off migrations on the old projects in the first place.
From the lack of information I'm doubting if what I'm asking is needed or possible, but there is something in the back of my head that's annoying me about this so I thought I'd ask the experts.
The easiest method is to simply delete the dbo._MigrationHistory table from these environments. If that table doesn't exist, then only an "initial" migration can ever be generated against that database, which will fail if someone tries to actually apply it to a database with existing tables.
You could set the database initializer in the config file as described at the bottom here, so you can have an updating initializer in the environments you want

VS2012 Database Project Validation

I've set up a new Visual Studio 2012 Database Project to hold the assets for a database and I'm having problems getting the project to build properly. The issue that I'm facing is that we have custom code within our database scripts that does certain evaluations when executed. This is by design, and works well. However because it's more complex than the standard database script (for say a table) the project won't build. I'd like to turn off the validation so that the project can build and deploy without being failing the build. Is there a way to turn off the validation portion of the project? I'm new to working with DB project types in VS, so not sure what all may be available. Any other strategies or work-arounds are also welcome.

How do I deploy different files for running Integration Tests on different architectures?

We have multiple test projects that access databases directly. Those tests basically validate our sql queries written in C# code. Unfortunately, they are not separated at the moment and are in the same assemblies that also house true, non-dependent Unit tests (I think those database tests are considered Integration test, correct me if I'm wrong).
Currently, we use 2 testsettings files (sqlserver.testsettings and oracle.testsettings) to deploy a different 'ConnectionStrings.config' file before running the tests. Each of them have connection strings specific to their test databases, that should be created before any tests are run. We do this because we want to test these database methods with both SqlServer and Oracle databases, since some of our clients use SqlServer while others use Oracle.
With this in mind, we have an 'app.config' file on the test projects that contains something along these lines:
<?xml version="1.0"?>
<configuration>
<connectionStrings configSource="ConnectionStrings.config"/>
</configuration>
I would like to know if there would be another way to do this without using the testsettings file, which is in this case already deprecated in favor of the new format used by 'runsettings' files. I can't find the equivalent custom-file-deployment feature on runsettings specifications though, and considered creating multiple build configurations using XML transformations over the ConnectionStrings.config or app.config files.
The problem with XML transforms is that it is currently not supported for these types of projects, and I had a very hard time with SlowCheetah when going to the build server, and ultimately decided against using it (I had this same configSource scenario on one of our Web Application projects and tried transforming the external config file. I ended up merging the file with the web.config and using the standard msdeploy transformation).
What would you recommend in this case? This must also be runnable on our build server. At the moment, we can specify the same tests to be run with both testsettings files there.
Ideally we would also like that SqlServer tests be the standard for all developers, and Oracle tests would only be selected to run on our build server. This does not work right now, since every developer needs to specifically select the sqlserver.testsettings file prior to running the tests the first time. With the build configuration idea this could be achieved, so I'm leaning towards that at the moment, but I would like to hear a potentially better approach to the problem.
I have a feeling we are doing something very wrong in this whole process (and this includes the ideas presented in this post) and that there should be a much easier and straightforward way of doing it.

Testing Web Site Project with NUnit

i'm new in web dev and have following questions
I have Web Site project. I have one datacontext class in App_Code folder which contains methods for working with database (dbml schema is also present there) and methods which do not directly interfere with db. I want to test both kind of methods using NUnit.
As Nunit works with classes in .dll or .exe i understood that i will need to either convert my entire project to a Web Application, or move all of the code that I would like to test (ie: the entire contents of App_Code) to a class library project and reference the class library project in the web site project.
If i choose to move methods to separate dll, the question is how do i test those methods there which are working with data base? :
Will i have to create a connection to
db in "setup" method before running
each of such methods? Is this correct that there is no need to run web appl in this case?
Or i need to run such tests during
runtime of web site when the
connection is established? In this case how to setup project and Nunit?
or some another way..
Second if a method is dependent on some setup in my .config file, for instance some network credentials or smtp setup, what is the approach to test such methods?
I will greatly appreciate any help!
The more it's concrete the better it is.
Thanks.
Generally, you should be mocking your database rather than really connecting to it for your unit tests. This means that you provide fake data access class instances that return canned results. Generally you would use a mocking framework such as Moq or Rhino to do this kind of thing for you, but lots of people also just write their own throwaway classes to serve the same purpose. Your tests shouldn't be dependent on the configuration settings of the production website.
There are many reasons for doing this, but mainly it's to separate your tests from your actual database implementation. What you're describing will produce very brittle tests that require a lot of upkeep.
Remember, unit testing is about making sure small pieces of your code work. If you need to test that a complex operation works from the top down (i.e. everything works between the steps of a user clicking something, getting data from a database, and returning it and updating a UI), then this is called integration testing. If you need to do full integration testing, it is usually recommended that you have a duplicate of your production environment - and I mean exact duplicate, same hardware, software, everything - that you run your integration tests against.

Resources