Exemplo n.º 1
0
        public async Task UpdateTest()
        {
            using (var myContext = CreateMagasinDbContext())
            {
                var repo    = new ArticleEFRepository(myContext);
                var article = new Article
                {
                    Id          = 1,
                    Libelle     = "Chargeur",
                    SKU         = "785625",
                    DateSortie  = DateTime.Now,
                    PrixInitial = 129,
                    Poids       = 76
                };

                repo.Update(article);
                await repo.Save();
            }
            using (var myContext = CreateMagasinDbContext())
            {
                var repo     = new ArticleEFRepository(myContext);
                var elements = await repo.GetAll();

                elements.Should().HaveCount(4);
                elements.Any(e => e.Id == 1).Should().BeTrue();
                elements.Any(e => e.Libelle == "Chargeur").Should().BeTrue();
                elements.Any(e => e.Libelle == "Tablette").Should().BeFalse();
            }
        }
Exemplo n.º 2
0
        public void ExistsTest()
        {
            using var myContext = CreateMagasinDbContext();
            var repo   = new ArticleEFRepository(myContext);
            var exists = repo.Exists(1);

            exists.Should().BeTrue();
        }
Exemplo n.º 3
0
        public async Task GetAllTest()
        {
            using var myContext = CreateMagasinDbContext();
            var repo        = new ArticleEFRepository(myContext);
            var allArticles = await repo.GetAll();

            allArticles.Should().HaveCount(4);
        }
Exemplo n.º 4
0
        public void GetAveragePriceBySecteurTest()
        {
            using var myContext = CreateMagasinDbContext();
            var repo    = new ArticleEFRepository(myContext);
            var average = repo.GetAveragePriceBySecteur(1);

            average.Should().Be(399);
        }
Exemplo n.º 5
0
        public void GetAllBySecteurTest()
        {
            using var myContext = CreateMagasinDbContext();
            var repo        = new ArticleEFRepository(myContext);
            var allArticles = repo.GetAllBySecteur(1);

            allArticles.Should().HaveCount(2);
        }
Exemplo n.º 6
0
        public async Task FindByIdTest()
        {
            using var myContext = CreateMagasinDbContext();
            var repo    = new ArticleEFRepository(myContext);
            var article = await repo.FindById(3);

            article.Libelle.Should().Be("PC");
            article.Id.Should().Be(3);
        }
Exemplo n.º 7
0
        public async Task RemoveTest()
        {
            using (var myContext = CreateMagasinDbContext())
            {
                var repo    = new ArticleEFRepository(myContext);
                var article = await repo.FindById(4);

                repo.Remove(article);
                await repo.Save();
            }
            using (var myContext = CreateMagasinDbContext())
            {
                var repo     = new ArticleEFRepository(myContext);
                var elements = await repo.GetAll();

                elements.Should().HaveCount(3);
                elements.Any(e => e.Id == 4).Should().BeFalse();
            }
        }
Exemplo n.º 8
0
        public async Task InsertTest()
        {
            using (var myContext = CreateMagasinDbContext())
            {
                var repo       = new ArticleEFRepository(myContext);
                var newArticle = new Article
                {
                    Id              = 5,
                    Libelle         = "Clavier",
                    SKU             = "854765",
                    DateSortie      = DateTime.Now,
                    PrixInitial     = 249,
                    Poids           = 250,
                    PositionMagasin = new List <PositionsMagasin>
                    {
                        new PositionsMagasin {
                            ArticleId = 5, EtagereId = 2, Quantite = 10
                        },
                        new PositionsMagasin {
                            ArticleId = 5, EtagereId = 1, Quantite = 42
                        }
                    }
                };

                repo.Insert(newArticle);
                await(repo.Save());
            }
            using (var myContext = CreateMagasinDbContext())
            {
                var repo     = new ArticleEFRepository(myContext);
                var elements = await repo.GetAll();

                elements.Should().HaveCount(5);
                elements.Any(e => e.Id == 5).Should().BeTrue();
                elements.Any(e => e.Libelle == "Clavier").Should().BeTrue();
            }
        }