Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions tdd-oop-inheritance.CSharp.Main/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,17 @@

namespace tdd_oop_inheritance.CSharp.Main
{
public class Article {
public class Article : LibraryItem{
public string title;

bool onLoan = false;
Author author;

public Article(string title) {
this.title = title;
}

public bool isOnLoan() {
return onLoan;
}

public string checkIn() {
if (!this.isOnLoan()) {
return "item is not currently on loan";
}

this.onLoan = false;
public Article(Author author,string title) : base(title)
{
this.author = author;

return "item has been checked in";
}

public string checkOut() {
if (this.isOnLoan()) {
return "item is currently on loan";
}

this.onLoan = true;

return "item has been checked out";
}
}
}
22 changes: 22 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/Author.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_oop_inheritance.CSharp.Main
{
public class Author
{
public string name;
public int tlf;
public string website;

public Author(string name, int tlf, string website)
{
this.name = name;
this.tlf = tlf;
this.website = website;
}
}
}
30 changes: 5 additions & 25 deletions tdd-oop-inheritance.CSharp.Main/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,17 @@

namespace tdd_oop_inheritance.CSharp.Main
{
public class Book {
public class Book : LibraryItem {
public string title;

bool onLoan = false;

public Book(string title) {
this.title = title;
}

public bool isOnLoan() {
return onLoan;
}

public string checkIn() {
if (!this.isOnLoan()) {
return "item is not currently on loan";
}
Author author;

this.onLoan = false;

return "item has been checked in";
public Book(Author author,string title) : base(title)
{
this.author = author;
}

public string checkOut() {
if (this.isOnLoan()) {
return "item is currently on loan";
}

this.onLoan = true;

return "item has been checked out";
}
}
}
59 changes: 7 additions & 52 deletions tdd-oop-inheritance.CSharp.Main/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,19 @@
namespace tdd_oop_inheritance.CSharp.Main
{
public class Library {
List<Article> articles = new List<Article>();
List<Book> books = new List<Book>();
List<Newspaper> newspapers = new List<Newspaper>();
List<LibraryItem> articles = new List<LibraryItem>();

public void addToStock(Article item) {
public void addToStock(LibraryItem item) {
this.articles.Add(item);
}

public void addToStock(Book item) {
this.books.Add(item);
}

public void addToStock(Newspaper item) {
this.newspapers.Add(item);
}

// The following methods may contain code that you are unfamiliar with. The strange syntax of article -> something
// is called a lambda expression (https://www.w3schools.com/java/java_lambda.asp)
public string checkInArticle(string title) {

List<Article> filtered = (List<Article>)this.articles.Where(article => article.title.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
}

return filtered[0].checkIn();
}

public string checkOutArticle(string title) {
List<Article> filtered = (List<Article>)this.articles.Where(article => article.title.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
}

return filtered[0].checkOut();
}
public string checkIn(string title) {

public string checkInBook(string title) {
List<Book> filtered = (List<Book>)this.books.Where(book => book.Equals(title));
List<LibraryItem> filtered = (List<LibraryItem>)this.articles.Where(article => article.title.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
Expand All @@ -56,8 +28,8 @@ public string checkInBook(string title) {
return filtered[0].checkIn();
}

public string checkOutBook(string title) {
List<Book> filtered = (List<Book>)this.books.Where(book => book.Equals(title));
public string checkOut(string title) {
List<LibraryItem> filtered = (List<LibraryItem>)this.articles.Where(article => article.title.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
Expand All @@ -66,24 +38,7 @@ public string checkOutBook(string title) {
return filtered[0].checkOut();
}

public string checkInNewspaper(string title) {
List<Newspaper> filtered = (List<Newspaper>)this.newspapers.Where(newspaper => newspaper.title.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
}

return filtered[0].checkIn();
}

public string checkOutNewspaper(string title) {
List<Newspaper> filtered = (List<Newspaper>)this.newspapers.Where(newspaper => newspaper.title.Equals(title));

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
}
public List<LibraryItem> Articles { get { return articles; } }

return filtered[0].checkOut();
}
}
}
52 changes: 52 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/LibraryItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_oop_inheritance.CSharp.Main
{
public class LibraryItem
{
public string title;

bool onLoan = false;

public LibraryItem(string title)
{
this.title = title;
}

public bool isOnLoan()
{
return onLoan;
}

public virtual string checkIn()
{
if (!this.isOnLoan())
{
return "item is not currently on loan";
}

this.onLoan = false;

return "item has been checked in";
}


public virtual string checkOut()
{
if (this.isOnLoan())
{
return "item is currently on loan";
}

this.onLoan = true;

return "item has been checked out";

}

}
}
16 changes: 7 additions & 9 deletions tdd-oop-inheritance.CSharp.Main/Newspaper.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace tdd_oop_inheritance.CSharp.Main
{
public class Newspaper
public class Newspaper : LibraryItem
{
public string title;

Boolean onLoan = false;

public Newspaper(string title) {
this.title = title;
public Newspaper(string title) : base(title)
{
}

public bool isOnLoan() {
return onLoan;
}

public string checkIn() {
public override string checkIn()
{
return "newspapers are not available for loan";
}

public string checkOut() {
public override string checkOut() {
return "newspapers are not available for loan";
}
}
Expand Down
18 changes: 11 additions & 7 deletions tdd-oop-inheritance.CSharp.Test/ArticleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,38 @@ class ArticleTest
[Test]
public void shouldCheckOutIfAvailable()
{
Article article = new Article("JUnit Rocks");
Author author = new Author("John", 50070090, "hi.com");
Article article = new Article(author,"JUnit Rocks");
Assert.AreEqual("item has been checked out", article.checkOut());
}

[Test]
public void shouldDeclineIfNotAvailableToCheckout()
{
Article article = new Article("JUnit Rocks");
article.checkOut();
Author author = new Author("John", 50070090, "hi.com");
Article article = new Article(author, "JUnit Rocks");
article.checkOut();

Assert.AreEqual("item is currently on loan", article.checkOut());
}

[Test]
public void shouldCheckInIfOnLoan()
{
Article article = new Article("JUnit Rocks");
article.checkOut();
Author author = new Author("John", 50070090, "hi.com");
Article article = new Article(author, "JUnit Rocks");
article.checkOut();

Assert.AreEqual("item has been checked in", article.checkIn());
}

[Test]
public void shouldDeclineCheckInIfNotOnLoan()
{
Article article = new Article("JUnit Rocks");
Author author = new Author("John", 50070090, "hi.com");
Article article = new Article(author, "JUnit Rocks");

Assert.AreEqual("item is not currently on loan", article.checkIn());
Assert.AreEqual("item is not currently on loan", article.checkIn());
}
}
}
12 changes: 8 additions & 4 deletions tdd-oop-inheritance.CSharp.Test/BookTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ public class BookTest
[Test]
public void shouldCheckOutIfAvailable()
{
Book book = new Book("JUnit Rocks");
Author author = new Author("John", 50070090, "hi.com");
Book book = new Book(author,"JUnit Rocks");
Assert.AreEqual("item has been checked out", book.checkOut());
}

[Test]
public void shouldDeclineIfNotAvailableToCheckout()
{
Book book = new Book("JUnit Rocks");
Author author = new Author("John", 50070090, "hi.com");
Book book = new Book(author, "JUnit Rocks");
book.checkOut();

Assert.AreEqual("item is currently on loan", book.checkOut());
Expand All @@ -24,7 +26,8 @@ public void shouldDeclineIfNotAvailableToCheckout()
[Test]
public void shouldCheckInIfOnLoan()
{
Book book = new Book("JUnit Rocks");
Author author = new Author("John", 50070090, "hi.com");
Book book = new Book(author, "JUnit Rocks");
book.checkOut();

Assert.AreEqual("item has been checked in", book.checkIn());
Expand All @@ -33,7 +36,8 @@ public void shouldCheckInIfOnLoan()
[Test]
public void shouldDeclineCheckInIfNotOnLoan()
{
Book book = new Book("JUnit Rocks");
Author author = new Author("John", 50070090, "hi.com");
Book book = new Book(author, "JUnit Rocks");

Assert.AreEqual("item is not currently on loan", book.checkIn());
}
Expand Down
Loading