9 Oct 2015

Is there any rule to decide what columns should be put in Included in non clustered index and in which order

Why use the INCLUDE clause when creating an index? Is there any rule to decide what columns should be put in Included in non clustered index and in which order.



I got that for the following query :

SELECT PrimaryInformation_Id, Company_Id, LastName
FROM Employee_PrimaryInformation
WHERE Company_Id = 5

I am suggested to make index like this:

CREATE NONCLUSTERED INDEX NC_EmpPrim
  ON Employee_PrimaryInformation(PrimaryInformation_Id, Company_Id)
  INCLUDE (LastName)

Yes, i know. what you think why can't we make index like this'

CREATE NONCLUSTERED INDEX NC_EmpPrim
      ON Employee_PrimaryInformation(PrimaryInformation_Id, Company_Id, LastName)

OR

CREATE NONCLUSTERED INDEX NC_EmpPrim
      ON Employee_PrimaryInformation(Company_Id, LastName)
INCLUDE (PrimaryInformation_Id)

For your example I've added a comment.'

CREATE INDEX <name> ON <table> (KeyColList) INCLUDE (NonKeyColList)
Where:

  • KeyColList = Key columns = used for row restriction and processing 
  • WHERE, JOIN, ORDER BY, GROUP BY etc
  • NonKeyColList = Non-key columns = used in SELECT and aggregation (e.g. SUM(col)) after selection/restriction

2 Oct 2015

Creating a Simple User Login Form in MVC

Step 1. Creating a project.


Then select that you are using Razor engine. Check create Tests if you are planning to use it later in your project. If not - leave it unchecked.



Right click on App_Data -> Add -> New item ->Data -> SQL Server Database -> OK.
Now we need a users table.
Right click on Tables and open New Query window.



Now paste code below to that query window and click execute (shortcut CTRL+SHIFT+E)

CREATE TABLE [dbo].[System_Users]
(
[Id] INT NOT NULL IDENTITY ,
[Username] NVARCHAR(50) NOT NULL,
[Password] NVARCHAR(50) NOT NULL,
[RegDate] DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
[Email] NVARCHAR(50) NOT NULL,
PRIMARY KEY ([Id])
)
GO
CREATE INDEX [IX_System_Users_Username] ON [dbo].[System_Users] ([Username])
GO
INSERT INTO [dbo].[System_Users]
([Username], [Password], [Email])
VALUES
('admin', '123456', 'admin@test.com')
GO


Step 3. Creating a HomeController 

OK. Now we need a home controller which will be our first page.







Step 4. Creating a Home view.

Right click on method name -> Create view.




Call it Index (The same as method name) and select to use layout.




Step 5. Creating a User model

User model is required to handle user information and for form creation.

Right click on Models -> Add -> New item -> Code -> Class; Name it User.cs.

In User class code should look like this:






using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel.DataAnnotations;

namespace GDDonSimpleLogin.Models
{
    public class User
    {

        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        [Display(Name = "Remember on this computer")]
        public bool RememberMe { get; set; }

        /// <summary>
        /// Checks if user with given password exists in the database
        /// </summary>
        /// <param name="_username">User name</param>
        /// <param name="_password">User password</param>
        /// <returns>True if user exist and password is correct</returns>
        public bool IsValid(string _username, string _password)
        {
            using (var cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;Initial Catalog=D:\GDDON\WORK\DEMO\GDDONSIMPLELOGIN\GDDONSIMPLELOGIN\APP_DATA\DATABASE1.MDF;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"))
            {
                string _sql = @"SELECT [Username] FROM [dbo].[System_Users] WHERE [Username] = @u AND [Password] = @p";
                var cmd = new SqlCommand(_sql, cn);
                cmd.Parameters.Add(new SqlParameter("@u", SqlDbType.NVarChar)).Value = _username;
                cmd.Parameters.Add(new SqlParameter("@p", SqlDbType.NVarChar)).Value = _password;
                cn.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Dispose();
                    cmd.Dispose();
                    return true;
                }
                else
                {
                    reader.Dispose();
                    cmd.Dispose();
                    return false;
                }
            }
        }
    }
}







Step 6. Creating User Controller  

