Exploring the source code

Download and unzip the download package. Start MS Visual Studio 2013 as an administrator and open the VitaAll.sln solution file. You will see a number of folders and projects in the Solution Explorer:

VITA projects in Solution Explorer
The solution projects are grouped into the following solution folders:
1.Framework - core components of VITA. Includes the projects:
  • Vita - main functionality assembly.
  • Vita.Web - Web-related functionality, integration with Web API stack
2.Drivers - contains database drivers (providers) for different database servers. The following servers are supported: MS SQL Compact Edition (SQL CE); MySql; Postgres; SQLite. The driver for MS SQL Server is embedded into Vita.dll.
3.Modules - contains module projects.
  • Vita.Modules - this project is a container for a number of standard modules that are provided out of the box. Contain useful functionality that can be easily imported into your solution.
4.Samples - sample projects.
  • Vita.Samples.BookStore - a sample project implementing simple online book store
  • Vita.Samples.BookStore.SampleData - generator of sample data used in unit test. Also contains Google Import facility, to import real books from Google Books API for sample UI project.
  • Vita.Samples.BookStore.UI - a sample Web BookStore, a Single-Page Application built on AngularJS, with VITA-based API controllers handling the data on the server side.
5.UnitTest - a set of unit-test projects.
  • Vita.UnitTests.Common - a utility library for test projects, not a test container by itself.
  • Vita.UnitTests.Basic - unit tests for basic VITA functionality.
  • Vita.UnitTests.Extended - unit tests for advanced functionality; uses sample book store application.
  • Vita.UnitTests.Web - unit tests for Web components; uses Web service for sample book store application.
6.Tools folder
  • Vita.Tools.ToolLib - tooling library
  • Vita.Tools.Vdbtool - a command-line tool; implements::
    • DB-First scenario - generates entity definitions (c# code) from the pre-existing database
    • DB Update scripts - generates DB update scripts for manually updating the database

Running the Test projects

The best way to approach the VITA framework and understand what it offers is to explore the unit tests - run them, see the result data in the database and explore the test code. Unit tests include many code snippets illustrating various aspects of the framework - basic CRUD capabilities, LINQ engine, entity caching, authorization framework, various logging/diagnostic facilities, Web API integration.
The Web-related projects are dependent on Web API packages - they will be downloaded automatically once you first compile the solution.

Important - do it first:
  1. Before running the unit tests turn off the 'Break on CLR exceptions' setting in Visual Studio (clear all checkboxes). Use Debug/Exceptions dialog in main VS Menu. Tests and samples throw and handle exceptions, so stopping would disrupt normal test execution.
  2. Create the following empty databases on local server and adjust the connection strings in App.config files if necessary: VitaTest, VitaBooks, VitaBooksLogs (MS SQL only) . See more on test databases below.

Unit test projects can be run in 2 modes:
  1. As traditional unit tests through Test Explorer window in VS. In this mode the tests run for MS SQL Server 2012. You can change the target by modifying the App.config file in unit test projects.
  2. As a console application for all supported database servers - just select the project as 'Startup Project' and click the Run button in Visual Studio (F5). The set of servers to run against is configured in the App.config files.
The VITA project sources reference Nuget package for native Db providers - these should be downloaded automatically when you run the unit tests. You should have the database servers installed locally or available on remote machines.
You should adjust connection strings in App.config file in the corresponding unit test project. Before running the unit tests you should create the test databases for MS SQL Server, and Postgres. Create the following empty databases:
  • VitaTest
  • VitaBooks
  • VitaBooksLogs - this database is required for MS SQL (the way unit tests are setup by default - there's a connection string pointing to this database); you can create this database for other servers as well, and add connection strings in config file(s).
  • VitaBooksUI - this MS SQL database is used by the sample UI Web App. This app is configured to work with MS SQL, so you need to create it only for this server.
For other servers:
  1. MS SQL CE, SQLite - both use empty database files included in test projects; these files are copied to the bin folder on project compile and the copy is used as a test database
  2. Local MySql installation - MySql treats schema/database terms interchangeably, so you will see 'schemas' created by unit tests as databases in local server.
Do not forget to adjust the connection strings in the app.config files.

Run the units tests using -
  1. VS Test Explorer window - right-click on the test group and select 'Run selected tests'.
  2. As console applications - mark the test project as 'Startup project', and then simply launch it from VS. The console window will appear and you will see the progress report as the system runs the tests in different modes for different servers.
Once the tests complete, open Database browser tool of your choice (ex: MS SQL Management Studio, SMS) and browse the generated data in the database tables. All database objects are created automatically by unit tests, as part of the automatic schema update functionality. The initial data (for Books sample) are generated by the SampleDataGenerator.cs class in BookStore sample project; some working data is added/modified in unit tests run. Inspect the source code for unit tests, see how things are done.

Running the sample Web BookStore application.

Locate the Vita.Samples.BookStore.UI project. Check and adjust the connection strings in the web.config file. Set the project as startup project, and launch it. On the first start the application initializes the database and then imports around 300 books from Google Books API. The initial start may take up to 1 minute, before the Home page appears. Once it opens, browse books, use search, use test accounts to login (usernames and passwords are listed in Login page). Signup as a new user, fill up the shopping cart, make a purchase. Browse the underlying code, see how it is implemented. Enjoy!

Last edited Dec 31, 2015 at 3:54 PM by rivantsov, version 39


No comments yet.