protected void GvShowCountry_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string countryID = GvShowCountry.DataKeys[e.RowIndex].Value.ToString();

            var region = new Region();

            region.CountryId = Convert.ToInt32(countryID);
            var regionService = new RegionService();
            int count         = regionService.ExperimentalRegionCount(region);

            if (count <= 0)
            {
                var country = new Country();
                country.Id = Convert.ToInt32(countryID);

                var countryService = new CountryService();
                countryService.DeleteCountry(country);

                Response.Write("<script>alert('删除成功')</script>");
            }
            else
            {
                Response.Write("<script>alert('此国家里面包括地区,不能删除')</script>");
            }
            //GvShowCountry.EditIndex = -1;//return to original state
            Bind();
        }
Example #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);
        }
Example #3
0
 protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "DeleteCountry")
     {
         CountryService.DeleteCountry(Convert.ToInt32(e.CommandArgument));
     }
     if (e.CommandName == "AddCountry")
     {
         GridViewRow footer = grid.FooterRow;
         if (
             string.IsNullOrEmpty(((TextBox)footer.FindControl("txtNewName")).Text) ||
             string.IsNullOrEmpty(((TextBox)footer.FindControl("txtNewISO2")).Text) ||
             string.IsNullOrEmpty(((TextBox)footer.FindControl("txtNewISO3")).Text)
             )
         {
             grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ffcccc");
             return;
         }
         var country = new Country
         {
             Name = ((TextBox)footer.FindControl("txtNewName")).Text,
             Iso2 = ((TextBox)footer.FindControl("txtNewISO2")).Text,
             Iso3 = ((TextBox)footer.FindControl("txtNewISO3")).Text
         };
         CountryService.InsertCountry(country);
         grid.ShowFooter = false;
     }
     if (e.CommandName == "CancelAdd")
     {
         grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ccffcc");
         grid.ShowFooter            = false;
     }
 }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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);
        }
Example #8
0
        public void DeleteCountryById_Success_Test()
        {
            // Arrange
            int id = 1;

            // create mock for repository
            var mock = new Mock <ICountryRepository>();

            mock.Setup(s => s.DeleteCountry(Moq.It.IsAny <int>())).Verifiable();

            // service
            CountryService countryService = new CountryService();

            CountryService.Repository = mock.Object;

            // Act
            countryService.DeleteCountry(id);

            // Assert
            Assert.IsTrue(true);
        }
Example #9
0
        public void DeleteCountryTest()
        {
            //Arrange
            var countryId = -1;
            var country   = new Country();

            countryRepositoryMock.Setup(x => x.GetById(countryId))
            .Returns(country)
            .Verifiable("should check in repository via GetById");
            countryRepositoryMock.Setup(x => x.Delete(country))
            .Verifiable("should call delete");
            unitOfWorkMock.Setup(x => x.Save())
            .Verifiable("should save after deleting");

            //Act
            var deletedCountry = countryService.DeleteCountry(countryId);

            //Assert
            Assert.IsNotNull(deletedCountry);
            unitOfWorkMock.Verify();
            countryRepositoryMock.Verify();
        }
Example #10
0
 protected void lbDeleteSelected_Click(object sender, EventArgs e)
 {
     if ((_selectionFilter != null) && (_selectionFilter.Values != null))
     {
         if (!_inverseSelection)
         {
             foreach (var id in _selectionFilter.Values)
             {
                 CountryService.DeleteCountry(Convert.ToInt32(id));
             }
         }
         else
         {
             var itemsIds = _paging.ItemsIds <int>("CountryID as ID");
             //  List<int> ids = CountryService.GetAllCountryID();
             foreach (int id in itemsIds.Where(id => !_selectionFilter.Values.Contains(id.ToString(CultureInfo.InvariantCulture))))
             {
                 CountryService.DeleteCountry(id);
             }
         }
     }
 }
Example #11
0
        public void DeleteCountry_Success_Test()
        {
            // Arrange
            CountryDTO dto = SampleCountryDTO(1);

            dto.IsDeleted = false;

            // create mock for repository
            var mock = new Mock <ICountryRepository>();

            mock.Setup(s => s.DeleteCountry(Moq.It.IsAny <R_Country>())).Verifiable();

            // service
            CountryService countryService = new CountryService();

            CountryService.Repository = mock.Object;

            // Act
            countryService.DeleteCountry(dto);

            // Assert
            Assert.IsTrue(true);
        }
Example #12
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();
        }