public void GetById()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }
                using (var db = new AuctionContext(options))
                {
                    var repository = new AuctionRepository(db);

                    var item = GenerateModel();
                    Assert.DoesNotThrow(() => repository.Save(item));

                    Assert.DoesNotThrow(() => item = repository.GetById(item.Id));
                    Assert.DoesNotThrow(() => repository.Delete(item));
                    Assert.NotNull(item);
                    Assert.Greater(item.Id, 0);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void RemoveLayout()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }

                using (var db = new AuctionContext(options))
                {
                    var repository =
                        new AuctionRepository(db);
                    var item = GenerateModel();
                    Assert.DoesNotThrow(() => repository.Save(item));
                    var layout = new AuctionLayout
                    {
                        Title       = "title",
                        Description = "description",
                        Layout      = GenerateAttachment(),
                        AuctionId   = item.Id
                    };
                    Assert.DoesNotThrow(() => repository.AddLayout(item, layout));
                    Assert.DoesNotThrow(() => repository.RemoveLayout(item, layout));
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void Activate()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }


                using (var db = new AuctionContext(options))
                {
                    var repository = new AuctionRepository(db);
                    var item       = GenerateModel();
                    item.IsActive = false;
                    Assert.DoesNotThrow(() => repository.Save(item));
                    Assert.DoesNotThrow(() => repository.Activate(item));
                    Assert.DoesNotThrow(() => repository.Delete(item));
                    Assert.IsTrue(item.IsActive);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void GetAuctionCategories()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }

                using (var db = new AuctionContext(options))
                {
                    var repository =
                        new AuctionRepository(db);

                    var item = GenerateModel();
                    Assert.DoesNotThrow(() => repository.Save(item));
                    Assert.DoesNotThrow(() => repository.AddCategory(item, new Category
                    {
                        Id = 1
                    }));
                    IEnumerable <Category> result = null;
                    Assert.DoesNotThrow(() => result = repository.GetAuctionCategories(item.Id));
                    Assert.True(result != null && result.Any());
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void RemoveCategory()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }

                using (var db = new AuctionContext(options))
                {
                    var repository =
                        new AuctionRepository(db);

                    var item = GenerateModel();
                    Assert.DoesNotThrow(() => repository.Save(item));
                    Assert.DoesNotThrow(() => repository.AddCategory(item, new Category
                    {
                        Id = 1
                    }));
                    Assert.DoesNotThrow(() => repository.RemoveCategory(item, new Category
                    {
                        Id = 1
                    }));
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void MakeBid()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }

                using (var db = new AuctionContext(options))
                {
                    var repository =
                        new AuctionRepository(db);

                    var item = GenerateModel();

                    Assert.DoesNotThrow(() => repository.Save(item));
                    var user = new User
                    {
                        Id = 1
                    };
                    Assert.DoesNotThrow(() => repository.MakeBid(user, item, 1000));
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void GetAuctionVideos()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    AuctionTestHelper.PopulateDefaultData(db);
                }

                using (var db = new AuctionContext(options))
                {
                    var repository =
                        new AuctionRepository(db);

                    var item = GenerateModel();
                    Assert.DoesNotThrow(() => repository.Save(item));
                    var video = new AuctionVideo
                    {
                        Title       = "title",
                        Description = "description",
                        Video       = GenerateAttachment(),
                        AuctionId   = item.Id
                    };
                    Assert.DoesNotThrow(() => repository.AddVideo(item, video));
                    IEnumerable <AuctionVideo> result = null;
                    Assert.DoesNotThrow(() => result = repository.GetAuctionVideos(item.Id));
                    Assert.True(result != null && result.Any());
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }
        public void GetAuctions()
        {
            try
            {
                var options = CreateNewContextOptions();
                using (var db = new AuctionContext(options))
                {
                    var repository =
                        new AuctionRepository(db);
                    AuctionTestHelper.PopulateDefaultData(db);
                    var item  = GenerateModel();
                    var item2 = GenerateModel();
                    item2.Code = "test2";
                    var item3 = GenerateModel();
                    item3.Code = "test3";
                    var cats = db.Set <Category>().ToList();

                    Assert.DoesNotThrow(() => repository.Save(item));
                    Assert.DoesNotThrow(() => repository.Save(item2));
                    Assert.DoesNotThrow(() => repository.Save(item3));
                    foreach (var category in cats)
                    {
                        Assert.DoesNotThrow(() => repository.AddCategory(item, category));
                    }
                    Assert.DoesNotThrow(() => repository.AddCategory(item2, cats.First()));

                    var user = new User
                    {
                        Id = 1
                    };

                    Assert.DoesNotThrow(() => repository.MakeBid(user, item, 1000));
                    Assert.DoesNotThrow(() => repository.MakeBid(new User
                    {
                        Id = 2
                    }, item, 800));
                    Assert.Throws <InvalidOperationException>(() => repository.MakeBid(user, item, 300));
                }
                using (var db = new AuctionContext(options))
                {
                    var cats   = db.Set <Category>().ToList();
                    var filter = new AuctionFilter
                    {
                        UserId = 1
                    };
                    IEnumerable <odec.Server.Model.Auction.Auction> result = null;
                    var repository =
                        new AuctionRepository(db);
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.UserId = null;
                    filter.InitialPriceInterval = new Interval <decimal?> {
                        Start = 100
                    };
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.InitialPriceInterval.End  = 400;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.InitialPriceInterval.End  = 200;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result == null || !result.Any());
                    filter.InitialPriceInterval      = null;
                    filter.AuctionTypeId             = 1;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.AuctionTypeId             = null;
                    filter.Title                     = "My";
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.Title             = null;
                    filter.StartDateInterval = new Interval <DateTime?> {
                        Start = DateTime.Today.AddDays(-7)
                    };
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.StartDateInterval.End     = DateTime.Today;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.StartDateInterval = null;
                    filter.MaxPriceInterval  = new Interval <decimal?>
                    {
                        Start = 800
                    };
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.MaxPriceInterval.End      = 900;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result == null || !result.Any());
                    filter.MaxPriceInterval.End      = 1000;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.MaxPriceInterval = null;

                    filter.Categories = cats;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any() && result.Count() == 2);
                    filter.Categories                = null;
                    filter.UserId                    = 1;
                    filter.AuctionTypeId             = 1;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.Title = "my";
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.InitialPriceInterval = new Interval <decimal?>
                    {
                        Start = 100
                    };
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.InitialPriceInterval.End  = 400;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.StartDateInterval = new Interval <DateTime?>
                    {
                        Start = DateTime.Today.AddDays(-7)
                    };
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.StartDateInterval.End     = DateTime.Today;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.MaxPriceInterval = new Interval <decimal?> {
                        Start = 800
                    };
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.MaxPriceInterval.End      = 1100;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));
                    Assert.True(result != null && result.Any());
                    filter.Categories = cats;
                    Assert.DoesNotThrow(() => result = repository.Get(filter));

                    Assert.True(result != null && result.Any() && result.Count() == 1);
                    filter = new AuctionFilter
                    {
                        EndDateInterval = new Interval <DateTime?>()
                        {
                            // End = DateTime.Today,
                        },
                        StateId = 1,
                        //AuctionTypeId = (int)AuctionTypes.Crafter,
                        Rows = 1000,
                        InitialPriceInterval   = new Interval <decimal?>(),
                        MaxPriceInterval       = new Interval <decimal?>(),
                        Categories             = new List <Category>(),
                        StartDateInterval      = new Interval <DateTime?>(),
                        AutoClosePriceInterval = new Interval <decimal?>()
                    };
                    Assert.DoesNotThrow(() => result = repository.Get(filter));

                    Assert.True(result != null && result.Any() && result.Count() > 1);
                }
            }
            catch (Exception ex)
            {
                LogEventManager.Logger.Error(ex);
                throw;
            }
        }