public async Task DeleteExistingPurchaserTest()
        {
            // arrange
            HAVIdatabaseContext dbContext  = CreateDbContext();
            PurchaserRepository repository = new PurchaserRepository(dbContext);
            Purchaser           purchaser  = new Purchaser()
            {
                Id        = 0,
                ProfileId = 0,
                CountryId = 0,
                Profile   = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };
            Purchaser addedPurchaser = await repository.AddPurchaser(purchaser);

            // act
            Purchaser result = await repository.DeletePurchaserForProfile(addedPurchaser.ProfileId);

            // assert
            Assert.IsTrue(result == addedPurchaser);

            dbContext.Dispose();
        }
        public async Task AddPurchaserToDatabaseTest()
        {
            // arrange
            HAVIdatabaseContext dbContext  = CreateDbContext();
            PurchaserRepository repository = new PurchaserRepository(dbContext);
            Purchaser           purchaser  = new Purchaser()
            {
                Id        = 0,
                ProfileId = 0,
                CountryId = 0,
                Profile   = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };

            // act
            Purchaser result = await repository.AddPurchaser(purchaser);

            // assert
            Assert.IsTrue(result.Id > 0);

            dbContext.Dispose();
        }
        public async Task GetExistingPurchasersFromDatabaseTest()
        {
            // arrange
            HAVIdatabaseContext dbContext  = CreateDbContext();
            PurchaserRepository repository = new PurchaserRepository(dbContext);
            Purchaser           purchaser1 = new Purchaser()
            {
                Id        = 0,
                ProfileId = 0,
                CountryId = 0,
                Profile   = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };
            Purchaser purchaser2 = new Purchaser()
            {
                Id        = 0,
                ProfileId = 0,
                CountryId = 0,
                Profile   = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };
            Purchaser addedPurchaser1 = await repository.AddPurchaser(purchaser1);

            Purchaser addedPurchaser2 = await repository.AddPurchaser(purchaser2);

            // act
            List <Purchaser> result = (List <Purchaser>) await repository.GetPurchasers();

            // assert
            Assert.IsTrue(result.Count == 2);
            Assert.IsTrue(result.Contains(addedPurchaser1));
            Assert.IsTrue(result.Contains(addedPurchaser2));

            dbContext.Dispose();
        }
Beispiel #4
0
        public async Task <ActionResult <Purchaser> > CreatePurchaser(Purchaser purchaser)
        {
            try
            {
                if (purchaser == null)
                {
                    return(BadRequest());
                }

                var createdPurchaser = await _purchaserRepository.AddPurchaser(purchaser);

                return(createdPurchaser);
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database."));
            }
        }
        public async Task GetExistingArticlesForPurchaserFromDatabaseTest()
        {
            // arrange
            HAVIdatabaseContext dbContext           = CreateDbContext();
            PurchaserRepository purchaserRepository = new PurchaserRepository(dbContext);
            Purchaser           purchaser           = new Purchaser()
            {
                Id        = 0,
                ProfileId = 0,
                CountryId = 0,
                Profile   = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };
            ArticleRepository repository = new ArticleRepository(dbContext);
            Article           article1   = new Article()
            {
                Id                                  = 0,
                PurchaserId                         = 1,
                CountryId                           = 0,
                SupplierId                          = 0,
                ArticleInformationId                = 0,
                InternalArticleInformationId        = 0,
                VailedForCustomer                   = "Customer",
                DateCreated                         = DateTime.Now,
                ArticleInformationCompleted         = 0,
                InternalArticalInformationCompleted = 0,
                ArticleState                        = 0,
                ErrorReported                       = 0,
                ErrorField                          = "Field",
                ErrorMessage                        = "Message",
                ErrorOwner                          = "Owner",
                ArticleInformation                  = new ArticleInformation(),
                InternalArticleInformation          = new InternalArticleInformation()
            };
            Article article2 = new Article()
            {
                Id                                  = 0,
                PurchaserId                         = 1,
                CountryId                           = 0,
                SupplierId                          = 0,
                ArticleInformationId                = 0,
                InternalArticleInformationId        = 0,
                VailedForCustomer                   = "Customer",
                DateCreated                         = DateTime.Now,
                ArticleInformationCompleted         = 0,
                InternalArticalInformationCompleted = 0,
                ArticleState                        = 0,
                ErrorReported                       = 0,
                ErrorField                          = "Field",
                ErrorMessage                        = "Message",
                ErrorOwner                          = "Owner",
                ArticleInformation                  = new ArticleInformation(),
                InternalArticleInformation          = new InternalArticleInformation()
            };
            await purchaserRepository.AddPurchaser(purchaser);

            Article addedArticle1 = await repository.AddArticle(article1);

            Article addedArticle2 = await repository.AddArticle(article2);

            // act
            List <Article> result = (List <Article>) await repository.GetArticlesForPurchaser(1);

            // assert
            Assert.IsTrue(result.Count == 2);
            Assert.IsTrue(result.Contains(addedArticle1));
            Assert.IsTrue(result.Contains(addedArticle2));

            dbContext.Dispose();
        }