示例#1
0
        public async Task UpdateCountryReturnsBadResutIfCountryAndIdDoNotMatch()
        {
            // arrange
            CountryService countryService = new CountryService(_client);
            Country        country        = new Country()
            {
                Id          = 0,
                ProfileId   = 0,
                CountryCode = "Code",
                CountryName = "Name",
                Profile     = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 0
                }
            };

            Country createCountry = await countryService.CreateCountry(country);

            // act
            var result = await _client.PutAsJsonAsync($"/api/countries/{2}", createCountry);

            // assert
            Assert.IsTrue(result.StatusCode == HttpStatusCode.BadRequest);
        }
示例#2
0
        public async Task UpdateCountryUpdatesExistingCountry()
        {
            // arrange
            CountryService countryService = new CountryService(_client);
            Country        country        = new Country()
            {
                Id          = 0,
                ProfileId   = 0,
                CountryCode = "Code",
                CountryName = "Name",
                Profile     = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 0
                }
            };

            Country expected = await countryService.CreateCountry(country);

            expected.CountryName = "TestName";

            await countryService.UpdateCountry(expected.Id, expected);

            // act
            Country actual = await countryService.GetCountry(expected.Id);

            List <Country> list = await countryService.GetCountries();

            // assert
            Assert.IsTrue(expected.CountryName == actual.CountryName);

            await countryService.DeleteCountry(expected.Id);
        }
示例#3
0
        public async Task GetCountriesIfCountryExists()
        {
            // arrange
            CountryService countryService = new CountryService(_client);
            Country        country        = new Country()
            {
                Id          = 0,
                ProfileId   = 0,
                CountryCode = "Code",
                CountryName = "Name",
                Profile     = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 0
                }
            };

            int     expected = 1;
            Country toDelete = await countryService.CreateCountry(country);

            List <Country> actual = await countryService.GetCountries();

            // assert
            Assert.IsTrue(actual.Count == expected);

            await countryService.DeleteCountry(toDelete.Id);
        }
示例#4
0
        public async Task DeletePurchaserForProfileDeletesThePurchaserIfItExists()
        {
            // arrange
            PurchaserService purchaserService = new PurchaserService(_client);
            CountryService   countryService   = new CountryService(_client);

            Purchaser purchaser = new Purchaser()
            {
                Id        = 0,
                ProfileId = 0,
                CountryId = 1,
                Profile   = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };

            Country country = new Country()
            {
                Id          = 0,
                ProfileId   = 0,
                CountryName = "Name",
                CountryCode = "Code",
                Profile     = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 0
                }
            };

            Country createdCountry = await countryService.CreateCountry(country);

            Purchaser createdPurchaser = await purchaserService.CreatePurchaser(purchaser);

            await purchaserService.DeletePurchaserForProfile(createdPurchaser.ProfileId);

            // act
            Purchaser expected = new Purchaser();
            Purchaser actual   = await purchaserService.GetPurchaser(createdPurchaser.ProfileId);

            // assert
            CollectionAssert.AreEquivalent(expected.Articles, actual.Articles);
            Assert.IsTrue(expected.Id == actual.Id);
            Assert.IsTrue(expected.CountryId == actual.CountryId);
            Assert.IsTrue(expected.ProfileId == actual.ProfileId);

            await countryService.DeleteCountry(createdCountry.Id);
        }
示例#5
0
        public async Task GetPurchasersForCountryReturnsPurchaserIfItExists()
        {
            // arrange
            PurchaserService purchaserService = new PurchaserService(_client);
            CountryService   countryService   = new CountryService(_client);

            Purchaser purchaser = new Purchaser()
            {
                Id        = 0,
                ProfileId = 0,
                CountryId = 1,
                Profile   = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };

            Country country = new Country()
            {
                Id          = 0,
                ProfileId   = 0,
                CountryName = "Name",
                CountryCode = "Code",
                Profile     = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 0
                }
            };

            Country toDeleteCountry = await countryService.CreateCountry(country);

            Purchaser toDeletePurchaser = await purchaserService.CreatePurchaser(purchaser);

            int expected = 1;

            // act
            List <Purchaser> actual = await purchaserService.GetPurchasersForCountry(1);

            // assert
            Assert.IsTrue(actual.Count == expected);

            await purchaserService.DeletePurchaserForProfile(toDeletePurchaser.ProfileId);

            await countryService.DeleteCountry(toDeleteCountry.Id);
        }