We need a user controller to manage user who's about to log in or log out. Create controller as you did previous and name it UserController. I preffer naming it User (not Users) becouse it stands for ONE user.

This is code which should appear in it.




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace GDDonSimpleLogin.Controllers
{
    public class UserLoginController : Controller
    {
        //
        // GET: /UserLogin/

        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(Models.User user)
        {
            if (ModelState.IsValid)
            {
                if (user.IsValid(user.UserName, user.Password))
                {
                    FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "Login data is incorrect!");
                }
            }
            return View(user);
        }
        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Index", "Home");
        }

    }
}








Step 7. Creating a login view 

Right click on Login method name and create view.




Use layout template as previously.

Step 8. Making login form

Code should look like this:




@model GDDonSimpleLogin.Models.User
@{
    ViewBag.Title = "Login";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true, "Login failed. Check your login details.");
    <div>
        <fieldset>
            <legend>Login</legend>
            <div class="editor-label">
                @Html.LabelFor(u => u.UserName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(u => u.UserName)
                @Html.ValidationMessageFor(u => u.UserName)
            </div>
            <div class="editor-label">
                @Html.LabelFor(u => u.Password)
            </div>
            <div class="editor-field">
                @Html.PasswordFor(u => u.Password)
                @Html.ValidationMessageFor(u => u.Password)
            </div>
            <div class="editor-label">
                @Html.CheckBoxFor(u => u.RememberMe)
                @Html.LabelFor(u => u.RememberMe)
            </div>
            <input type="submit" value="Log In" />
        </fieldset>
    </div>
}





Here we create our form, add labels and validators.

Step 9. Editing _Layout.cshtml page (add login button)

This file is in Views -> Shared folder.

We are going to add this code so it will allow us to login, log out and displays our name.




<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    <div style="width: auto; background-color: #728ea7;">
        @if (Request.IsAuthenticated) {
            <strong>@Html.Encode(User.Identity.Name)</strong>
            @Html.ActionLink("Sign Out", "Logout", "User")
        }
        else {
            @Html.ActionLink("Register", "Register", "User")
            <span> | </span>
            @Html.ActionLink("Sign In", "Login", "User")
        }
    </div>
    @RenderBody()
    @Scripts.Render("~/bundles/jquery")
    @RenderSection("scripts", required: false)
</body>
</html>


1 Oct 2015

Software QA Terminology: Bug Bash

In this article of Software QA Terminology series, we will explore Bug Bash. It is a test activity that is carried out by a number of people simultaneously. It helps in bringing in a fresh perspective to the testing. Let’s dig into it in detail.

Definition:

As WikiPedia puts it: A Bug Bash is a procedure where all the developers, testers, program managers, usability researchers, designers, documentation folks, and even sometimes marketing people, put aside their regular day-to-day duties and “pound on the product”—that is, each exercises the product in every way they can think of. Idea is to get as many bugs into the bug database as possible.



It helps in bringing in a fresh perspective to the testing. It can be helpful in uncovering defects which are unconventional as system gets exposed to variety of users.

Benefits:

Below are some benefits of organizing Bug Bash in your project.

  • Many usability feedback can be found after this activity.
  • Defect which are never encountered during test cycles may be uncovered.
  • It can be helpful to build company morale & encourage people about quality.

Limitations:

All the above points aside, Bug Bash also has some limitations. These includes


  • It would not cover all aspects that you might want to test in your application.
  • Huge documentation(Eg. bug reports) may be produced which makes managing these reports cumbersome.
  • Bug reports may be duplicate and incomprehensible as non-testers may not delve deeper into writing good bug reports.

Best Practices:

Follow below best practices to get the maximum out of Bug Bash sessions.

  • Declare about session of Bug Bash well in advance, about week or two weeks before.
  • Freeze the build on which test activities are to be performed.
  • Have a small briefing session with the team about an overview of the system. After that, let them use the system on their own.
  • Provide the team with some examples of good bug report.
  • Keep incentives to involve participants.

Bug Bash activity can prove fruitful if planned and executed properly. However, it should be used with caution. Have you been involved in Bug Bash before? Let us know if it was useful in your project.