Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F13 nova funkcionalnost pretrazivanje pri dodavanju knjige #48

Merged
merged 18 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
35 changes: 35 additions & 0 deletions .github/workflows/build_test_f13.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build and run unit test on branch push

on:
push:
branches:
- 45-nova-funkcionalnost-f13
pull_request:
branches:
- 45-nova-funkcionalnost-f13
workflow_dispatch:

jobs:
buildTest:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.6

- name: Install MSBuild
uses: microsoft/setup-msbuild@v2

- name: Install NuGet
uses: nuget/setup-nuget@v2

- name: Restore dependencies
run: nuget restore Software\E_Libra\E_Libra.sln

- name: Build solution
run: msbuild.exe Software\E_Libra\E_Libra.sln /p:platform="Any CPU" /p:configuration="Debug"

- name: Build Unit Test project
run: dotnet build Software\E_Libra\UnitTesting\UnitTesting.csproj --configuration Debug

- name: Run unit tests
run: dotnet test Software\E_Libra\UnitTesting\UnitTesting.csproj --no-build --verbosity normal
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ public bool AddAuthor(Author author)

return isSuccesful;
}

public List<Author> SearchAuthors(string search)
{
return authorRepository.SearchAuthor(search);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@ public bool Add(Genre entity)

return isSuccesful;
}

