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

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

bool onLoan = false;
private Author _author;
public Article(Author author, string name) : base(name) { _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;

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 Author Author { get { return _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 _name;
private string _contactInformation;
private string _website;

public Author(string name, string contactInformation, string website)
{
_name = name;
_contactInformation = contactInformation;
_website = website;
}

public string Name { get { return _name; } }
public string ContactInformation { get { return _contactInformation; } }
public string Website { get { return _website; } }
}
}
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 : Literature {

bool onLoan = false;
private Author _author;

public Book(string title) {
this.title = title;
}
public Book(Author author, string name) : base(name) { _author = author; }

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 Author Author { get { return _author; } }
}
}
49 changes: 49 additions & 0 deletions tdd-oop-inheritance.CSharp.Main/Literature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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 Literature
{
public string title;

bool onLoan = false;

public Literature(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";
}
}
}
18 changes: 4 additions & 14 deletions tdd-oop-inheritance.CSharp.Main/Newspaper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,15 @@

namespace tdd_oop_inheritance.CSharp.Main
{
public class Newspaper
public class Newspaper : Literature
{
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 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
19 changes: 15 additions & 4 deletions tdd-oop-inheritance.CSharp.Test/ArticleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ namespace tdd_oop_inheritance.CSharp.Test
{
class ArticleTest
{
Author author = new Author("Steven Guy", "+4712345678", "http://thisisawebsite.com");

[Test]
public void shouldCheckOutIfAvailable()
{
Article article = new Article("JUnit Rocks");
Literature 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");
Literature article = new Article(author, "JUnit Rocks");
article.checkOut();

Assert.AreEqual("item is currently on loan", article.checkOut());
Expand All @@ -24,7 +26,7 @@ public void shouldDeclineIfNotAvailableToCheckout()
[Test]
public void shouldCheckInIfOnLoan()
{
Article article = new Article("JUnit Rocks");
Literature article = new Article(author, "JUnit Rocks");
article.checkOut();

Assert.AreEqual("item has been checked in", article.checkIn());
Expand All @@ -33,9 +35,18 @@ public void shouldCheckInIfOnLoan()
[Test]
public void shouldDeclineCheckInIfNotOnLoan()
{
Article article = new Article("JUnit Rocks");
Literature article = new Article(author, "JUnit Rocks");

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

[Test]
public void shouldReturnNameOfAuthor()
{
Literature book = new Book(author, "JUnit Rocks");
string nameOfAuthor = "";
if (book is Book b) nameOfAuthor = b.Author.Name;
Assert.AreEqual("Steven Guy", nameOfAuthor);
}
}
}
18 changes: 14 additions & 4 deletions tdd-oop-inheritance.CSharp.Test/BookTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ namespace tdd_oop_inheritance.CSharp.Test
{
public class BookTest
{
Author author = new Author("Steven Guy", "+4712345678", "http://thisisawebsite.com");
[Test]
public void shouldCheckOutIfAvailable()
{
Book book = new Book("JUnit Rocks");
Literature 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");
Literature book = new Book(author, "JUnit Rocks");
book.checkOut();

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

Assert.AreEqual("item has been checked in", book.checkIn());
Expand All @@ -33,9 +34,18 @@ public void shouldCheckInIfOnLoan()
[Test]
public void shouldDeclineCheckInIfNotOnLoan()
{
Book book = new Book("JUnit Rocks");
Literature book = new Book(author, "JUnit Rocks");

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

[Test]
public void shouldReturnNameOfAuthor()
{
Literature book = new Book(author, "JUnit Rocks");
string nameOfAuthor = "";
if (book is Book b) nameOfAuthor = b.Author.Name;
Assert.AreEqual("Steven Guy", nameOfAuthor);
}
}
}
4 changes: 2 additions & 2 deletions tdd-oop-inheritance.CSharp.Test/NewspaperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public class NewspaperTest
[Test]
public void shouldBeUnavailableForCheckIn()
{
Newspaper newspaper = new Newspaper("The Daily Java");
Literature newspaper = new Newspaper("The Daily Java");
Assert.AreEqual("newspapers are not available for loan", newspaper.checkIn());
}

[Test]
public void shouldBeUnavailableForCheckOut()
{
Newspaper newspaper = new Newspaper("The Daily Java");
Literature newspaper = new Newspaper("The Daily Java");
Assert.AreEqual("newspapers are not available for loan", newspaper.checkOut());
}
}
Expand Down