Create a solution with name “StudentsDatabase” which will have a class library project named as “StudentsManager” and a unit test project named as “Test”.
Class library project will have following features-
It will have one contract class named as “Student” with following data members-
i. Int id (can be access from anywhere but can be set only in this assembly)
ii. String name
iii. Int age
iv. Int branch
v. Int section
It will have two enum files with names as “Branch” and “Section” with following values-
i. Branch enum will have following values with their corresponding int value starting from 101-
CS, IT, ECE, ME, EE, EI, CIVIL, CHEM, ENV
ii. Section enum will have values-
A, B, C, D, E, F, G, H
Main class with name as “Students” which will store data [Hint: have one private static variable for list of Student] and perform following operations (need to create methods for each)-
i. Add -> it accepts Student type data, auto assign id based on count of stored records (e.g. 1 for first student, 2 for second student etc) and return newly added student id. If given student name matches with any of the stored student name then it throw exception with message “Student record with same name already exists.”
ii. GetById -> it accepts integer id and return Student type data. If given id is not present in database then throws exception with message "No record found."
iii. ClearAll -> it clears all records stored in database.
Unit test project will have following features-
It will have reference to above created library project.
It will have a POCO class with two data members-
i. Object result -> it will store returned data from Add/GetById method
ii. String errorMessage -> it will store error message thrown from Add/GetById method if any
It will have 2 features files-
i. AddStudent -> 2 scenarios (one for normal adding and another for duplicate name student record adding) [Remember – branch name and section will be given in feature file like “ECE” and “B” respectively. You have to store their equivalent int value (defined in enum) in database.]
ii. GetStudent -> 2 scenarios (one for getting record by valid id and another for getting record by invalid id)
It will have hooks file which will have a hook to call ClearAll method from Students class. This hook should be running before each scenario.
It will have multiple step definitions files according their step type e.g. WhenStep file to store all when steps and ThenSteps file to store all then steps.
In then steps you need to get expected outcome from result object of POCO class using casting.
To work with POCO class in your step definition files, use context injection.
Frame scenario in such a way that pre-requisite of test case is also done in scenario itself.
e.g. if I want to write a scenario to delete a record then scenario will be like this [This is for example purpose only]-
Given database is already having record with name as “Mohan”
When I delete the record with name as “Mohan”
Then I should be getting success result
Here I’ll do actions like this->
In Given -> I’ll add a record with given name
In When -> I’ll delete record by calling delete method
In Then -> I’ll validate returned bool value in above step with ‘True’
Hello How are you?
I am C# developer with nearly 3 years experience in .NET , SQL server , and other technologies . I can build the Restful Api for you .
I use best practices in .NET core , i try to adhere to the REST specifications as much as possible .
I work on my own , i dont give you projects to other users .
I speak fluent English .
Thanks