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: 19 additions & 11 deletions tdd-oop-inheritance.CSharp.Main/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@
using System.Text;
using System.Threading.Tasks;

using tdd_oop_inheritance.CSharp.Main.Interfaces;
namespace tdd_oop_inheritance.CSharp.Main
{
public class Article {
public string title;

bool onLoan = false;

public Article(string title) {
this.title = title;
public class Article : Text, IAuthorable {

private IAuthor _author;
public bool authorExists;

public Article(string title, IAuthor author) : base(title)
{
onLoan = false;
_author = author;
if (author != null)
{
authorExists = true;
}
}

public bool isOnLoan() {
public IAuthor Author { get { return _author; } set { _author = value; } }

public override bool isOnLoan() {
return onLoan;
}

public string checkIn() {
public override string checkIn() {
if (!this.isOnLoan()) {
return "item is not currently on loan";
}
Expand All @@ -29,7 +37,7 @@ public string checkIn() {
return "item has been checked in";
}

public string checkOut() {
public override string checkOut() {
if (this.isOnLoan()) {
return "item is currently on loan";
}
Expand Down
27 changes: 27 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/Author.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using tdd_oop_inheritance.CSharp.Main.Interfaces;
namespace tdd_oop_inheritance.CSharp.Main
{
public class Author : IAuthor
{
//private string _name;
//private string _contactInfo;
//private string _website;

public Author(string name, string contactInfo, string website)
{
this.Name = name;
this.ContactInfo = contactInfo;
this.Website = website;
}

public string Name { get; set; }
public string ContactInfo { get; set; }
public string Website { get; set; }
}
}
28 changes: 18 additions & 10 deletions tdd-oop-inheritance.CSharp.Main/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,31 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using tdd_oop_inheritance.CSharp.Main.Interfaces;

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

bool onLoan = false;

public Book(string title) {
this.title = title;
public class Book : Text, IAuthorable {

private IAuthor _author;
public bool authorExists;

public Book(string title, IAuthor author) : base(title)
{
onLoan = false;
_author = author;
if (author != null)
{
authorExists = true;
}
}
public IAuthor Author { get { return _author; } set { _author = value; } }

public bool isOnLoan() {
public override bool isOnLoan() {
return onLoan;
}

public string checkIn() {
public override string checkIn() {
if (!this.isOnLoan()) {
return "item is not currently on loan";
}
Expand All @@ -29,7 +37,7 @@ public string checkIn() {
return "item has been checked in";
}

public string checkOut() {
public override string checkOut() {
if (this.isOnLoan()) {
return "item is currently on loan";
}
Expand Down
15 changes: 15 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/Interfaces/IAuthor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_oop_inheritance.CSharp.Main.Interfaces
{
public interface IAuthor
{
public string Name { get; }
public string ContactInfo { get; set; }
public string Website { get; set; }
}
}
13 changes: 13 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/Interfaces/IAuthorable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_oop_inheritance.CSharp.Main.Interfaces
{
public interface IAuthorable
{
IAuthor Author { get; set; }
}
}
78 changes: 14 additions & 64 deletions tdd-oop-inheritance.CSharp.Main/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,32 @@
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<Text> texts = new List<Text>();

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

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

public void addToStock(Newspaper item) {
this.newspapers.Add(item);
public void addToStock(Text item)
{
this.texts.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) {
public string checkInText(Text text)
{
List<Text> filtered = (List<Text>)this.texts.Where(text => text.Equals(text));
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) {
public string checkOutText(Text text)
{
List<Text> filtered = (List<Text>)this.texts.Where(text => text.Equals(text));
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";
}

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

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

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

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

Boolean onLoan = false;

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

public bool isOnLoan() {
public override 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
25 changes: 25 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/Text.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tdd_oop_inheritance.CSharp.Main
{
public abstract class Text
{
protected string title;

protected bool onLoan;

public Text(string title)
{
this.title = title;
onLoan = false;
}

public abstract string checkIn();
public abstract string checkOut();
public abstract bool isOnLoan();
}
}
21 changes: 17 additions & 4 deletions tdd-oop-inheritance.CSharp.Test/ArticleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ class ArticleTest
[Test]
public void shouldCheckOutIfAvailable()
{
Article article = new Article("JUnit Rocks");
Author author = new Author("Bill Nye", "thescience@guy.com", "www.billnye.com");
Article article = new Article("JUnit Rocks", author);
Assert.AreEqual("item has been checked out", article.checkOut());
}

[Test]
public void shouldDeclineIfNotAvailableToCheckout()
{
Article article = new Article("JUnit Rocks");
Author author = new Author("Bill Nye", "thescience@guy.com", "www.billnye.com");
Article article = new Article("JUnit Rocks", author);
article.checkOut();

Assert.AreEqual("item is currently on loan", article.checkOut());
Expand All @@ -24,7 +26,8 @@ public void shouldDeclineIfNotAvailableToCheckout()
[Test]
public void shouldCheckInIfOnLoan()
{
Article article = new Article("JUnit Rocks");
Author author = new Author("Bill Nye", "thescience@guy.com", "www.billnye.com");
Article article = new Article("JUnit Rocks", author);
article.checkOut();

Assert.AreEqual("item has been checked in", article.checkIn());
Expand All @@ -33,9 +36,19 @@ public void shouldCheckInIfOnLoan()
[Test]
public void shouldDeclineCheckInIfNotOnLoan()
{
Article article = new Article("JUnit Rocks");
Author author = new Author("Bill Nye", "thescience@guy.com", "www.billnye.com");
Article article = new Article("JUnit Rocks", author);

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

[Test]
public void articleAuthorExists()
{
Author author = new Author("Bill Nye", "thescience@guy.com", "www.billnye.com");
Article article = new Article("JUnit Rocks", author);

Assert.IsTrue(article.authorExists);
}
}
}
Loading