public void GetShoppingListItem_ParametersMatchExpectedValues()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>()
                            .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeShoppingListItem = new FakeShoppingListItem {
            }.Generate();

            //Act
            using (var context = new CarbonKitchenDbContext(dbOptions))
            {
                context.ShoppingListItems.AddRange(fakeShoppingListItem);
                context.SaveChanges();

                var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions));

                //Assert
                var ShoppingListItemById = context.ShoppingListItems.FirstOrDefault(i => i.ShoppingListItemId == fakeShoppingListItem.ShoppingListItemId);

                ShoppingListItemById.Should().BeEquivalentTo(fakeShoppingListItem);
                ShoppingListItemById.ShoppingListItemId.Should().Be(fakeShoppingListItem.ShoppingListItemId);
                ShoppingListItemById.Name.Should().Be(fakeShoppingListItem.Name);
                ShoppingListItemById.Category.Should().Be(fakeShoppingListItem.Category);
                ShoppingListItemById.Unit.Should().Be(fakeShoppingListItem.Unit);
            }
        }
        public void GetShoppingListItems_FilterListWithExact(string filters)
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>()
                            .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeShoppingListItemOne = new FakeShoppingListItem {
            }.Generate();

            fakeShoppingListItemOne.Name           = "Alpha";
            fakeShoppingListItemOne.Category       = "Bravo";
            fakeShoppingListItemOne.ShoppingListId = 5;

            var fakeShoppingListItemTwo = new FakeShoppingListItem {
            }.Generate();

            fakeShoppingListItemTwo.Name           = "Charlie";
            fakeShoppingListItemTwo.Category       = "Delta";
            fakeShoppingListItemTwo.ShoppingListId = 6;

            var fakeShoppingListItemThree = new FakeShoppingListItem {
            }.Generate();

            fakeShoppingListItemThree.Name           = "Echo";
            fakeShoppingListItemThree.Category       = "Foxtrot";
            fakeShoppingListItemThree.ShoppingListId = 7;

            //Act
            using (var context = new CarbonKitchenDbContext(dbOptions))
            {
                context.ShoppingListItems.AddRange(fakeShoppingListItemOne, fakeShoppingListItemTwo, fakeShoppingListItemThree);
                context.SaveChanges();

                var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions));

                var ShoppingListItemRepo = service.GetShoppingListItems(new ShoppingListItemParametersDto {
                    Filters = filters
                });

                //Assert
                ShoppingListItemRepo.Should()
                .HaveCount(1);

                context.Database.EnsureDeleted();
            }
        }
        public void GetShoppingListItems_SearchQueryReturnsExpectedRecordCount(string queryString, int expectedCount)
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>()
                            .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeShoppingListItemOne = new FakeShoppingListItem {
            }.Generate();

            fakeShoppingListItemOne.Name     = "Alpha";
            fakeShoppingListItemOne.Category = "Bravo";

            var fakeShoppingListItemTwo = new FakeShoppingListItem {
            }.Generate();

            fakeShoppingListItemTwo.Name     = "Hartsfield";
            fakeShoppingListItemTwo.Category = "White";

            var fakeShoppingListItemThree = new FakeShoppingListItem {
            }.Generate();

            fakeShoppingListItemThree.Name     = "Bravehart";
            fakeShoppingListItemThree.Category = "Jonfav";

            //Act
            using (var context = new CarbonKitchenDbContext(dbOptions))
            {
                context.ShoppingListItems.AddRange(fakeShoppingListItemOne, fakeShoppingListItemTwo, fakeShoppingListItemThree);
                context.SaveChanges();

                var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions));

                var ShoppingListItemRepo = service.GetShoppingListItems(new ShoppingListItemParametersDto {
                    QueryString = queryString
                });

                //Assert
                ShoppingListItemRepo.Should()
                .HaveCount(expectedCount);

                context.Database.EnsureDeleted();
            }
        }
        public void GetShoppingListItems_ListSortedInDescOrder()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>()
                            .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeShoppingListItemOne = new FakeShoppingListItem {
            }.Generate();

            fakeShoppingListItemOne.Name = "Bravo";

            var fakeShoppingListItemTwo = new FakeShoppingListItem {
            }.Generate();

            fakeShoppingListItemTwo.Name = "Alpha";

            var fakeShoppingListItemThree = new FakeShoppingListItem {
            }.Generate();

            fakeShoppingListItemThree.Name = "Charlie";

            //Act
            using (var context = new CarbonKitchenDbContext(dbOptions))
            {
                context.ShoppingListItems.AddRange(fakeShoppingListItemOne, fakeShoppingListItemTwo, fakeShoppingListItemThree);
                context.SaveChanges();

                var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions));

                var ShoppingListItemRepo = service.GetShoppingListItems(new ShoppingListItemParametersDto {
                    SortOrder = "-Name"
                });

                //Assert
                ShoppingListItemRepo.Should()
                .ContainInOrder(fakeShoppingListItemThree, fakeShoppingListItemOne, fakeShoppingListItemTwo);

                context.Database.EnsureDeleted();
            }
        }
        public void DeleteShoppingListItem_ReturnsProperCount()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>()
                            .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeShoppingListItemOne = new FakeShoppingListItem {
            }.Generate();
            var fakeShoppingListItemTwo = new FakeShoppingListItem {
            }.Generate();
            var fakeShoppingListItemThree = new FakeShoppingListItem {
            }.Generate();

            //Act
            using (var context = new CarbonKitchenDbContext(dbOptions))
            {
                context.ShoppingListItems.AddRange(fakeShoppingListItemOne, fakeShoppingListItemTwo, fakeShoppingListItemThree);

                var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions));
                service.DeleteShoppingListItem(fakeShoppingListItemTwo);

                context.SaveChanges();

                //Assert
                var ShoppingListItemList = context.ShoppingListItems.ToList();

                ShoppingListItemList.Should()
                .NotBeEmpty()
                .And.HaveCount(2);

                ShoppingListItemList.Should().ContainEquivalentOf(fakeShoppingListItemOne);
                ShoppingListItemList.Should().ContainEquivalentOf(fakeShoppingListItemThree);
                Assert.DoesNotContain(ShoppingListItemList, i => i == fakeShoppingListItemTwo);

                context.Database.EnsureDeleted();
            }
        }
        public void GetShoppingListItems_ReturnExpectedPageSize()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <CarbonKitchenDbContext>()
                            .UseInMemoryDatabase(databaseName: $"ShoppingListItemDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeShoppingListItemOne = new FakeShoppingListItem {
            }.Generate();
            var fakeShoppingListItemTwo = new FakeShoppingListItem {
            }.Generate();
            var fakeShoppingListItemThree = new FakeShoppingListItem {
            }.Generate();

            //Act
            using (var context = new CarbonKitchenDbContext(dbOptions))
            {
                context.ShoppingListItems.AddRange(fakeShoppingListItemOne, fakeShoppingListItemTwo, fakeShoppingListItemThree);
                context.SaveChanges();

                var service = new ShoppingListItemRepository(context, new SieveProcessor(sieveOptions));

                var ShoppingListItemRepo = service.GetShoppingListItems(new ShoppingListItemParametersDto {
                    PageSize = 2
                });

                //Assert
                ShoppingListItemRepo.Should()
                .NotBeEmpty()
                .And.HaveCount(2);

                ShoppingListItemRepo.Should().ContainEquivalentOf(fakeShoppingListItemOne);
                ShoppingListItemRepo.Should().ContainEquivalentOf(fakeShoppingListItemTwo);

                context.Database.EnsureDeleted();
            }
        }
        public async Task GetShoppingListItems_ReturnsSuccessCodeAndResourceWithAccurateFields()
        {
            var fakeShoppingListItemOne = new FakeShoppingListItem {
            }.Generate();
            var fakeShoppingListItemTwo = new FakeShoppingListItem {
            }.Generate();

            var appFactory = _factory;

            using (var scope = appFactory.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <CarbonKitchenDbContext>();
                context.Database.EnsureCreated();

                context.ShoppingListItems.RemoveRange(context.ShoppingListItems);
                context.ShoppingListItems.AddRange(fakeShoppingListItemOne, fakeShoppingListItemTwo);
                context.SaveChanges();
            }

            var client     = appFactory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            var result     = await client.GetAsync($"api/v1/ShoppingListItems")
                             .ConfigureAwait(false);

            var responseContent = await result.Content.ReadAsStringAsync()
                                  .ConfigureAwait(false);

            var response   = JsonConvert.DeserializeObject <IEnumerable <ShoppingListItemDto> >(responseContent);

            // Assert
            result.StatusCode.Should().Be(200);
            response.Should().ContainEquivalentOf(fakeShoppingListItemOne);
            response.Should().ContainEquivalentOf(fakeShoppingListItemTwo);
        }