示例#6
0
        public async Task GetCountryGetsExistingCountry()
        {
            // arrange
            CountryService countryService = new CountryService(_client);
            Country        country        = new Country()
            {
                Id          = 0,
                ProfileId   = 0,
                CountryCode = "Code",
                CountryName = "Name",
                Profile     = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 0
                }
            };

            Country expected = await countryService.CreateCountry(country);

            // act
            Country actual = await countryService.GetCountry(expected.Id);


            // assert
            Assert.IsTrue(expected.CountryCode == actual.CountryCode);
            Assert.IsTrue(expected.CountryName == actual.CountryName);
            CollectionAssert.AreEquivalent(expected.Articles, actual.Articles);
            Assert.IsTrue(expected.Id == actual.Id);
            Assert.IsTrue(expected.Profile.Id == actual.Profile.Id);
            Assert.IsTrue(expected.Profile.Password == actual.Profile.Password);
            CollectionAssert.AreEquivalent(expected.Profile.Purchasers, actual.Profile.Purchasers);
            Assert.IsTrue(expected.Profile.Username == actual.Profile.Username);
            CollectionAssert.AreEquivalent(expected.Profile.Suppliers, actual.Profile.Suppliers);
            Assert.IsTrue(expected.Profile.Usertype == actual.Profile.Usertype);
            CollectionAssert.AreEquivalent(expected.Profile.Countries, actual.Profile.Countries);
            Assert.IsTrue(expected.ProfileId == actual.ProfileId);
            CollectionAssert.AreEquivalent(expected.CompanyCodes, actual.CompanyCodes);
            CollectionAssert.AreEquivalent(expected.Iloscategories, actual.Iloscategories);
            CollectionAssert.AreEquivalent(expected.Ilosorderpickgroups, actual.Ilosorderpickgroups);
            CollectionAssert.AreEquivalent(expected.InformCostTypes, actual.InformCostTypes);
            CollectionAssert.AreEquivalent(expected.PrimaryDciloscodes, actual.PrimaryDciloscodes);
            CollectionAssert.AreEquivalent(expected.Purchasers, actual.Purchasers);
            CollectionAssert.AreEquivalent(expected.SupplierDeliveryUnits, actual.SupplierDeliveryUnits);
            CollectionAssert.AreEquivalent(expected.VailedForCustomers, actual.VailedForCustomers);
            CollectionAssert.AreEquivalent(expected.VatTaxCodes, actual.VatTaxCodes);

            await countryService.DeleteCountry(expected.Id);
        }
        public void CreateCountry_Correct()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(CreateCountry_Correct));
            var country = new Country
            {
                Id   = 11,
                Name = "Bulgaria"
            };

            //Act & Assert
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut        = new CountryService(assertContext);
                var countryDTO = new CountryDTO(country.Id, country.Name);
                var result     = sut.CreateCountry(countryDTO);

                Assert.AreEqual(country.Id, result.Id);
                Assert.AreEqual(country.Name, result.Name);
            }
        }
示例#8
0
        public async Task UpdateArticleUpdateTheGivenArticle()
        {
            // arrange
            ArticleService   articleService   = new ArticleService(_client);
            PurchaserService purchaserService = new PurchaserService(_client);
            CountryService   countryService   = new CountryService(_client);
            SupplierService  supplierService  = new SupplierService(_client);

            Article article = new Article()
            {
                Id                                  = 0,
                PurchaserId                         = 1,
                CountryId                           = 1,
                SupplierId                          = 1,
                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()
            };

            Country country = new Country()
            {
                Id          = 0,
                ProfileId   = 0,
                CountryName = "Name",
                CountryCode = "Code",
                Profile     = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 0
                }
            };

            Purchaser purchaser = new Purchaser()
            {
                Id        = 0,
                ProfileId = 0,
                CountryId = 1,
                Profile   = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };

            Supplier supplier = new Supplier()
            {
                Id                    = 0,
                ProfileId             = 0,
                CompanyName           = "Name",
                CompanyLocation       = "Location",
                FreightResponsibility = "EXW",
                PalletExchange        = 1,
                Profile               = new Profile()
                {
                    Id       = 0,
                    Username = "******",
                    Password = "******",
                    Usertype = 2
                }
            };

            Country countryToDelete = await countryService.CreateCountry(country);

            purchaser.CountryId = countryToDelete.Id;
            Purchaser purchaserToDelete = await purchaserService.CreatePurchaser(purchaser);

            Supplier supplierToDelete = await supplierService.CreateSupplier(supplier);

            article.CountryId   = countryToDelete.Id;
            article.SupplierId  = supplierToDelete.Id;
            article.PurchaserId = purchaserToDelete.Id;
            Article expected = await articleService.CreateArticle(article);

            expected.ArticleState = 3;

            // act
            await articleService.UpdateArticle(expected.Id, expected);

            Article actual = await articleService.GetArticle(expected.Id);

            // assert
            Assert.IsTrue(expected.ArticleState == actual.ArticleState);
            List <Country> now = await countryService.GetCountries();

            await articleService.DeleteArticle(expected.Id);

            await purchaserService.DeletePurchaserForProfile(purchaserToDelete.ProfileId);

            await supplierService.DeleteSupplier(supplierToDelete.Id);

            await countryService.DeleteCountry(countryToDelete.Id);

            await _context.DisposeAsync();

            List <Country> late = await countryService.GetCountries();
        }