You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
3.2 KiB
68 lines
3.2 KiB
using System;
|
|
using Model;
|
|
|
|
namespace TestDataManager;
|
|
|
|
public class DataManagerTest_WithMemberData1
|
|
{
|
|
[Theory]
|
|
[MemberData(nameof(TestData_BorrowBook))]
|
|
public async void TestBorrowBook(bool expectedResult, Book bookToBorrow, Person borrower, IDataManager dataManager)
|
|
{
|
|
bool result = await dataManager.BorrowBook(bookToBorrow, borrower);
|
|
Book? book = (await dataManager.GetBooksByIsbn(bookToBorrow?.Isbn, 0, 100)).SingleOrDefault();
|
|
Person? person = (await dataManager.GetPersonsByName(borrower?.LastName, 0, 100)).SingleOrDefault();
|
|
|
|
Assert.Equal(expectedResult, result);
|
|
|
|
if(result)
|
|
{
|
|
Assert.NotNull(book);
|
|
Assert.NotNull(person);
|
|
Assert.Contains(book, person.Books);
|
|
Assert.Equal(person, book.Borrower);
|
|
}
|
|
else
|
|
{
|
|
if(person != null && book != null)
|
|
{
|
|
Assert.DoesNotContain(book, person.Books);
|
|
Assert.NotEqual(person, book.Borrower);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<object[]> TestData_BorrowBook =>
|
|
new List<object[]>
|
|
{
|
|
//T1. no book and no borrower
|
|
new object[] { false, null, null, new BorrowBookStub() },
|
|
|
|
//T2. no book
|
|
new object[] { false, null, new Person("John", "Coltrane"), new BorrowBookStub() },
|
|
|
|
//T3. no borrower
|
|
new object[] { false, new Book( "Les Pardaillan", "Michel Zévaco", "978-2221098417"), null, new BorrowBookStub() },
|
|
|
|
//T4. new book and new borrower
|
|
new object[] { false, new Book( "Les Pardaillan", "Michel Zévaco", "978-2221098417"), new Person("John", "Coltrane"), new BorrowBookStub() },
|
|
|
|
//T5. new book and already known borrower
|
|
new object[] { false, new Book( "Les Pardaillan", "Michel Zévaco", "978-2221098417"), new Person(1, "Chick", "Corea"), new BorrowBookStub() },
|
|
|
|
//T6. already known but free book and new borrower
|
|
new object[] { false, new Book(2, "Les Misérables", "Victor Hugo", "979-8850172916"), new Person("John", "Coltrane"), new BorrowBookStub() },
|
|
|
|
//T7. already known but already borrowed book and new borrower
|
|
new object[] { false, new Book(1, "Les Trois Mousquetaires", "Alexandre Dumas", "979-8415441792"), new Person("John", "Coltrane"), new BorrowBookStub() },
|
|
|
|
//T8. already known but free book and already known borrower
|
|
new object[] { true, new Book(2, "Les Misérables", "Victor Hugo", "979-8850172916"), new Person(1, "Chick", "Corea"), new BorrowBookStub() },
|
|
|
|
//T9. already known but already borrowed book by another borrower and already known borrower
|
|
new object[] { false, new Book(1, "Les Trois Mousquetaires", "Alexandre Dumas", "979-8415441792"), new Person(2, "Stanley", "Clarke"), new BorrowBookStub() },
|
|
|
|
//T10. already known but already borrowed book by this borrower and already known borrower
|
|
new object[] { true, new Book(1, "Les Trois Mousquetaires", "Alexandre Dumas", "979-8415441792"), new Person(1, "Chick", "Corea"), new BorrowBookStub() },
|
|
};
|
|
} |