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
33 changes: 4 additions & 29 deletions tdd-oop-inheritance.CSharp.Main/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,12 @@

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

bool onLoan = false;
public Author author { get; set; }

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;

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";
public Article(Author author, string title) : base(title) {
this.author = author;
}
}
}
26 changes: 26 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/Author.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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
{
private string _authorname;
private string _authorwebsite;
private string _authorcontact;

public Author (string authorname, string authorwebsite, string authorcontact)
{
this._authorname = authorname;
this._authorwebsite = authorwebsite;
this._authorcontact = authorcontact;
}

public string AuthorName { get => _authorname; set => _authorname = value; }
public string AuthorWebsite { get => _authorwebsite; set => _authorwebsite = value; }
public string AuthorContact { get => _authorcontact; set => _authorcontact = value; }
}
}
33 changes: 4 additions & 29 deletions tdd-oop-inheritance.CSharp.Main/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,12 @@

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

bool onLoan = false;
public Author author { get; set; }

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";
}

this.onLoan = false;

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";
public Book(Author author, string title) : base (title) {
this.author = author;
}
}
}
51 changes: 51 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace tdd_oop_inheritance.CSharp.Main
{
public class Item
{
private string _title;

public string Title { get => _title; set => _title = value; }

bool onLoan = false;

public Item(string title)
{
_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";
}
}
}
88 changes: 35 additions & 53 deletions tdd-oop-inheritance.CSharp.Main/Library.cs
Original file line number Diff line number Diff line change
@@ -1,89 +1,71 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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>();
public class Library
{

public void addToStock(Article item) {
this.articles.Add(item);
}
public List<Item> items = new List<Item>();

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

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

// 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));
List<Item> filtered = (List<Item>)this.items.Where(item => item.Title.Equals(title));

if (filtered.Count() < 1) {
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));
public string checkOutItem(string title)
{
List<Item> filtered = (List<Item>)this.items.Where(item => item.Title.Equals(title));

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

return filtered[0].checkOut();
}

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

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
public virtual string AuthorInfo(string title)
{
List<Item> filtered = (List<Item>)this.items
.Where(item => item.Title.Equals(title)).ToList();
if (filtered.Count() < 1)
{
return "Item is not part of lib collection";
}

return filtered[0].checkIn();
}

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

if (filtered.Count() < 1) {
return "item is not part of the library's collection";
if (filtered[0] is Book)
{
Book book = (Book)filtered[0];
return book.author.AuthorName.ToString();
}
else if (filtered[0] is Article)
{
Article article = (Article)filtered[0];
return article.author.AuthorName.ToString();

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";
else
{
return "Item is not part of lib collection";
}

return filtered[0].checkOut();
}
}
}
21 changes: 10 additions & 11 deletions tdd-oop-inheritance.CSharp.Main/Newspaper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@

namespace tdd_oop_inheritance.CSharp.Main
{
public class Newspaper
public class Newspaper : Item
{
public string title;
public Newspaper(string title) : base(title)
{

Boolean onLoan = false;

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

public bool isOnLoan() {
return onLoan;
}
//public Newspaper(string title) :base (title){
// this.title = title;
//}

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
15 changes: 8 additions & 7 deletions tdd-oop-inheritance.CSharp.Test/ArticleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,34 @@ class ArticleTest
[Test]
public void shouldCheckOutIfAvailable()
{
Article article = new Article("JUnit Rocks");
Author author = new Author("Jane Doe", "Website", "@here");
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("Jane Doe", "Website", "@here");
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("Jane Doe", "Website", "@here");
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("Jane Doe", "Website", "@here");
Article article = new Article(author, "JUnit Rocks");
Assert.AreEqual("item is not currently on loan", article.checkIn());
}
}
Expand Down
Loading