Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View TonyHaddad91's full-sized avatar

Antwan Alhaddad TonyHaddad91

  • Berlin, Germany
View GitHub Profile
class Book(var numOfPages: Int, var pagePrice: Int=0, var type: Type = Type.SOFT_COPY) {
init {
if(numOfPages<=0)
throw RuntimeException("Number of pages must be more than zero")
}
fun calculateBookPrice(): Int {
var price: Int = numOfPages * pagePrice
if (type == Type.HARD_COPY)
price += 20
class ExampleUnitTest {
lateinit var nonNullBook: Book
/**
* This method will be called before each test we have
*/
@Before
fun thisMethodShouldBeCalledBeforeEachTestCall() {
println("Before Test method called")
nonNullBook = Book(300)
Firstly we need to create Basket reposiotry for Basket model and we create an interface for the repository in order to use it in the Controller,
The basket interface will contain add to basket and remove from basket operation and the repository should implement them
Then to add Unit of Work implementation
We need to add unit of works class
which contain an instance of the Basket repository and contain save method in order to save the transaction at the end
At the end in HomeController We Call basket repository instance in unit of work class in order to call the corresponding method from inside it
and once we done all the transactions we need to do we can call unit of work save method in order to save all the transactions we have done.