facts sample
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
dae9e9d2c5
commit
77a679411d
@ -0,0 +1,70 @@
|
|||||||
|
namespace Model;
|
||||||
|
|
||||||
|
public class Book : IEquatable<Book>
|
||||||
|
{
|
||||||
|
public long Id { get; private init; }
|
||||||
|
|
||||||
|
public string Title
|
||||||
|
{
|
||||||
|
get => title;
|
||||||
|
set => title = value ?? "";
|
||||||
|
}
|
||||||
|
private string title = null!;
|
||||||
|
|
||||||
|
public string Author
|
||||||
|
{
|
||||||
|
get => author;
|
||||||
|
set => author = value ?? "";
|
||||||
|
}
|
||||||
|
private string author = null!;
|
||||||
|
|
||||||
|
public string Isbn
|
||||||
|
{
|
||||||
|
get => isbn;
|
||||||
|
set => isbn = value ?? "";
|
||||||
|
}
|
||||||
|
private string isbn = null!;
|
||||||
|
|
||||||
|
public Person? Borrower { get; set; }
|
||||||
|
|
||||||
|
public Book(long id, string title, string author, string isbn)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Title = title;
|
||||||
|
Author = author;
|
||||||
|
Isbn = isbn;
|
||||||
|
}
|
||||||
|
public Book(string title, string author, string isbn)
|
||||||
|
: this(0, title, author, isbn)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(Book? other)
|
||||||
|
{
|
||||||
|
if (Id != 0)
|
||||||
|
return Id == (other?.Id ?? 0);
|
||||||
|
else
|
||||||
|
return Title.Equals(other?.Title)
|
||||||
|
&& Author.Equals(other?.Author)
|
||||||
|
&& Isbn.Equals(other?.Isbn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if(ReferenceEquals(obj, null)) return false;
|
||||||
|
if(ReferenceEquals(obj, this)) return true;
|
||||||
|
if(GetType() != obj.GetType()) return false;
|
||||||
|
return Equals(obj as Book);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
if(Id != 0)
|
||||||
|
return (int)(Id % 7879);
|
||||||
|
else
|
||||||
|
return Isbn.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
=> $"{Id} - {Title} ({Isbn}) // {Author}";
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
namespace Model;
|
||||||
|
|
||||||
|
public interface IDataManager
|
||||||
|
{
|
||||||
|
Task<IEnumerable<Book>> GetBooks(int index, int count);
|
||||||
|
Task<IEnumerable<Book>> GetBooksByTitle(string title, int index, int count);
|
||||||
|
Task<IEnumerable<Book>> GetBooksByAuthor(string author, int index, int count);
|
||||||
|
Task<IEnumerable<Book>> GetBooksByIsbn(string isbn, int index, int count);
|
||||||
|
Task<Book?> GetBookById(long id);
|
||||||
|
|
||||||
|
Task<IEnumerable<Person>> GetPersons(int index, int count);
|
||||||
|
Task<IEnumerable<Person>> GetPersonsByName(string name, int index, int count);
|
||||||
|
Task<Person?> GetPersonById(long id);
|
||||||
|
Task<IEnumerable<Book>> GetBooksBorrowedBy(Person person, int index, int count);
|
||||||
|
|
||||||
|
Task<Book> CreateBook(string title, string author, string isbn);
|
||||||
|
Task<Book?> UpdateBook(long id, Book book);
|
||||||
|
Task<bool> DeleteBook(long id);
|
||||||
|
|
||||||
|
Task<Person> CreatePerson(string firstName, string lastName);
|
||||||
|
Task<Person?> UpdatePerson(long id, Person person);
|
||||||
|
Task<bool> DeletePerson(long id);
|
||||||
|
|
||||||
|
Task<bool> BorrowBook(Book book, Person person);
|
||||||
|
Task<bool> ReturnBook(Book book, Person person);
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
using Model;
|
||||||
|
|
||||||
|
namespace TestModel;
|
||||||
|
|
||||||
|
public class PersonTest
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void TestFirstName_CorrectValue()
|
||||||
|
{
|
||||||
|
Person person = new Person("Chuck", "McGill");
|
||||||
|
Assert.Equal("Chuck", person.FirstName);
|
||||||
|
|
||||||
|
person.FirstName = "Jimmy";
|
||||||
|
Assert.Equal("Jimmy", person.FirstName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestFirstName_NullValue()
|
||||||
|
{
|
||||||
|
Person person = new Person("Jimmy", "McGill");
|
||||||
|
Assert.Equal("Jimmy", person.FirstName);
|
||||||
|
|
||||||
|
person.FirstName = null;
|
||||||
|
Assert.Equal("Jane", person.FirstName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestFirstName_EmptyValue()
|
||||||
|
{
|
||||||
|
Person person = new Person("Jimmy", "McGill");
|
||||||
|
Assert.Equal("Jimmy", person.FirstName);
|
||||||
|
|
||||||
|
person.FirstName = "";
|
||||||
|
Assert.Equal("Jane", person.FirstName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestFirstName_WhiteSpacesValue()
|
||||||
|
{
|
||||||
|
Person person = new Person("Jimmy", "McGill");
|
||||||
|
Assert.Equal("Jimmy", person.FirstName);
|
||||||
|
|
||||||
|
person.FirstName = " ";
|
||||||
|
Assert.Equal("Jane", person.FirstName);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.5.3" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Xunit" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Model\Model.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in new issue