STT Labsss
STT Labsss
Lab Manuals
2. After making the program in C# then I test it in the visual studio line by line by using
break point in C#.
3. After White box testing by using break point in visual studio show Output. In this all
operation perform good.
Division Operation:
Modulus Operation:
Addition Operation:
Minus Operation:
Lab # 02: Decision-Making Structures in C#
Objective:
Learn how to use decision-making structures (if, if-else, switch) to write programs that make
choices based on conditions.
Implement white box testing
Implement black box testing
OUTPUT:
Task 2: Student Grade Book
Create a program that accepts student marks and assigns a grade based on the score.
OUTPUT:
OUTPUT:
Lab # 03: Loops in C#
Objective:
Understand and implement for, while, and do-while loops to solve repetitive tasks efficiently.
Testing: Breakpoint added before the loop; verified each iteration and output.
Task 2: Sum of Even Numbers (1 to 50)
Description: Program calculates the sum of all even numbers between 1 and 50.
Testing: Breakpoint added inside the loop to watch how the sum variable updates.
Lab # 04: Arrays in C#
Objective:
Learn how to declare, initialize, and manipulate arrays.
Learn single dimension array
Learn understand multidimensional array
Task 1: Single-Dimensional Array
1. Create an array that stores 5 integers.
3. Output: The array is displayed in reverse order. We use a for loop to traverse the array
backward and print each number.
Task 2: Multidimensional Array (Student Info)
1. Create a 2D array (string[,] studentInfo) to store student information.
2. Display: The program will print the student data in a tabular format.
Lab # 05: Function, Classes and MSUnit testing
Objective:
Understand how to define and call functions and classes to make the code modular and
reusable.
Learn how to use exception handling
Learn how to implement MS Unit testing
Tasks:
Bank Account:
Create a BankAccount Class with Debit and Credit functions:
Create Bank Account Tests class to implement unit testing using MSUnit:
Objective:
Create Relational Database In Visual Studio and Connect with the business Logic.
1. Right Click on the Create Project lab 6_8 and add database in it name as mydb.mdf.
2. Open the mydb and right Click on the table and create table like Users, Categories, products.
Create a project name as lab 6_8 right click on in and add class named as DAO login in visual Studio.
Class Declaration:
This defines a class login_DAO which is responsible for performing operations like signup, login,
and password updates.
The connectionString variable stores the connection details needed to connect to the SQL Server
database (LocalDB in this case).
Signup Method:
Change password:
Purpose: This method checks if the old password is correct using isValid. If valid, it calls
updatePassword to update the password.
Update Password:
Purpose: This method resets the password for a user by verifying their security question and
answer.
It first checks if the email, security question, and answer match any user in the database.
If they match, it calls updatePassword to reset the password.
Menu Loop:
This while loop keeps running until the user chooses to exit.
It shows a menu with options for signup, login, changing passwords, and more.
Signup Option:
When the user selects "Signup", it prompts them to enter details like email, name,
password, etc.
It then calls the Signup method from the login_DAO class to add the user to the database.
Login Option:
When the user selects "Login", they are asked for an email and password.
The isValid method checks whether the credentials are correct.
Change Password Option:
The user provides their email, old password, and new password.
The changePassword method checks if the old password is correct, and then it updates
the password.
This option helps the user reset their password by verifying their security question and
answer.
Exit Option:
3. Run and show the on the black box Output with database.
Signup Process:
IN BLACK BOX:
Login Process:
In Black Box:
Change Password:
In Black Box:
Forget Password:
In Black Box:
Password:
What We Did:
What We Did:
What We Did:
Created a dictionary with student ID (int) as key and name (string) as value.
What We Did:
What We Did:
UsingMicrosoft.VisualStudio.TestTools.Un
itTesting; using
System.Collections.Generic;
namespace ProductApp.Tests
{
[TestClass] public
class ProductServiceTests
{
private ProductService _service;
[TestInitialize]
public void
Setup()
{
string conn = "Data Source=localhost;Initial Catalog=ProductDB;Integrated
[TestMethod]
public void
TestCreateProduct()
{
bool result = _service.CreateProduct("TestWatch", "test.jpg", 99.99m, 5);
Assert.IsTrue(result, "Product should be created successfully.");
}
[TestMethod]
public void
TestReadProducts()
{
List<string> products = _service.ReadProducts();
Assert.IsTrue(products.Count > 0, "There should be products in the list.");
}
[TestMethod]
public void
TestUpdateProduct()
{
bool result = _service.UpdateProduct(1, "UpdatedName", 199.99m, 10);
Assert.IsTrue(result, "Product should be updated.");
}
[TestMethod]
public void
TestDeleteProduct()
{
bool result = _service.DeleteProduct(1); // Use a valid ID
Assert.IsTrue(result, "Product should be deleted.");
}
}
}
Lab # 12:
namespace ProductApp.Tests
{
[TestClass] public
class ProductModuleTests
{
private ProductService
_testProductId;
{
string conn = "Data Source=localhost;Initial Catalog=ProductDB;Integrated
Security=True;";
}
[TestMethod]
public void
TestFullCRUDModule()
{
// 1. Create
"ModuleTest");
Assert.IsNotNull(createdProduct, "Created product not found.");
_testProductId = createdProduct.ProductID;
// 3. Update
// 4. Confirm Update
== _testProductId);
// 5. Delete
bool deleted =
_service.DeleteProduct(_testProductId);
failed.");
// 6. Confirm Deletion
== _testProductId);
1. Introduction
This report outlines the white box testing process for the ProductDB CRUD Console Application developed
in C#. The objective of white box testing is to verify the internal logic and structure of each module and
ensure full statement and branch coverage.
1. Introduction
This report outlines the black box testing process for the ProductDB CRUD Console Application. Black
box testing focuses on testing the application's functionality without knowledge of its internal code
structure. The aim is to validate that the system behaves as expected for different input conditions.
4. Conclusion
Black box testing verified that the application correctly handles valid and invalid inputs. Each feature
(Create, Read, Update, Delete) was tested for positive and negative scenarios. The application met the
functional requirements under all tested conditions.
Lab # 15 & 16:
Product CRUD operation using MS SQL and C#
Task 1: Setting Up the Database
1. Database:
System.Data.SqlClie
nt; namespace
ProductApp
{
class Program
{
static string connectionString = "Data Source=localhost;Initial
while (true)
{
Console.Clear();
Console.WriteLine("=== ProductDB CRUD Application ===");
Console.WriteLine("1. Create Product");
Console.WriteLine("2. Read All Products");
Console.WriteLine("3. Update Product");
Console.WriteLine("4. Delete Product");
Console.WriteLine("5. Exit");
switch (Console.ReadLine())
{
case "1":
CreateProduct();
break;
case "2":
ReadProducts();
break;
case "3":
UpdateProduct();
break;
case "4":
DeleteProduct();
break;
case "5":
return;
default:
Console.WriteLine("Invalid
choice!");
break;
Name: ");
decimal price);
quantity);
input."); return;
string query = "INSERT INTO Products (ProductName, Photo, Price, Quantity) VALUES
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@photo", photo);
cmd.Parameters.AddWithValue("@price", price);
cmd.Parameters.AddWithValue("@qty", quantity);
try
{
con.Open();
cmd.ExecuteNonQuery();
SqlConnection(connectionString);
SqlCommand(query,con);
try
{
con.Open();
cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine($"ID: {reader["ProductID"]}, Name: {reader["ProductName"]}, Price:
{reader["Price"]}, Qty: {reader["Quantity"]}, Photo: {reader["Photo"]}");
}
}
catch (Exception ex)
{
to update: "); if
id))
Console.WriteLine("Invalid ID.");
return;
decimal price);
quantity);
input."); return;
string query = "UPDATE Products SET ProductName = @name, Price = @price, Quantity =
@qty WHERE ProductID = @id";
using SqlConnection con = new
SqlConnection(connectionString);
using SqlCommand cmd = new
SqlCommand(query, con);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@price", price);
cmd.Parameters.AddWithValue("@qty", quantity);
cmd.Parameters.AddWithValue("@id", id);
try
{
con.Open();
int rows =
cmd.ExecuteNonQuery();
to delete: "); if
id))
Console.WriteLine("Invalid ID.");
return;
ProductID = @id";
using SqlConnection con = new
SqlConnection(connectionString);
cmd.Parameters.AddWithValue("@id", id);
try
{
con.Open();
int rows =
cmd.ExecuteNonQuery();