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: 5 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,13 @@

namespace tdd_oop_inheritance.CSharp.Main
{
public class Article {
public class Article : ItemClass{
public string title;
Author author;

bool onLoan = false;

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


public Author(string _name, string _contactInfo, string? _website)
{
name = _name;
contactInfo = _contactInfo;
website = _website;
}
}
}
35 changes: 6 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,14 @@

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

bool onLoan = false;

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

namespace tdd_oop_inheritance.CSharp.Main
{
public class ItemClass
{
public string title;
bool onLoan;
Author? author;
public ItemClass(string title, Author? author)
{
this.title = title;
this.author = author;
}

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

public Author returnAuthor()
{
return author;
}
}
}
16 changes: 7 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,23 @@

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

Boolean onLoan = false;
public bool onLoan;

public Newspaper(string title) {
public Newspaper(string title) : base(title, null){
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
29 changes: 22 additions & 7 deletions tdd-oop-inheritance.CSharp.Test/ArticleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ class ArticleTest
[Test]
public void shouldCheckOutIfAvailable()
{
Article article = new Article("JUnit Rocks");
Assert.AreEqual("item has been checked out", article.checkOut());
Author author = new Author("Axel", "95901753", "www.com");
ItemClass item = new Article("JUnit Rocks", author);
Assert.AreEqual("item has been checked out", item.checkOut());
}

[Test]
public void shouldDeclineIfNotAvailableToCheckout()
{
Article article = new Article("JUnit Rocks");
article.checkOut();
Author author = new Author("Axel", "95901753", "www.com");
ItemClass item = new Article("JUnit Rocks", author);
item.checkOut();

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

[Test]
public void shouldCheckInIfOnLoan()
{
Article article = new Article("JUnit Rocks");
Author author = new Author("Axel", "95901753", "www.com");
ItemClass article = new Article("JUnit Rocks", author);
article.checkOut();

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

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

[Test]
public void getAuthorForBook()
{
Author author = new Author("Axel", "95901753", "www.com");
ItemClass book = new Book("What", author);

Assert.That(book.returnAuthor(), Is.EqualTo(author));


}
}
}
33 changes: 23 additions & 10 deletions tdd-oop-inheritance.CSharp.Test/BookTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,47 @@ public class BookTest
[Test]
public void shouldCheckOutIfAvailable()
{
Book book = new Book("JUnit Rocks");
Assert.AreEqual("item has been checked out", book.checkOut());
Author author = new Author("Axel", "95901753", "www.com");
ItemClass item = new Book("JUnit Rocks", author);
Assert.AreEqual("item has been checked out", item.checkOut());
}

[Test]
public void shouldDeclineIfNotAvailableToCheckout()
{
Book book = new Book("JUnit Rocks");
book.checkOut();
Author author = new Author("Axel", "95901753", "www.com");
ItemClass item = new Book("JUnit Rocks", author);
item.checkOut();

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

[Test]
public void shouldCheckInIfOnLoan()
{
Book book = new Book("JUnit Rocks");
book.checkOut();
Author author = new Author("Axel", "95901753", "www.com");
ItemClass article = new Book("JUnit Rocks", author);
article.checkOut();

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

[Test]
public void shouldDeclineCheckInIfNotOnLoan()
{
Book book = new Book("JUnit Rocks");
Author author = new Author("Axel", "95901753", "www.com");
ItemClass article = new Book("JUnit Rocks", author);

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

[Test]
public void getAuthorName()
{
Author author = new Author("Axel", "95901753", "www.com");
ItemClass article = new Book("JUnit Rocks", author);
string name = author.name;
Assert.That(name == article.returnAuthor().name);
}
}
}
11 changes: 9 additions & 2 deletions tdd-oop-inheritance.CSharp.Test/NewspaperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ public class NewspaperTest
[Test]
public void shouldBeUnavailableForCheckIn()
{
Newspaper newspaper = new Newspaper("The Daily Java");
ItemClass 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");
ItemClass newspaper = new Newspaper("The Daily Java");
Assert.AreEqual("newspapers are not available for loan", newspaper.checkOut());
}

[Test]
public void noAuthor()
{
ItemClass newspaper = new Newspaper("Ye");
Assert.That(newspaper.returnAuthor(), Is.Null);
}
}
}