From 901adff12bc6cdf9ad4ee482cfc5e11ebf1a4547 Mon Sep 17 00:00:00 2001 From: Baris Yerlikaya Date: Sun, 14 Apr 2024 10:53:47 +0300 Subject: [PATCH 1/4] namespaces were edited, package update was done. --- .../Contexts/MemoryDbContext.cs | 33 ++- .../PublisherRepository.cs | 19 +- .../Controllers/PublisherController.cs | 56 ++--- sample/Sample.Api/PublisherData.cs | 17 +- sample/Sample.Api/PublisherRepository.cs | 19 +- sample/Sample.Api/Sample.Api.csproj | 8 +- sample/Sample.Common/DataInitializer.cs | 217 +++++++++--------- sample/Sample.Common/Dto/BookSearchRequest.cs | 17 +- .../Dto/ComparativeSearchRequest.cs | 45 ++-- .../Dto/PublisherSearchRequest.cs | 37 ++- .../Sample.Common/Dto/TextualSearchRequest.cs | 25 +- sample/Sample.Common/Entity/Author.cs | 17 +- sample/Sample.Common/Entity/Book.cs | 21 +- sample/Sample.Common/Entity/Country.cs | 13 +- sample/Sample.Common/Entity/Publisher.cs | 15 +- 15 files changed, 269 insertions(+), 290 deletions(-) diff --git a/sample/Sample.Api/ApplicationSpecific/Contexts/MemoryDbContext.cs b/sample/Sample.Api/ApplicationSpecific/Contexts/MemoryDbContext.cs index 18aed6e..d1dc9ef 100644 --- a/sample/Sample.Api/ApplicationSpecific/Contexts/MemoryDbContext.cs +++ b/sample/Sample.Api/ApplicationSpecific/Contexts/MemoryDbContext.cs @@ -2,29 +2,28 @@ using Sample.Common.Entity; using System.Reflection; -namespace Sample.Api.ApplicationSpecific.Contexts +namespace Sample.Api.ApplicationSpecific.Contexts; + +public class MemoryDbContext : DbContext { - public class MemoryDbContext : DbContext - { - public DbSet Publishers { get; set; } + public DbSet Publishers { get; set; } - public DbSet Books { get; set; } + public DbSet Books { get; set; } - public DbSet Authors { get; set; } + public DbSet Authors { get; set; } - public DbSet Countries { get; set; } + public DbSet Countries { get; set; } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); - } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); + } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) { - if (!optionsBuilder.IsConfigured) - { - base.OnConfiguring(optionsBuilder.UseInMemoryDatabase("DummyDataDb")); - } + base.OnConfiguring(optionsBuilder.UseInMemoryDatabase("DummyDataDb")); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Api/ApplicationSpecific/PublisherRepository.cs b/sample/Sample.Api/ApplicationSpecific/PublisherRepository.cs index dd53d9f..db5da0a 100644 --- a/sample/Sample.Api/ApplicationSpecific/PublisherRepository.cs +++ b/sample/Sample.Api/ApplicationSpecific/PublisherRepository.cs @@ -1,16 +1,15 @@ using Sample.Api.ApplicationSpecific.Contexts; using Sample.Common.Entity; -namespace Sample.Api.ApplicationSpecific +namespace Sample.Api.ApplicationSpecific; + +public class PublisherRepository { - public class PublisherRepository - { - private readonly MemoryDbContext _context = new(); + private readonly MemoryDbContext _context = new(); - public void AddRange(IEnumerable publishers) - { - _context.AddRange(publishers); - _context.SaveChanges(); - } + public void AddRange(IEnumerable publishers) + { + _context.AddRange(publishers); + _context.SaveChanges(); } -} +} \ No newline at end of file diff --git a/sample/Sample.Api/Controllers/PublisherController.cs b/sample/Sample.Api/Controllers/PublisherController.cs index 03337ed..6772bb1 100644 --- a/sample/Sample.Api/Controllers/PublisherController.cs +++ b/sample/Sample.Api/Controllers/PublisherController.cs @@ -5,41 +5,33 @@ using Sample.Common.Entity; using SmartWhere; -namespace Sample.Api.Controllers +namespace Sample.Api.Controllers; + +[ApiController] +public class PublisherController(MemoryDbContext context) : ControllerBase { - [ApiController] - public class PublisherController : ControllerBase + [HttpPost("/publishers")] + public IActionResult GetPublishers(PublisherSearchRequest request) { - private readonly MemoryDbContext _context; - - public PublisherController(MemoryDbContext context) - { - _context = context; - } - - [HttpPost("/publishers")] - public IActionResult GetPublishers(PublisherSearchRequest request) - { - var result = _context.Set() - .Include(x => x.Books) - .ThenInclude(x => x.Author) - .Where(request) - .ToList(); + var result = context.Set() + .Include(x => x.Books) + .ThenInclude(x => x.Author) + .Where(request) + .ToList(); - return Ok(result); - } + return Ok(result); + } - [HttpPost("/books")] - public IActionResult GetBooks(BookSearchRequest request) - { - var result = _context.Books - .Include(x => x.Author) - .Where(request) - .Skip(request.Start) - .Take(request.Max) - .ToList(); + [HttpPost("/books")] + public IActionResult GetBooks(BookSearchRequest request) + { + var result = context.Books + .Include(x => x.Author) + .Where(request) + .Skip(request.Start) + .Take(request.Max) + .ToList(); - return Ok(result); - } + return Ok(result); } -} +} \ No newline at end of file diff --git a/sample/Sample.Api/PublisherData.cs b/sample/Sample.Api/PublisherData.cs index 5f3fd0f..5ca7d84 100644 --- a/sample/Sample.Api/PublisherData.cs +++ b/sample/Sample.Api/PublisherData.cs @@ -1,14 +1,13 @@ using Sample.Common; -namespace Sample.Api +namespace Sample.Api; + +public static class PublisherData { - public static class PublisherData + public static void FillDummyData() { - public static void FillDummyData() - { - PublisherRepository publisherRepository = new(); - var publisher = DataInitializer.FillMockData().ToList(); - publisherRepository.AddRange(publisher); - } + PublisherRepository publisherRepository = new(); + var publisher = DataInitializer.FillMockData().ToList(); + publisherRepository.AddRange(publisher); } -} +} \ No newline at end of file diff --git a/sample/Sample.Api/PublisherRepository.cs b/sample/Sample.Api/PublisherRepository.cs index 8ee0167..343e8ea 100644 --- a/sample/Sample.Api/PublisherRepository.cs +++ b/sample/Sample.Api/PublisherRepository.cs @@ -1,16 +1,15 @@ using Sample.Api.ApplicationSpecific.Contexts; using Sample.Common.Entity; -namespace Sample.Api +namespace Sample.Api; + +public class PublisherRepository { - public class PublisherRepository - { - private readonly MemoryDbContext _context = new(); + private readonly MemoryDbContext _context = new(); - public void AddRange(IEnumerable publishers) - { - _context.AddRange(publishers); - _context.SaveChanges(); - } + public void AddRange(IEnumerable publishers) + { + _context.AddRange(publishers); + _context.SaveChanges(); } -} +} \ No newline at end of file diff --git a/sample/Sample.Api/Sample.Api.csproj b/sample/Sample.Api/Sample.Api.csproj index 09ad05d..7b8138c 100644 --- a/sample/Sample.Api/Sample.Api.csproj +++ b/sample/Sample.Api/Sample.Api.csproj @@ -6,10 +6,10 @@ - - - - + + + + diff --git a/sample/Sample.Common/DataInitializer.cs b/sample/Sample.Common/DataInitializer.cs index e77b259..ea858e9 100644 --- a/sample/Sample.Common/DataInitializer.cs +++ b/sample/Sample.Common/DataInitializer.cs @@ -1,132 +1,131 @@ using Sample.Common.Entity; -namespace Sample.Common +namespace Sample.Common; + +public static class DataInitializer { - public static class DataInitializer - { - private static readonly List Countries = new() - { - "Germany", - "England", - "USA", - "Turkey", - "China", - "India", - "Cyprus", - "Greece", - "Bulgaria", - "Italy", - "France", - "Spain", - "Hungary" - }; + private static readonly List Countries = + [ + "Germany", + "England", + "USA", + "Turkey", + "China", + "India", + "Cyprus", + "Greece", + "Bulgaria", + "Italy", + "France", + "Spain", + "Hungary" + ]; - private static readonly List<(int publisherId, int index, string bookName, string authorName, int publishedYear)> BookAndAuthorNames = new() - { - (1,1,"In Search of Lost Time","Marcel Proust",2020), - (1,2,"Ulysses","James Joyce",1986), - (1,3,"Don Quixote","Miguel de Cervantes",1956), - (1,4,"One Hundred Years of Solitude","Gabriel Garcia Marquez",1898), - (1,5,"The Great Gatsby","F. Scott Fitzgerald",2000), - (1,6,"Moby Dick","Herman Melville",1900), - (1,7,"War and Peace","Leo Tolstoy",1992), - (1,8,"Hamlet","William Shakespeare",2021), - (1,9,"The Odyssey","Homer",1978), - (1,10,"Madame Bovary","Gustave Flaubert",2020), - (2,11,"The Divine Comedy","Dante Alighieri",2001), - (2,12,"Lolita","Vladimir Nabokov",1987), - (2,13,"The Brothers Karamazov","Fyodor Dostoyevsky",1970), - (2,14,"Crime and Punishment","Fyodor Dostoyevsky",1999), - (2,15,"Wuthering Heights","Emily Brontë",1907), - (2,16,"The Catcher in the Rye","J. D. Salinger",1980), - (2,17,"Pride and Prejudice","Jane Austen",2012), - (2,18,"The Adventures of Huckleberry Finn","Mark Twain",2001), - (2,19,"Anna Karenina","Leo Tolstoy",2003), - (2,20,"Alice's Adventures in Wonderland","Lewis Carroll",1954), - (3,21,"The Iliad","Homer",1961), - (3,22,"To the Lighthouse","Virginia Woolf",1999), - (3,23,"Catch-22","Joseph Heller",1986), - (3,24,"Heart of Darkness","Joseph Conrad",1988), - (3,25,"The Sound and the Fury","William Faulkner",1990), - (3,26,"Nineteen Eighty Four","George Orwell",1991), - (3,27,"Great Expectations","Charles Dickens",1948), - (3,28,"One Thousand and One Nights","India/Iran/Iraq/Egypt",1938), - (3,29,"The Grapes of Wrath","John Steinbeck",1881), - (3,30,"Absalom, Absalom!","William Faulkner",1901), - (4,31,"Invisible Man","Ralph Ellison",1898), - (4,32,"To Kill a Mockingbird","Harper Lee",2004), - (4,33,"The Trial","Franz Kafka",2005), - (4,34,"The Red and the Black","Stendhal",1999), - (4,35,"Middlemarch","George Eliot",1970), - (4,36,"Gulliver's Travels","Jonathan Swift",1980), - (4,37,"Mrs. Dalloway","Virginia Woolf",1990), - (4,38,"The Stories of Anton Chekhov","Anton Chekhov",1999), - (4,39,"The Stranger","Albert Camus",1908), - (4,40,"Jane Eyre","Charlotte Bronte",1991), - (5,41,"The Aeneid","Virgil",2000), - (5,42,"Collected Fiction","Jorge Luis Borges",1985), - (5,43,"The Sun Also Rises","Ernest Hemingway",1986), - (5,44,"David Copperfield","Charles Dickens",1988), - (5,45,"Tristram Shandy","Laurence Sterne",1994), - (5,46,"Leaves of Grass","Walt Whitman",2000), - (5,47,"The Magic Mountain","Thomas Mann",1955), - (5,48,"A Portrait of the Artist as a Young Man","James Joyce",1948), - (5,49,"Midnight's Children","Salman Rushdie",1997), - (5,50,"Beloved","Toni Morrison",2023) - }; + private static readonly List<(int publisherId, int index, string bookName, string authorName, int publishedYear)> BookAndAuthorNames = + [ + (1, 1, "In Search of Lost Time", "Marcel Proust", 2020), + (1, 2, "Ulysses", "James Joyce", 1986), + (1, 3, "Don Quixote", "Miguel de Cervantes", 1956), + (1, 4, "One Hundred Years of Solitude", "Gabriel Garcia Marquez", 1898), + (1, 5, "The Great Gatsby", "F. Scott Fitzgerald", 2000), + (1, 6, "Moby Dick", "Herman Melville", 1900), + (1, 7, "War and Peace", "Leo Tolstoy", 1992), + (1, 8, "Hamlet", "William Shakespeare", 2021), + (1, 9, "The Odyssey", "Homer", 1978), + (1, 10, "Madame Bovary", "Gustave Flaubert", 2020), + (2, 11, "The Divine Comedy", "Dante Alighieri", 2001), + (2, 12, "Lolita", "Vladimir Nabokov", 1987), + (2, 13, "The Brothers Karamazov", "Fyodor Dostoyevsky", 1970), + (2, 14, "Crime and Punishment", "Fyodor Dostoyevsky", 1999), + (2, 15, "Wuthering Heights", "Emily Brontë", 1907), + (2, 16, "The Catcher in the Rye", "J. D. Salinger", 1980), + (2, 17, "Pride and Prejudice", "Jane Austen", 2012), + (2, 18, "The Adventures of Huckleberry Finn", "Mark Twain", 2001), + (2, 19, "Anna Karenina", "Leo Tolstoy", 2003), + (2, 20, "Alice's Adventures in Wonderland", "Lewis Carroll", 1954), + (3, 21, "The Iliad", "Homer", 1961), + (3, 22, "To the Lighthouse", "Virginia Woolf", 1999), + (3, 23, "Catch-22", "Joseph Heller", 1986), + (3, 24, "Heart of Darkness", "Joseph Conrad", 1988), + (3, 25, "The Sound and the Fury", "William Faulkner", 1990), + (3, 26, "Nineteen Eighty Four", "George Orwell", 1991), + (3, 27, "Great Expectations", "Charles Dickens", 1948), + (3, 28, "One Thousand and One Nights", "India/Iran/Iraq/Egypt", 1938), + (3, 29, "The Grapes of Wrath", "John Steinbeck", 1881), + (3, 30, "Absalom, Absalom!", "William Faulkner", 1901), + (4, 31, "Invisible Man", "Ralph Ellison", 1898), + (4, 32, "To Kill a Mockingbird", "Harper Lee", 2004), + (4, 33, "The Trial", "Franz Kafka", 2005), + (4, 34, "The Red and the Black", "Stendhal", 1999), + (4, 35, "Middlemarch", "George Eliot", 1970), + (4, 36, "Gulliver's Travels", "Jonathan Swift", 1980), + (4, 37, "Mrs. Dalloway", "Virginia Woolf", 1990), + (4, 38, "The Stories of Anton Chekhov", "Anton Chekhov", 1999), + (4, 39, "The Stranger", "Albert Camus", 1908), + (4, 40, "Jane Eyre", "Charlotte Bronte", 1991), + (5, 41, "The Aeneid", "Virgil", 2000), + (5, 42, "Collected Fiction", "Jorge Luis Borges", 1985), + (5, 43, "The Sun Also Rises", "Ernest Hemingway", 1986), + (5, 44, "David Copperfield", "Charles Dickens", 1988), + (5, 45, "Tristram Shandy", "Laurence Sterne", 1994), + (5, 46, "Leaves of Grass", "Walt Whitman", 2000), + (5, 47, "The Magic Mountain", "Thomas Mann", 1955), + (5, 48, "A Portrait of the Artist as a Young Man", "James Joyce", 1948), + (5, 49, "Midnight's Children", "Salman Rushdie", 1997), + (5, 50, "Beloved", "Toni Morrison", 2023) + ]; - private static readonly List Publishers = new(); + private static readonly List Publishers = []; - public static IQueryable FillMockData() - { + public static IQueryable FillMockData() + { - if (Publishers.Any()) - return Publishers.AsQueryable(); + if (Publishers.Any()) + return Publishers.AsQueryable(); - var index = 1; + var index = 1; - for (var i = 1; i <= 5; i++) + for (var i = 1; i <= 5; i++) + { + Publisher publisher = new() { - Publisher publisher = new() - { - Id = i, - Name = $"Publisher {i}" - }; + Id = i, + Name = $"Publisher {i}" + }; - var publisherBooks = BookAndAuthorNames.Where(x => x.publisherId == i); + var publisherBooks = BookAndAuthorNames.Where(x => x.publisherId == i); - foreach (var publisherBook in publisherBooks) + foreach (var publisherBook in publisherBooks) + { + Book book = new() { - Book book = new() + Id = publisherBook.index, + Name = publisherBook.bookName, + Price = new Random().NextDouble() * (323.2 - 10.5) + 10.5, + PublishedYear = publisherBook.publishedYear, + CreatedDate = DateTime.Now.AddDays(-index), + Author = new Author { - Id = publisherBook.index, - Name = publisherBook.bookName, - Price = new Random().NextDouble() * (323.2 - 10.5) + 10.5, - PublishedYear = publisherBook.publishedYear, - CreatedDate = DateTime.Now.AddDays(-index), - Author = new Author + Id = index, + Name = publisherBook.authorName, + Age = index == 3 ? 30 : new Random().Next(20, 65), + Country = new Country { Id = index, - Name = publisherBook.authorName, - Age = index == 3 ? 30 : new Random().Next(20, 65), - Country = new Country - { - Id = index, - Name = Countries[new Random().Next(0, Countries.Count)] - } + Name = Countries[new Random().Next(0, Countries.Count)] } - }; - - publisher.Books.Add(book); + } + }; - index++; - } + publisher.Books.Add(book); - Publishers.Add(publisher); + index++; } - - return Publishers.AsQueryable(); + Publishers.Add(publisher); } + + + return Publishers.AsQueryable(); } -} +} \ No newline at end of file diff --git a/sample/Sample.Common/Dto/BookSearchRequest.cs b/sample/Sample.Common/Dto/BookSearchRequest.cs index 65eccd6..cc7c959 100644 --- a/sample/Sample.Common/Dto/BookSearchRequest.cs +++ b/sample/Sample.Common/Dto/BookSearchRequest.cs @@ -1,16 +1,15 @@ using SmartWhere.Attributes; using SmartWhere.Interfaces; -namespace Sample.Common.Dto +namespace Sample.Common.Dto; + +public class BookSearchRequest : IWhereClause { - public class BookSearchRequest : IWhereClause - { - public int Start { get; set; } + public int Start { get; set; } - public int Max { get; set; } + public int Max { get; set; } - [WhereClauseClass] - public BookSearchDto SearchData { get; set; } - } -} + [WhereClauseClass] + public BookSearchDto SearchData { get; set; } +} \ No newline at end of file diff --git a/sample/Sample.Common/Dto/ComparativeSearchRequest.cs b/sample/Sample.Common/Dto/ComparativeSearchRequest.cs index 19d3faa..4e9d62d 100644 --- a/sample/Sample.Common/Dto/ComparativeSearchRequest.cs +++ b/sample/Sample.Common/Dto/ComparativeSearchRequest.cs @@ -2,35 +2,34 @@ using SmartWhere.Enums; using SmartWhere.Interfaces; -namespace Sample.Common.Dto +namespace Sample.Common.Dto; + +public class ComparativeSearchRequest : IWhereClause { - public class ComparativeSearchRequest : IWhereClause - { - [ComparativeWhereCaluse("Author.Age", ComparisonOperator.GreaterThan)] - public int? AuthorAge { get; set; } + [ComparativeWhereCaluse("Author.Age", ComparisonOperator.GreaterThan)] + public int? AuthorAge { get; set; } - [ComparativeWhereCaluse("PublishedYear", ComparisonOperator.GreaterThanOrEqual)] - public int? PublishedStartYear { get; set; } + [ComparativeWhereCaluse("PublishedYear", ComparisonOperator.GreaterThanOrEqual)] + public int? PublishedStartYear { get; set; } - [ComparativeWhereCaluse("PublishedYear", ComparisonOperator.LessThanOrEqual)] - public int? PublishedEndYear { get; set; } + [ComparativeWhereCaluse("PublishedYear", ComparisonOperator.LessThanOrEqual)] + public int? PublishedEndYear { get; set; } - [ComparativeWhereCaluse("Price", ComparisonOperator.LessThan)] - public decimal? Price { get; set; } + [ComparativeWhereCaluse("Price", ComparisonOperator.LessThan)] + public decimal? Price { get; set; } - [ComparativeWhereCaluse("Price", ComparisonOperator.GreaterThanOrEqual)] - public decimal? StartPrice { get; set; } + [ComparativeWhereCaluse("Price", ComparisonOperator.GreaterThanOrEqual)] + public decimal? StartPrice { get; set; } - [ComparativeWhereCaluse("Price", ComparisonOperator.LessThanOrEqual)] - public decimal? EndPrice { get; set; } + [ComparativeWhereCaluse("Price", ComparisonOperator.LessThanOrEqual)] + public decimal? EndPrice { get; set; } - [ComparativeWhereCaluse("CreatedDate", ComparisonOperator.LessThan)] - public DateTime? BookCreatedDate { get; set; } + [ComparativeWhereCaluse("CreatedDate", ComparisonOperator.LessThan)] + public DateTime? BookCreatedDate { get; set; } - [ComparativeWhereCaluse("CreatedDate", ComparisonOperator.GreaterThanOrEqual)] - public DateTime? StartCreatedDate { get; set; } + [ComparativeWhereCaluse("CreatedDate", ComparisonOperator.GreaterThanOrEqual)] + public DateTime? StartCreatedDate { get; set; } - [ComparativeWhereCaluse("CreatedDate", ComparisonOperator.LessThanOrEqual)] - public DateTime? EndCreatedDate { get; set; } - } -} + [ComparativeWhereCaluse("CreatedDate", ComparisonOperator.LessThanOrEqual)] + public DateTime? EndCreatedDate { get; set; } +} \ No newline at end of file diff --git a/sample/Sample.Common/Dto/PublisherSearchRequest.cs b/sample/Sample.Common/Dto/PublisherSearchRequest.cs index e503534..a60ddae 100644 --- a/sample/Sample.Common/Dto/PublisherSearchRequest.cs +++ b/sample/Sample.Common/Dto/PublisherSearchRequest.cs @@ -1,29 +1,28 @@ using SmartWhere.Attributes; using SmartWhere.Interfaces; -namespace Sample.Common.Dto +namespace Sample.Common.Dto; + +public class PublisherSearchRequest : IWhereClause { - public class PublisherSearchRequest : IWhereClause - { - [WhereClause(PropertyName = "Id")] - public int? PublisherId { get; set; } + [WhereClause(PropertyName = "Id")] + public int? PublisherId { get; set; } - [WhereClause] - public string Name { get; set; } + [WhereClause] + public string Name { get; set; } - [WhereClause("Book.Name")] - public string BookName { get; set; } + [WhereClause("Book.Name")] + public string BookName { get; set; } - [WhereClause("Books.Author.Name")] - public string AuthorName { get; set; } + [WhereClause("Books.Author.Name")] + public string AuthorName { get; set; } - [WhereClause("Book.PublishedYear")] - public int? BookPublishedYear { get; set; } + [WhereClause("Book.PublishedYear")] + public int? BookPublishedYear { get; set; } - [WhereClause("Book.Author.Age")] - public int? AuthorAge { get; set; } + [WhereClause("Book.Author.Age")] + public int? AuthorAge { get; set; } - [WhereClause("Book.Author.Country.Name")] - public string AuthorCountry { get; set; } - } -} + [WhereClause("Book.Author.Country.Name")] + public string AuthorCountry { get; set; } +} \ No newline at end of file diff --git a/sample/Sample.Common/Dto/TextualSearchRequest.cs b/sample/Sample.Common/Dto/TextualSearchRequest.cs index b5a19a7..8c8b577 100644 --- a/sample/Sample.Common/Dto/TextualSearchRequest.cs +++ b/sample/Sample.Common/Dto/TextualSearchRequest.cs @@ -2,20 +2,19 @@ using SmartWhere.Enums; using SmartWhere.Interfaces; -namespace Sample.Common.Dto +namespace Sample.Common.Dto; + +public class TextualSearchRequest : IWhereClause { - public class TextualSearchRequest : IWhereClause - { - [TextualWhereClause(StringMethod.Contains)] - public string Name { get; set; } + [TextualWhereClause(StringMethod.Contains)] + public string Name { get; set; } - [TextualWhereClause("Name", StringMethod.NotContains)] - public string BookName { get; set; } + [TextualWhereClause("Name", StringMethod.NotContains)] + public string BookName { get; set; } - [TextualWhereClause("Author.Name", StringMethod.NotStartsWith)] - public string AuthorName { get; set; } + [TextualWhereClause("Author.Name", StringMethod.NotStartsWith)] + public string AuthorName { get; set; } - [TextualWhereClause("Author.Country.Name", StringMethod.NotEndsWith)] - public string CountryName { get; set; } - } -} + [TextualWhereClause("Author.Country.Name", StringMethod.NotEndsWith)] + public string CountryName { get; set; } +} \ No newline at end of file diff --git a/sample/Sample.Common/Entity/Author.cs b/sample/Sample.Common/Entity/Author.cs index e4917b8..19634c2 100644 --- a/sample/Sample.Common/Entity/Author.cs +++ b/sample/Sample.Common/Entity/Author.cs @@ -1,13 +1,12 @@ -namespace Sample.Common.Entity +namespace Sample.Common.Entity; + +public class Author { - public class Author - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public int Age { get; set; } + public int Age { get; set; } - public Country Country { get; set; } - } -} + public Country Country { get; set; } +} \ No newline at end of file diff --git a/sample/Sample.Common/Entity/Book.cs b/sample/Sample.Common/Entity/Book.cs index 3ca2851..5b87e80 100644 --- a/sample/Sample.Common/Entity/Book.cs +++ b/sample/Sample.Common/Entity/Book.cs @@ -1,18 +1,17 @@ -namespace Sample.Common.Entity +namespace Sample.Common.Entity; + +public class Book { - public class Book - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public int PublishedYear { get; set; } + public int PublishedYear { get; set; } - public double Price { get; set; } + public double Price { get; set; } - public DateTime CreatedDate { get; set; } + public DateTime CreatedDate { get; set; } - public Author Author { get; set; } + public Author Author { get; set; } - } -} +} \ No newline at end of file diff --git a/sample/Sample.Common/Entity/Country.cs b/sample/Sample.Common/Entity/Country.cs index 8f00e08..3260d16 100644 --- a/sample/Sample.Common/Entity/Country.cs +++ b/sample/Sample.Common/Entity/Country.cs @@ -1,9 +1,8 @@ -namespace Sample.Common.Entity +namespace Sample.Common.Entity; + +public class Country { - public class Country - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } - } -} + public string Name { get; set; } +} \ No newline at end of file diff --git a/sample/Sample.Common/Entity/Publisher.cs b/sample/Sample.Common/Entity/Publisher.cs index 86440cf..e44d43e 100644 --- a/sample/Sample.Common/Entity/Publisher.cs +++ b/sample/Sample.Common/Entity/Publisher.cs @@ -1,11 +1,10 @@ -namespace Sample.Common.Entity +namespace Sample.Common.Entity; + +public class Publisher { - public class Publisher - { - public int Id { get; set; } + public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public List Books { get; set; } = new(); - } -} + public List Books { get; set; } = new(); +} \ No newline at end of file From 1e8bb5c323f0b9d5ff96917bc27df7843fa29e68 Mon Sep 17 00:00:00 2001 From: Baris Yerlikaya Date: Sun, 14 Apr 2024 10:54:16 +0300 Subject: [PATCH 2/4] namespaces were edited, package update was done. --- .../ComparativeWhereCaluseTest.cs | 323 +++++++++--------- tests/SmartWhere.Tests/SmartWhere.Test.csproj | 6 +- .../TextualWhereClauseTest.cs | 217 ++++++------ tests/SmartWhere.Tests/WhereClauseTest.cs | 243 +++++++------ 4 files changed, 393 insertions(+), 396 deletions(-) diff --git a/tests/SmartWhere.Tests/ComparativeWhereCaluseTest.cs b/tests/SmartWhere.Tests/ComparativeWhereCaluseTest.cs index 3a5ad35..2ecabf0 100644 --- a/tests/SmartWhere.Tests/ComparativeWhereCaluseTest.cs +++ b/tests/SmartWhere.Tests/ComparativeWhereCaluseTest.cs @@ -1,204 +1,203 @@ -namespace SmartWhere.Test +namespace SmartWhere.Test; + +public class ComparativeWhereCaluseTest { - public class ComparativeWhereCaluseTest - { - private readonly IQueryable _books = DataInitializer.FillMockData() - .SelectMany(x => x.Books) - .AsQueryable(); + private readonly IQueryable _books = DataInitializer.FillMockData() + .SelectMany(x => x.Books) + .AsQueryable(); - [Fact] - public void SmartWhere_Should_Return_Results_Grater_Than_AuthorAge_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Grater_Than_AuthorAge_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - AuthorAge = 20 - }; + AuthorAge = 20 + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => x.Author.Age > 20)); - } + //Assert + Assert.True(result.Any(x => x.Author.Age > 20)); + } - [Fact] - public void SmartWhere_Should_Return_Results_Grater_Than_Or_Equal_PublishedStartYear_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Grater_Than_Or_Equal_PublishedStartYear_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - PublishedStartYear = 1990 - }; + PublishedStartYear = 1990 + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => x.PublishedYear >= 1990)); - } + //Assert + Assert.True(result.Any(x => x.PublishedYear >= 1990)); + } - [Fact] - public void SmartWhere_Should_Return_Results_Less_Than_Or_Equal_PublishedEndYear_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Less_Than_Or_Equal_PublishedEndYear_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - PublishedEndYear = 2000 - }; + PublishedEndYear = 2000 + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => x.PublishedYear <= 2000)); - } + //Assert + Assert.True(result.Any(x => x.PublishedYear <= 2000)); + } - [Fact] - public void SmartWhere_Should_Return_Results_Grater_Than_Or_Equal_PublishedStartYear_Parameter_And_Less_Than_Or_Equal_PublishedEndYear_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Grater_Than_Or_Equal_PublishedStartYear_Parameter_And_Less_Than_Or_Equal_PublishedEndYear_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - PublishedStartYear = 1980, - PublishedEndYear = 1999 - }; - - //Act - var result = _books.Where(request); - - //Assert - Assert.True(result.Any(x => x.PublishedYear >= 1980 && x.PublishedYear <= 1999)); - } - - [Fact] - public void SmartWhere_Should_Return_Results_Less_Than_Price_Parameter() + PublishedStartYear = 1980, + PublishedEndYear = 1999 + }; + + //Act + var result = _books.Where(request); + + //Assert + Assert.True(result.Any(x => x.PublishedYear >= 1980 && x.PublishedYear <= 1999)); + } + + [Fact] + public void SmartWhere_Should_Return_Results_Less_Than_Price_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - Price = 120 - }; + Price = 120 + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => x.Price < 120)); - } + //Assert + Assert.True(result.Any(x => x.Price < 120)); + } - [Fact] - public void SmartWhere_Should_Return_Results_Greater_Than_Or_Equal_StartPrice_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Greater_Than_Or_Equal_StartPrice_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - StartPrice = 120 - }; + StartPrice = 120 + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => x.Price >= 120)); - } + //Assert + Assert.True(result.Any(x => x.Price >= 120)); + } - [Fact] - public void SmartWhere_Should_Return_Results_Less_Than_Or_Equal_EndPrice_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Less_Than_Or_Equal_EndPrice_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - EndPrice = 230 - }; + EndPrice = 230 + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => x.Price <= 230)); - } + //Assert + Assert.True(result.Any(x => x.Price <= 230)); + } - [Fact] - public void SmartWhere_Should_Return_Results_Greater_Than_Or_Equal_StartPrice_Parameter_And_Less_Than_Or_Equal_EndPrice_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Greater_Than_Or_Equal_StartPrice_Parameter_And_Less_Than_Or_Equal_EndPrice_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - StartPrice = 140, - EndPrice = 300 - }; - - //Act - var result = _books.Where(request); - - //Assert - Assert.True(result.Any(x => x.Price >= 140 && x.Price <= 300)); - } - - [Fact] - public void SmartWhere_Should_Return_Results_Less_Than_BookCreatedDate_Parameter() + StartPrice = 140, + EndPrice = 300 + }; + + //Act + var result = _books.Where(request); + + //Assert + Assert.True(result.Any(x => x.Price >= 140 && x.Price <= 300)); + } + + [Fact] + public void SmartWhere_Should_Return_Results_Less_Than_BookCreatedDate_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - BookCreatedDate = DateTime.Now.AddDays(-3) - }; + BookCreatedDate = DateTime.Now.AddDays(-3) + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => x.CreatedDate <= DateTime.Now.AddDays(-3))); - } + //Assert + Assert.True(result.Any(x => x.CreatedDate <= DateTime.Now.AddDays(-3))); + } - [Fact] - public void SmartWhere_Should_Return_Results_Greater_Than_Or_Equal_StartCreatedDate_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Greater_Than_Or_Equal_StartCreatedDate_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - StartCreatedDate = DateTime.Now.AddDays(-15) - }; + StartCreatedDate = DateTime.Now.AddDays(-15) + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => x.CreatedDate >= DateTime.Now.AddDays(-15))); - } + //Assert + Assert.True(result.Any(x => x.CreatedDate >= DateTime.Now.AddDays(-15))); + } - [Fact] - public void SmartWhere_Should_Return_Results_Less_Than_Or_Equal_EndCreatedDate_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Less_Than_Or_Equal_EndCreatedDate_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - EndCreatedDate = DateTime.Now.AddDays(-5) - }; + EndCreatedDate = DateTime.Now.AddDays(-5) + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => x.CreatedDate <= DateTime.Now.AddDays(-5))); - } + //Assert + Assert.True(result.Any(x => x.CreatedDate <= DateTime.Now.AddDays(-5))); + } - [Fact] - public void SmartWhere_Should_Return_Results_Greater_Than_Or_Equal_StartCreatedDate_Parameter_And_Less_Than_Or_Equal_EndCreatedDate_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Greater_Than_Or_Equal_StartCreatedDate_Parameter_And_Less_Than_Or_Equal_EndCreatedDate_Parameter() + { + //Arrange + ComparativeSearchRequest request = new() { - //Arrange - ComparativeSearchRequest request = new() - { - StartCreatedDate = DateTime.Now.AddDays(-8), - EndCreatedDate = DateTime.Now.AddDays(-2) - }; - - //Act - var result = _books.Where(request); - - //Assert - Assert.True(result.Any(x => x.CreatedDate >= DateTime.Now.AddDays(-8) && x.CreatedDate <= DateTime.Now.AddDays(-2))); - } + StartCreatedDate = DateTime.Now.AddDays(-8), + EndCreatedDate = DateTime.Now.AddDays(-2) + }; + + //Act + var result = _books.Where(request); + + //Assert + Assert.True(result.Any(x => x.CreatedDate >= DateTime.Now.AddDays(-8) && x.CreatedDate <= DateTime.Now.AddDays(-2))); } -} +} \ No newline at end of file diff --git a/tests/SmartWhere.Tests/SmartWhere.Test.csproj b/tests/SmartWhere.Tests/SmartWhere.Test.csproj index 0a7a47b..a81ea27 100644 --- a/tests/SmartWhere.Tests/SmartWhere.Test.csproj +++ b/tests/SmartWhere.Tests/SmartWhere.Test.csproj @@ -9,12 +9,12 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/SmartWhere.Tests/TextualWhereClauseTest.cs b/tests/SmartWhere.Tests/TextualWhereClauseTest.cs index 22c1b9b..32ae107 100644 --- a/tests/SmartWhere.Tests/TextualWhereClauseTest.cs +++ b/tests/SmartWhere.Tests/TextualWhereClauseTest.cs @@ -1,135 +1,134 @@ -namespace SmartWhere.Test +namespace SmartWhere.Test; + +public class TextualWhereClauseTest { - public class TextualWhereClauseTest + private readonly IQueryable _books = DataInitializer.FillMockData().SelectMany(x => x.Books).AsQueryable(); + + [Fact] + public void SmartWhere_Should_Return_Results_Contains_Name_Parameter() { - private readonly IQueryable _books = DataInitializer.FillMockData().SelectMany(x => x.Books).AsQueryable(); + //Arrange + TextualSearchRequest request = new() + { + Name = "Nineteen" + }; + + //Act + var result = _books.Where(request); - [Fact] - public void SmartWhere_Should_Return_Results_Contains_Name_Parameter() + //Assert + Assert.True(result.Any(x => x.Name.Contains("Nineteen"))); + } + + [Fact] + public void SmartWhere_Should_Return_Results_Not_Contains_BookName_Parameter() + { + //Arrange + TextualSearchRequest request = new() { - //Arrange - TextualSearchRequest request = new() - { - Name = "Nineteen" - }; + BookName = "Example Book Name" + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => x.Name.Contains("Nineteen"))); - } + //Assert + Assert.True(result.Any(x => !x.Name.Contains("Example Book Name"))); + } - [Fact] - public void SmartWhere_Should_Return_Results_Not_Contains_BookName_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Starting_With_Name_Parameter() + { + //Arrange + BookSearchRequest request = new() { - //Arrange - TextualSearchRequest request = new() + Start = 0, + Max = 50, + SearchData = new BookSearchDto { - BookName = "Example Book Name" - }; + Name = "Nineteen" + } + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => !x.Name.Contains("Example Book Name"))); - } + //Assert + Assert.True(result.Any(x => x.Name.StartsWith("Nineteen"))); + } - [Fact] - public void SmartWhere_Should_Return_Results_Starting_With_Name_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Not_Starting_With_AuthorName_Parameter() + { + //Arrange + TextualSearchRequest request = new() { - //Arrange - BookSearchRequest request = new() - { - Start = 0, - Max = 50, - SearchData = new BookSearchDto - { - Name = "Nineteen" - } - }; - - //Act - var result = _books.Where(request); - - //Assert - Assert.True(result.Any(x => x.Name.StartsWith("Nineteen"))); - } - - [Fact] - public void SmartWhere_Should_Return_Results_Not_Starting_With_AuthorName_Parameter() + AuthorName = "Camus" + }; + + //Act + var result = _books.Where(request); + + //Assert + Assert.True(result.Any(x => !x.Name.StartsWith("Camus"))); + } + + [Fact] + public void SmartWhere_Should_Return_Results_Ending_With_AuthorName_Parameter() + { + //Arrange + BookSearchRequest request = new() { - //Arrange - TextualSearchRequest request = new() + Start = 0, + Max = 50, + SearchData = new BookSearchDto { AuthorName = "Camus" - }; + } + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => !x.Name.StartsWith("Camus"))); - } + //Assert + Assert.True(result.Any(x => x.Author.Name.EndsWith("Camus"))); + } - [Fact] - public void SmartWhere_Should_Return_Results_Ending_With_AuthorName_Parameter() - { - //Arrange - BookSearchRequest request = new() - { - Start = 0, - Max = 50, - SearchData = new BookSearchDto - { - AuthorName = "Camus" - } - }; - - //Act - var result = _books.Where(request); - - //Assert - Assert.True(result.Any(x => x.Author.Name.EndsWith("Camus"))); - } - - [Fact] - public void SmartWhere_Should_Return_Results_Not_Ending_With_CountryName_Parameter() + [Fact] + public void SmartWhere_Should_Return_Results_Not_Ending_With_CountryName_Parameter() + { + //Arrange + TextualSearchRequest request = new() { - //Arrange - TextualSearchRequest request = new() - { - CountryName = "ta" - }; + CountryName = "ta" + }; - //Act - var result = _books.Where(request); + //Act + var result = _books.Where(request); - //Assert - Assert.True(result.Any(x => !x.Author.Country.Name.EndsWith("ta"))); - } + //Assert + Assert.True(result.Any(x => !x.Author.Country.Name.EndsWith("ta"))); + } - [Fact] - public void SmartWhere_Should_Return_Results_Starting_With_Name_And_Ending_With_AuthorName() + [Fact] + public void SmartWhere_Should_Return_Results_Starting_With_Name_And_Ending_With_AuthorName() + { + //Arrange + BookSearchRequest request = new() { - //Arrange - BookSearchRequest request = new() + Start = 0, + Max = 50, + SearchData = new BookSearchDto { - Start = 0, - Max = 50, - SearchData = new BookSearchDto - { - Name = "Anna", - AuthorName = "toy" - } - }; - - //Act - var result = _books.Where(request); - - //Assert - Assert.True(result.Any(x => x.Name.StartsWith("Anna") && x.Author.Name.EndsWith("toy"))); - } + Name = "Anna", + AuthorName = "toy" + } + }; + + //Act + var result = _books.Where(request); + + //Assert + Assert.True(result.Any(x => x.Name.StartsWith("Anna") && x.Author.Name.EndsWith("toy"))); } -} +} \ No newline at end of file diff --git a/tests/SmartWhere.Tests/WhereClauseTest.cs b/tests/SmartWhere.Tests/WhereClauseTest.cs index c552dfe..0bd738b 100644 --- a/tests/SmartWhere.Tests/WhereClauseTest.cs +++ b/tests/SmartWhere.Tests/WhereClauseTest.cs @@ -1,154 +1,153 @@ -namespace SmartWhere.Test +namespace SmartWhere.Test; + +public class WhereClauseTest { - public class WhereClauseTest - { - private readonly IQueryable _publishers = DataInitializer.FillMockData(); + private readonly IQueryable _publishers = DataInitializer.FillMockData(); - [Fact] - public void SmartWhere_Should_Return_Results_By_PublisherId() + [Fact] + public void SmartWhere_Should_Return_Results_By_PublisherId() + { + //Arrange + PublisherSearchRequest request = new() { - //Arrange - PublisherSearchRequest request = new() - { - PublisherId = 3 - }; + PublisherId = 3 + }; - //Act - var result = _publishers.Where(request); + //Act + var result = _publishers.Where(request); - //Assert - Assert.True(result.Any(x => x.Id == 3)); - } + //Assert + Assert.True(result.Any(x => x.Id == 3)); + } - [Fact] - public void SmartWhere_Should_Return_Results_By_PublisherName() + [Fact] + public void SmartWhere_Should_Return_Results_By_PublisherName() + { + //Arrange + PublisherSearchRequest request = new() { - //Arrange - PublisherSearchRequest request = new() - { - Name = "Publisher 4" - }; + Name = "Publisher 4" + }; - //Act - var result = _publishers.Where(request); + //Act + var result = _publishers.Where(request); - //Assert - Assert.True(result.Any(x => x.Name == "Publisher 4")); - } + //Assert + Assert.True(result.Any(x => x.Name == "Publisher 4")); + } - [Fact] - public void SmartWhere_Should_Return_Results_By_PublisherId_And_Name() + [Fact] + public void SmartWhere_Should_Return_Results_By_PublisherId_And_Name() + { + //Arrange + PublisherSearchRequest request = new() { - //Arrange - PublisherSearchRequest request = new() - { - PublisherId = 4, - Name = "Publisher 4" - }; - - //Act - var result = _publishers.Where(request); - - //Assert - Assert.True(result.Any(x => x.Name == "Publisher 4" && x.Id == 4)); - } - - [Fact] - public void SmartWhere_Should_Return_Results_By_AuthorName() + PublisherId = 4, + Name = "Publisher 4" + }; + + //Act + var result = _publishers.Where(request); + + //Assert + Assert.True(result.Any(x => x.Name == "Publisher 4" && x.Id == 4)); + } + + [Fact] + public void SmartWhere_Should_Return_Results_By_AuthorName() + { + //Arrange + PublisherSearchRequest request = new() { - //Arrange - PublisherSearchRequest request = new() - { - AuthorName = "George Eliot" - }; + AuthorName = "George Eliot" + }; - //Act - var result = _publishers.Where(request); + //Act + var result = _publishers.Where(request); - //Assert - Assert.True(result.Any(x => x.Books.Any(b => b.Author.Name == "George Eliot"))); - } + //Assert + Assert.True(result.Any(x => x.Books.Any(b => b.Author.Name == "George Eliot"))); + } - [Fact] - public void SmartWhere_Should_Return_Results_By_BookName() + [Fact] + public void SmartWhere_Should_Return_Results_By_BookName() + { + //Arrange + PublisherSearchRequest request = new() { - //Arrange - PublisherSearchRequest request = new() - { - BookName = "Middlemarch" - }; + BookName = "Middlemarch" + }; - //Act - var result = _publishers.Where(request); + //Act + var result = _publishers.Where(request); - //Assert - Assert.True(result.Any(x => x.Books.Any(b => b.Name == "Middlemarch"))); - } + //Assert + Assert.True(result.Any(x => x.Books.Any(b => b.Name == "Middlemarch"))); + } - [Fact] - public void SmartWhere_Should_Return_Results_By_BookName_And_AuthorName() + [Fact] + public void SmartWhere_Should_Return_Results_By_BookName_And_AuthorName() + { + //Arrange + PublisherSearchRequest request = new() { - //Arrange - PublisherSearchRequest request = new() - { - BookName = "Middlemarch", - AuthorName = "George Eliot" - }; - - //Act - var result = _publishers.Where(request); - - //Assert - Assert.True(result.Any(x => x.Books.Any(b => b.Name == "Middlemarch" && b.Author.Name == "George Eliot"))); - } - - [Fact] - public void SmartWhere_Should_Return_Results_By_BookPublishedYear() + BookName = "Middlemarch", + AuthorName = "George Eliot" + }; + + //Act + var result = _publishers.Where(request); + + //Assert + Assert.True(result.Any(x => x.Books.Any(b => b.Name == "Middlemarch" && b.Author.Name == "George Eliot"))); + } + + [Fact] + public void SmartWhere_Should_Return_Results_By_BookPublishedYear() + { + //Arrange + PublisherSearchRequest request = new() { - //Arrange - PublisherSearchRequest request = new() - { - BookPublishedYear = 1986 - }; + BookPublishedYear = 1986 + }; - //Act - var result = _publishers.Where(request); + //Act + var result = _publishers.Where(request); - //Assert - Assert.True(result.Any(x => x.Books.Any(b => b.PublishedYear == 1986))); - } + //Assert + Assert.True(result.Any(x => x.Books.Any(b => b.PublishedYear == 1986))); + } - [Fact] - public void SmartWhere_Should_Return_Results_By_AuthorAge() + [Fact] + public void SmartWhere_Should_Return_Results_By_AuthorAge() + { + //Arrange + PublisherSearchRequest request = new() { - //Arrange - PublisherSearchRequest request = new() - { - AuthorAge = 30 - }; + AuthorAge = 30 + }; - //Act - var result = _publishers.Where(request); + //Act + var result = _publishers.Where(request); - //Assert - Assert.True(result.Any(x => x.Books.Any(b => b.Author.Age == 30))); - } + //Assert + Assert.True(result.Any(x => x.Books.Any(b => b.Author.Age == 30))); + } - [Fact] - public void SmartWhere_Should_Return_Results_By_AuthorCountry() + [Fact] + public void SmartWhere_Should_Return_Results_By_AuthorCountry() + { + //Arrange + PublisherSearchRequest request = new() { - //Arrange - PublisherSearchRequest request = new() - { - AuthorCountry = "Turkey" - }; - - //Act - var result = _publishers.Where(request); - - //Assert - Assert.True(result.Any(x => x.Books.Any(b => b.Author.Country.Name == "Turkey"))); - } + AuthorCountry = "Turkey" + }; + + //Act + var result = _publishers.Where(request); + + //Assert + Assert.True(result.Any(x => x.Books.Any(b => b.Author.Country.Name == "Turkey"))); } } \ No newline at end of file From ee9eb7d594a759a3bbae2afc625c9843df602b7b Mon Sep 17 00:00:00 2001 From: Baris Yerlikaya Date: Sun, 14 Apr 2024 10:55:06 +0300 Subject: [PATCH 3/4] refactored and updated packages. --- src/SmartWhere/Attributes/WhereClauseClassAttribute.cs | 4 +--- src/SmartWhere/Interfaces/IWhereClause.cs | 4 +--- src/SmartWhere/SmartWhere.cs | 6 +++--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/SmartWhere/Attributes/WhereClauseClassAttribute.cs b/src/SmartWhere/Attributes/WhereClauseClassAttribute.cs index e53f42c..17f68ae 100644 --- a/src/SmartWhere/Attributes/WhereClauseClassAttribute.cs +++ b/src/SmartWhere/Attributes/WhereClauseClassAttribute.cs @@ -1,6 +1,4 @@ namespace SmartWhere.Attributes; [AttributeUsage(AttributeTargets.Property)] -public class WhereClauseClassAttribute : Attribute -{ -} \ No newline at end of file +public class WhereClauseClassAttribute : Attribute; \ No newline at end of file diff --git a/src/SmartWhere/Interfaces/IWhereClause.cs b/src/SmartWhere/Interfaces/IWhereClause.cs index 81b8074..61041ff 100644 --- a/src/SmartWhere/Interfaces/IWhereClause.cs +++ b/src/SmartWhere/Interfaces/IWhereClause.cs @@ -1,5 +1,3 @@ namespace SmartWhere.Interfaces; -public interface IWhereClause -{ -} \ No newline at end of file +public interface IWhereClause; \ No newline at end of file diff --git a/src/SmartWhere/SmartWhere.cs b/src/SmartWhere/SmartWhere.cs index 2200d70..a8b6022 100644 --- a/src/SmartWhere/SmartWhere.cs +++ b/src/SmartWhere/SmartWhere.cs @@ -252,7 +252,7 @@ private static Expression ComplexComparison( { methodExpression = Expression.Call(typeof(Enumerable), "Any", - new[] { lastEnumerableMember.Type.GetGenericArguments().FirstOrDefault() }, + [lastEnumerableMember.Type.GetGenericArguments().FirstOrDefault()], lastEnumerableMember, Expression.Lambda(methodExpression!, parameterExpression!)); } @@ -345,7 +345,7 @@ private static Expression MethodExpressionForComplexComparison( { return Expression.Call(typeof(Enumerable), "Any", - new[] { lastMember.Type.GetGenericArguments().FirstOrDefault() }, + [lastMember.Type.GetGenericArguments().FirstOrDefault()], lastMember, Expression.Lambda(methodExpression, parameterExpression)); } @@ -357,7 +357,7 @@ private static Expression MethodExpressionForComplexComparison( { return Expression.Call(typeof(Enumerable), "Any", - new[] { lastEnumerableMember.Type.GetGenericArguments().FirstOrDefault() }, + [lastEnumerableMember.Type.GetGenericArguments().FirstOrDefault()], lastEnumerableMember, Expression.Lambda(methodExpression!, parameterExpression)); } From 6b863db4a52fb5c854e218e4b96e08546743c2fd Mon Sep 17 00:00:00 2001 From: Baris Yerlikaya Date: Sun, 14 Apr 2024 10:57:41 +0300 Subject: [PATCH 4/4] version number upgraded, license file updated. --- LICENSE | 2 +- src/SmartWhere/SmartWhere.csproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index ec87858..14cbedc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Baris Yerlikaya +Copyright (c) 2024 Baris Yerlikaya Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/SmartWhere/SmartWhere.csproj b/src/SmartWhere/SmartWhere.csproj index 937efe9..91492fd 100644 --- a/src/SmartWhere/SmartWhere.csproj +++ b/src/SmartWhere/SmartWhere.csproj @@ -2,13 +2,13 @@ SmartWhere - 2.2.0.2 + 2.2.0.3 Barış Yerlikaya Barış Yerlikaya SmartWhere SmartWhere It intelligently filters a sequence of items in a simple and practical way. - Copyright (c) 2023 Barış Yerlikaya + Copyright (c) 2024 Barış Yerlikaya README.md https://github.com/byerlikaya/SmartWhere filter filtering where whereclause smartwhere netcore smart