-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathUnitTests.cs
More file actions
52 lines (46 loc) · 1.85 KB
/
UnitTests.cs
File metadata and controls
52 lines (46 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using Exercise;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Execise.Tests
{
[TestClass]
public class UnitTests
{
//test the two calls to library instance return same instance
[TestMethod]
public void LibraryShouldBeSingleton()
{
//check that when you create a Library instance second time,
//you get exactly the same instance as for a very first time
Library lib1 = Library.GetLibrary();
Library lib2 = Library.GetLibrary();
Assert.AreSame(lib1, lib2);
}
//test that an book was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void BookShouldRegister()
{
Library lib = Library.GetLibrary();
Book book = new Book("author", "title", 2017, 10);
Assert.AreNotEqual(lib.Register(book), -1);
}
//test that an customer was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void CustomerShouldRegister()
{
Library lib = Library.GetLibrary();
Customer customer = new Customer("name", "addr");
Assert.AreNotEqual(lib.Register(customer), -1);
}
//test that a book can be borrowed
[TestMethod]
public void CanBorrowBook()
{
//create a borrowable book with available amount more than one.
//Run BorrowOne method of the BookBorrowable instance. Check that total amount was reduced by one.
Book book = new Book("author", "title", 2017, 10);
int old = book.AvailableAmount;
BookBorrowable bookBorrowable = new BookBorrowable(null, new BorrowOne(book));
Assert.AreEqual(old - 1, book.AvailableAmount);
}
}
}