Skip to content

Commit

Permalink
Merge pull request #48 from foivz/45-nova-funkcionalnost-f13
Browse files Browse the repository at this point in the history
F13 nova funkcionalnost pretrazivanje pri dodavanju knjige
  • Loading branch information
vlovric21 authored Jun 15, 2024
2 parents 04940a1 + e8ea20d commit b609520
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 34 deletions.
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 =
"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*"/>
<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
62 changes: 62 additions & 0 deletions Software/E_Libra/PresentationLayer/UcAddNewBook.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace PresentationLayer
{
//Viktor Lovrić
public partial class UcAddNewBook : UserControl
{
string checkboxValue;
private DispatcherTimer genreSearchTimer = new DispatcherTimer();
private DispatcherTimer authorSearchTimer = new DispatcherTimer();
public UcAddNewBook()
{
InitializeComponent();

genreSearchTimer.Interval = TimeSpan.FromMilliseconds(300);
genreSearchTimer.Tick += GenreSearchTimer_Tick;

authorSearchTimer.Interval = TimeSpan.FromMilliseconds(500);
authorSearchTimer.Tick += AuthorSearchTimer_Tick;
}

private void btnCancel_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -216,5 +225,58 @@ private void UcNewGenre_ButtonClicked(object sender, EventArgs e)
{
LoadGenres();
}

private void txtSearchGenre_TextChanged(object sender, TextChangedEventArgs e)
{
genreSearchTimer.Stop();
genreSearchTimer.Start();
}

private void txtSearchAuthor_TextChanged(object sender, TextChangedEventArgs e)
{
authorSearchTimer.Stop();
authorSearchTimer.Start();
}

private void GenreSearchTimer_Tick(object sender, EventArgs e)
{
genreSearchTimer.Stop();
FilterGenres();
}

private void AuthorSearchTimer_Tick(object sender, EventArgs e)
{
authorSearchTimer.Stop();
FilterAuthors();
}

private void FilterGenres()
{
string search = txtSearchGenre.Text;
if (string.IsNullOrEmpty(search))
{
LoadGenres();
return;
}
using (GenreServices genreServices = new GenreServices())
{
cmbGenre.ItemsSource = genreServices.SearchGenres(search);
}
}

private void FilterAuthors()
{
string search = txtSearchAuthor.Text;
if (string.IsNullOrEmpty(search))
{
LoadAuthors();
return;
}
using (AuthorService authorService = new AuthorService())
{
cmbAuthor.ItemsSource = authorService.SearchAuthors(search);
}
}

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

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);
}
}
}
Loading

0 comments on commit b609520

Please sign in to comment.