CSharp-OOP-Advanced-Unit-Testing-Exercises
CSharp-OOP-Advanced-Unit-Testing-Exercises
This document defines the exercises for "C# OOP Advanced" course @ Software University.
Problem 1. Database
Create a simple class - Database. It should store integers. You should set the initial integers by constructor. Store
them in an array. Your Database should have a functionality to add, remove and fetch all of the stored items. Your
task is to test the class. In other words, create the class and write tests to ensure its methods are working as
intended.
Constraints
Storing array's capacity must be exactly 16 integers
o If the size of the array is not 16 integers long, throw InvalidOperationException
Add operation, should add an element at the next free cell (just like a stack)
o If there are 16 elements in the Database and try to add 17 th, throw an InvalidOperationException
Remove operation, should support only removing the element at the last index (just like a stack)
o If you try to remove an element from an empty Database throw InvalidOperationException
Constructors should take integers only, and store them in an array
Fetch method should return the elements as array
Hint
Do not forget to test the constructor(s). They are methods too!
Constraints
Database should have methods:
Add
o If there are already users with this username, throw InvalidOperationException
o If there are already users with this id, throw InvalidOperationException
Remove
FindByUsername
o If no user is present by this username, throw InvalidOperationException
o If username parameter is null, throw ArgumentNullException
o Arguments are all CaseSensitive
FindById
o If no user is present by this id, throw InvalidOperationException
o If negative ids are found, throw ArgumentOutOfRangeException
© Software University Foundation. This work is licensed under the CC-BY-NC-SA license.
Follow us: Page 1 of 2
Hint
Do not forget to test the constructor(s). They are methods too!
Create new Unit Test Project and add reference to the “CustomLinkedList”.
Create Test Methods for all public members that need testing.
Create tests that ensure all methods, getters and setters work correctly (do not test auto-properties).
Make sure that the methods throw the correct exceptions in case a wrong input is entered.
Give meaningful assert messages for failed tests.
For the StorageMester.Tests.Structure you need to test if all fields, consts, propeties, constructors and
methods exists.
For the StorageMester.BusinessLogic.Tests you need to test if all business methods are implemented
properly.
© Software University Foundation. This work is licensed under the CC-BY-NC-SA license.
Follow us: Page 2 of 2