public List<Genre> SearchGenres(string search)
{
return genreRepository.SearchGenre(search);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public interface IAuthorRepository : IDisposable
{
IQueryable<Author> GetAll();
int Add(Author entity, bool saveChanges = true);
List<Author> SearchAuthor(string search);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface IGenreRepository : IDisposable
IQueryable<Genre> GetAll();
int Add(Genre entity, bool saveChanges = true);
IQueryable<MostPopularGenres> GetMostPopularGenres(int Library_id);
List<Genre> SearchGenre(string search);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,13 @@ private int GetAuthorNextId()
return lastId + 1;

}

public List<Author> SearchAuthor(string search)
{
var sql = from a in Entities
where a.name.Contains(search) || a.surname.Contains(search)
select a;
return sql.ToList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ group genre.name by genre into genreGroup
return query;
}

public List<Genre> SearchGenre(string search)
{
var sql = from g in Entities
where g.name.Contains(search)
select g;
return sql.ToList();
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using FluentAssertions;
using BussinessLogicLayer.services;
using EntitiesLayer;

namespace IntegrationTesting.Nove_funkcionalnosti.F13
{
[Collection("Database collection")]
public class AuthorService_intTest
{
readonly AuthorService service;
readonly DatabaseFixture fixture;

public AuthorService_intTest(DatabaseFixture fixture)
{
this.fixture = fixture;
this.fixture.ResetDatabase();
service = new AuthorService();
}


//Viktor Lovrić
[Fact]
public void SearchAuthors_GivenStringIsPassed_ReturnsAuthors()
{
//Arrange
string sql =
vlovric21 marked this conversation as resolved.
Show resolved Hide resolved
"INSERT [dbo].[Author] ([idAuthor], [name], [surname], [birth_date]) VALUES (1, N'Author1', N'Surname1', '2021-06-01') " +
"INSERT [dbo].[Author] ([idAuthor], [name], [surname], [birth_date]) VALUES (2, N'Author2', N'Surname2', '2021-06-01') " +
"INSERT [dbo].[Author] ([idAuthor], [name], [surname], [birth_date]) VALUES (3, N'Drugaciji', N'Oddrugih', '2021-06-01') ";
Helper.ExecuteCustomSql(sql);

var authors = new List<Author>
{
new Author { idAuthor = 3, name = "Drugaciji", surname = "Oddrugih", birth_date = DateTime.Parse("2021-06-01") }
};

//Act
var result = service.SearchAuthors("Drug");

//Assert
result.Should().BeEquivalentTo(authors);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using BussinessLogicLayer.services;
using FluentAssertions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace IntegrationTesting.Nove_funkcionalnosti.F13
{
[Collection("Database collection")]
public class GenreServices_intTest
{
readonly GenreServices services;
readonly DatabaseFixture fixture;

public GenreServices_intTest(DatabaseFixture fixture)
{
this.fixture = fixture;
this.fixture.ResetDatabase();
services = new GenreServices();
}

//Viktor Lovrić
[Fact]
public void SearchGenres_GivenStringIsPassed_ReturnsGenres()
{
//Arrange
string sql =
"INSERT [dbo].[Genre] ([name]) VALUES (N'zanr1') " +
"INSERT [dbo].[Genre] ([name]) VALUES (N'zanr2') " +
"INSERT [dbo].[Genre] ([name]) VALUES (N'Drugaciji') ";
Helper.ExecuteCustomSql(sql);

var genres = new List<EntitiesLayer.Genre>
{
new EntitiesLayer.Genre { id = 1, name = "zanr1" },
new EntitiesLayer.Genre { id = 2, name = "zanr2" }
};

//Act
var result = services.SearchGenres("zanr");

//Assert
result.Should().BeEquivalentTo(genres);
}


}
}
37 changes: 25 additions & 12 deletions Software/E_Libra/PresentationLayer/UcAddNewBook.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,31 @@
<TextBox Width="300" Height="30" Grid.Column="1" Grid.Row="6" x:Name="txtLinkDigital"></TextBox>
<TextBox Width="300" Height="30" Grid.Column="1" Grid.Row="7" x:Name="txtLinkPicture"></TextBox>
<TextBox Width="300" Height="30" Grid.Column="1" Grid.Row="8" x:Name="txtNumberCopies"></TextBox>
<StackPanel Grid.Column="1" Grid.Row="9" Orientation="Horizontal" HorizontalAlignment="Center">
<ComboBox x:Name="cmbGenre" Width="300" Height="30" Margin="70,0,0,0"></ComboBox>
<Button x:Name="btnNewGenre" Content="Novi žanr" Width="auto" Height="30" Margin="10,0,0,0"
Background="#637E60" Foreground="#FFEFE8" Click="btnNewGenre_Click"></Button>
</StackPanel>

<StackPanel Grid.Column="1" Grid.Row="10" Orientation="Horizontal" HorizontalAlignment="Center">
<ComboBox x:Name="cmbAuthor" Width="300" Height="30" Margin="70,0,0,0"></ComboBox>
<Button x:Name="btnNewAuthor" Content="Novi autor" Width="auto" Height="30" Margin="10,0,0,0"
Background="#637E60" Foreground="#FFEFE8" Click="btnNewAuthor_Click"></Button>
</StackPanel>


<Grid Grid.Column="1" Grid.Row="9" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
vlovric21 marked this conversation as resolved.
Show resolved Hide resolved
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="txtSearchGenre" Height="25" Grid.Column="0" Margin="30,0,0,0" TextChanged="txtSearchGenre_TextChanged"/>
<ComboBox x:Name="cmbGenre" Height="30" Grid.Column="1" Margin="10,0,0,0"/>
<Button x:Name="btnNewGenre" Content="New Genre" Height="30" Grid.Column="2" Margin="10,0,0,0"
Background="#637E60" Foreground="#FFEFE8" Click="btnNewGenre_Click"/>
</Grid>

<Grid Grid.Column="1" Grid.Row="10" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="txtSearchAuthor" Height="25" Grid.Column="0" Margin="30,0,0,0" TextChanged="txtSearchAuthor_TextChanged"/>
<ComboBox x:Name="cmbAuthor" Height="30" Grid.Column="1" Margin="10,0,0,0"/>
<Button x:Name="btnNewAuthor" Content="New Author" Height="30" Grid.Column="2" Margin="10,0,0,0"
Background="#637E60" Foreground="#FFEFE8" Click="btnNewAuthor_Click"/>
</Grid>

<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="11" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="btnCancel" Content="Odustani" Width="60" Height="30" Margin="0,0,10,0"
Background="#637E60" Foreground="#FFEFE8" Click="btnCancel_Click"></Button>
Expand Down
28 changes: 28 additions & 0 deletions Software/E_Libra/PresentationLayer/UcAddNewBook.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,33 @@ private void UcNewGenre_ButtonClicked(object sender, EventArgs e)
{
LoadGenres();
}

private void txtSearchGenre_TextChanged(object sender, TextChangedEventArgs e)
{
string search = txtSearchGenre.Text;
if (string.IsNullOrEmpty(search))
{
LoadGenres();
return;
}
vlovric21 marked this conversation as resolved.
Show resolved Hide resolved
using (GenreServices genreServices = new GenreServices())
{
cmbGenre.ItemsSource = genreServices.SearchGenres(search);
}
}

private void txtSearchAuthor_TextChanged(object sender, TextChangedEventArgs e)
{
string search = txtSearchAuthor.Text;
if (string.IsNullOrEmpty(search))
{
LoadAuthors();
return;
}
using (AuthorService authorService = new AuthorService())
{
cmbAuthor.ItemsSource = authorService.SearchAuthors(search);
}
}
vlovric21 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using BussinessLogicLayer.services;
using DataAccessLayer.Interfaces;
using EntitiesLayer;
using FakeItEasy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace UnitTesting.Nove_funkcionalnosti.F13 {
public class AuthorService_Test
{
readonly IAuthorRepository repo;
readonly AuthorService service;
vlovric21 marked this conversation as resolved.
Show resolved Hide resolved

public AuthorService_Test()
{
repo = A.Fake<IAuthorRepository>();
service = new AuthorService(repo);
}

//Viktor Lovrić
[Fact]
public void SearchAuthors_GivenStringIsPassed_ReturnsAuthors()
{
//Arrange
var authors = new List<Author>
{
new Author { idAuthor = 1, name = "Author1", surname = "Surname1", birth_date = DateTime.Now },
new Author { idAuthor = 2, name = "Author2", surname = "Surname2", birth_date = DateTime.Now },
};

A.CallTo(() => repo.SearchAuthor("Author")).Returns(authors);

//Act
var result = service.SearchAuthors("Author");

//Assert
Assert.Equal(authors, result);
}
}
}
10 changes: 0 additions & 10 deletions Software/E_Libra/UnitTesting/Nove funkcionalnosti/F13/Class1.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using BussinessLogicLayer.services;
using DataAccessLayer.Interfaces;
using EntitiesLayer;
using FakeItEasy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace UnitTesting.Nove_funkcionalnosti.F13
{
public class GenreServices_Test
{
readonly IGenreRepository repo;
readonly GenreServices service;

public GenreServices_Test()
{
repo = A.Fake<IGenreRepository>();
service = new GenreServices(repo);
}

//Viktor Lovrić
[Fact]
public void SearchGenres_GivenStringIsPassed_ReturnsGenres()
{
//Arrange
var genres = new List<Genre>
{
new Genre { name = "Genre1" },
new Genre { name = "Genre2" }
};

A.CallTo(() => repo.SearchGenre("Genre")).Returns(genres);

//Act
var result = service.SearchGenres("Genre");

//Assert
Assert.Equal(genres, result);
}
}
}