示例#1
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ICountryService, ICountryRepository>();
            var model         = new ApiCountryServerRequestModel();
            var validatorMock = new Mock <IApiCountryServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new CountryService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             validatorMock.Object,
                                             mock.DALMapperMockFactory.DALCountryMapperMock,
                                             mock.DALMapperMockFactory.DALCountryRequirementMapperMock,
                                             mock.DALMapperMockFactory.DALDestinationMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <CountryDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
示例#2
0
        public void CallRepositoriesDeleteMethodWithCorrectCountryModel_WhenCountryWithPassedNameIsFound()
        {
            // arrange
            var repository = new Mock <IEfRepository <Country> >();

            var country = new Country()
            {
                Name = "presentName"
            };
            var countries = new List <Country>()
            {
                country
            }.AsQueryable();

            repository.Setup(r => r.All).Returns(countries);
            repository.Setup(r => r.Delete(It.Is <Country>(c => c == country)));

            var countryService = new CountryService(repository.Object);

            // act
            var returnedResult = countryService.Delete("presentName");

            // assert
            repository.Verify(r => r.Delete(It.Is <Country>(c => c == country)), Times.Once);
        }
示例#3
0
        public ActionResult Delete(int id, FormCollection data)
        {
            Country country = _CountryService.GetById(id);

            _CountryService.Delete(country);
            return(RedirectToAction("Index"));
        }
示例#4
0
        private static void DeleteCountry(BancoContext context, CountryService service)
        {
            Country country = FindCountry(context, service);

            service.Delete(country);
            Paused();
        }
示例#5
0
 public ActionResult Delete(int id)
 {
     _CountryService.Delete(new Country {
         Id = id
     });
     return(RedirectToAction("Index"));
 }
示例#6
0
        public ActionResult OnDelete(int id)
        {
            var result = CountryService.Delete(id);

            SetFlashMessage(result == Result.Ok ? "Xóa Quốc gia thành công." : "Quốc gia không tồn tại trên hệ thống.");
            return(RedirectToAction("Index"));
        }
        public CountriesControllerTests()
        {
            var list = new List <Country>
            {
                new Country {
                    Id = 1, Name = "test 1"
                },
                new Country {
                    Id = 2, Name = "test 2"
                }
            }.AsQueryable();

            var mockContext                   = Substitute.For <TtContext>();
            var countryRepository             = Substitute.For <Repository <Country> >(mockContext);
            var organizationCountryRepository = Substitute.For <Repository <OrganizationCountry> >(mockContext);
            var organizationRepository        = Substitute.For <Repository <Organization> >(mockContext);

            _service = Substitute.For <CountryService>(countryRepository, organizationCountryRepository, organizationRepository);
            _service.GetList().Returns(list);
            _service.GetItem(Arg.Any <int>()).Returns(new Country {
                Id = 1, Name = "test 1"
            });
            _service.Create(Arg.Any <Country>());
            _service.Update(Arg.Any <int>(), Arg.Any <Country>());
            _service.Delete(Arg.Any <int>());

            var mockLogger = Substitute.For <ILoggerFactory>();

            _controller = new CountriesController(_service, mockLogger);
        }
示例#8
0
        public void ReturnTrue_WhenCountryWithPassedNameIsFoundAndDeleted()
        {
            // arrange
            var repository = new Mock <IEfRepository <Country> >();

            var country = new Country()
            {
                Name = "presentName"
            };
            var countries = new List <Country>()
            {
                country
            }.AsQueryable();

            repository.Setup(r => r.All).Returns(countries);
            repository.Setup(r => r.Delete(It.Is <Country>(c => c == country)));

            var countryService = new CountryService(repository.Object);

            // act
            var returnedResult = countryService.Delete("presentName");

            // assert
            Assert.IsTrue(returnedResult);
        }
示例#9
0
        public ActionResult Delete(CountryRowModel[] model)
        {
            foreach (var item in model)
            {
                var obj = _countryService.Find(item.Id);
                _countryService.Delete(obj);
            }

            return(AjaxForm().ReloadPage());
        }
        public ActionResult Delete(CountryActionModel model)
        {
            Country    objectFirst = service.GetByID(model.ID);
            bool       result      = service.Delete(objectFirst);
            JsonResult jsonResult  = new JsonResult
            {
                Data = result ? (new { Success = true, Msg = "" }) : (new { Success = false, Msg = "Unable to Save Department" }),
            };

            return(jsonResult);
        }
 public bool Delete(int id)
 {
     try
     {
         _service.Delete(id);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#12
0
        private async Task Delete(long countryId)
        {
            var deleteModal  = ModalService.Show <DeleteModal>("Confirm delete operation");
            var deleteResult = await deleteModal.Result;

            if (!deleteResult.Cancelled)
            {
                await CountryService.Delete(countryId.ToString());

                Countries.Remove(Countries.First(country => country.Id.Equals(countryId)));
            }
        }
        public void CountryService_Delete_ShouldRemoveCountryFromSession()
        {
            var country = new Country {
                Name = "UK", ISOTwoLetterCode = "GB"
            };

            Session.Transact(session => session.Save(country));

            _countryService.Delete(country);
            Session.Evict(country);

            Session.QueryOver <Country>().RowCount().Should().Be(0);
        }
        public ActionResult Delete(Genre genre)
        {
            if (genre.Id.HasValue)
            {
                var wasDeleted = _countryService.Delete(genre.Id.Value);

                if (!wasDeleted)
                {
                    return(View("Message", model: $"Country: {genre.Name} can not be deleted due to active relations."));
                }
            }

            return(RedirectToAction("Index"));
        }
示例#15
0
        public void ReturnFalse_WhenCountryWithThePassedNameIsNotPresentInRepository()
        {
            // arrange
            var repository = new Mock <IEfRepository <Country> >();
            var countries  = new List <Country>().AsQueryable();

            repository.Setup(r => r.All).Returns(countries);

            var countryService = new CountryService(repository.Object);

            // act
            var returnedResult = countryService.Delete("notPresentName");

            // assert
            Assert.IsFalse(returnedResult);
        }
示例#16
0
        public void TestDelete(bool isInUse)
        {
            Mock <ICountryDao> countryDaoMock = new Mock <ICountryDao>();

            countryDaoMock.Setup(x => x.IsInUse(It.IsAny <Country>())).Returns(isInUse);
            countryDaoMock.Setup(x => x.Delete(It.IsAny <Country>()));

            Country country = new Country();

            ICountryService countryService = new CountryService(countryDaoMock.Object);

            countryService.Delete(country);

            countryDaoMock.Verify(x => x.IsInUse(country), Times.Once);
            countryDaoMock.Verify(x => x.Delete(country), Times.Once);
        }
示例#17
0
        public void TestDelete()
        {
            this.TestAdd();

            ConfigurationHelper.Ensure();
            var service = new CountryService();

            var countBefore = service.GetAll().Count();

            var maxId = service.GetAll().Max(i => i.Id);

            service.Delete(maxId);

            var countAfter = service.GetAll().Count();

            Assert.Equal(countBefore, countAfter + 1);
        }
示例#18
0
        public void Delete_IdNonExisting_ReturnsNull()
        {
            //Arrange
            int     nonExistingId = 12;
            Country expected      = null;

            Mock <ICountryRepository> countryRepository = new Mock <ICountryRepository>();

            countryRepository.Setup(repo => repo.Delete(nonExistingId)).
            Returns(expected);

            ICountryService countryService = new CountryService(countryRepository.Object);

            //Act
            Country actual = countryService.Delete(nonExistingId);

            //Assert
            Assert.Equal(expected, actual);
        }
示例#19
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ICountryRepository>();
            var model = new ApiCountryRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new CountryService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.CountryModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLCountryMapperMock,
                                             mock.DALMapperMockFactory.DALCountryMapperMock,
                                             mock.BOLMapperMockFactory.BOLProvinceMapperMock,
                                             mock.DALMapperMockFactory.DALProvinceMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.CountryModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
示例#20
0
 protected void lbDeleteSelected_Click(object sender, EventArgs e)
 {
     if ((_selectionFilter != null) && (_selectionFilter.Values != null))
     {
         if (!_inverseSelection)
         {
             foreach (var id in _selectionFilter.Values)
             {
                 CountryService.Delete(SQLDataHelper.GetInt(id));
             }
         }
         else
         {
             foreach (var id in _paging.ItemsIds <int>("CountryID as ID").Where(id => !_selectionFilter.Values.Contains(id.ToString(CultureInfo.InvariantCulture))))
             {
                 CountryService.Delete(id);
             }
         }
     }
 }
示例#21
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <ICountryService, ICountryRepository>();
            var model = new ApiCountryServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new CountryService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.CountryModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALCountryMapperMock,
                                             mock.DALMapperMockFactory.DALProvinceMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.CountryModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <CountryDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
示例#22
0
        public void Delete_IdExisting_ReturnsDeletedCountryWithSpecifiedId()
        {
            //Arrange
            int     existingId = 12;
            Country expected   = new Country {
                Id = existingId, Name = "Denmark"
            };

            Mock <ICountryRepository> countryRepository = new Mock <ICountryRepository>();

            countryRepository.Setup(repo => repo.Delete(existingId)).
            Returns(expected);

            ICountryService countryService = new CountryService(countryRepository.Object);

            //Act
            Country actual = countryService.Delete(existingId);

            //Assert
            Assert.Equal(expected, actual);
        }
示例#23
0
        protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DeleteCountry")
            {
                CountryService.Delete(SQLDataHelper.GetInt(e.CommandArgument));
            }

            if (e.CommandName == "AddCountry")
            {
                var 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;
                }

                CountryService.Add(new Country
                {
                    Name           = ((TextBox)footer.FindControl("txtNewName")).Text,
                    Iso2           = ((TextBox)footer.FindControl("txtNewISO2")).Text,
                    Iso3           = ((TextBox)footer.FindControl("txtNewISO3")).Text,
                    DisplayInPopup = ((CheckBox)footer.FindControl("chkNewDisplayInPopup")).Checked,
                    SortOrder      = ((TextBox)footer.FindControl("txtNewSortOrder")).Text.TryParseInt()
                });

                grid.ShowFooter = false;
            }
            if (e.CommandName == "CancelAdd")
            {
                grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ccffcc");
                grid.ShowFooter            = false;
            }
        }
示例#24
0
 public JsonResult <ResponseBase <TBL_SLI_COUNTRY> > Delete(int ID)
 {
     return(Json(service.Delete(ID)));
 }
示例#25
0
        public void Delete_Country()
        {
            service.Delete(country.Id);

            Assert.Empty(context.Set <Country>());
        }
示例#26
0
        void menuCountry(BancoContext context)
        {
            CountryService service = new CountryService(new UnitOfWork(context), new CountryRepository(context));
            char           seguir  = 's';

            do
            {
                System.Console.Clear();
                System.Console.WriteLine("MENU COUNTRY");
                System.Console.WriteLine("1º) Crear Country");
                System.Console.WriteLine("2º) Eliminar Country");
                System.Console.WriteLine("3º) Listar Country");
                System.Console.WriteLine("4º) Regresar");
                System.Console.Write("Seleccione una opción:  ");
                switch (System.Console.Read())
                {
                case '1':
                    System.Console.Clear();
                    System.Console.WriteLine("Crear Country");
                    #region  Crear Country
                    string texto = Microsoft.VisualBasic.Interaction.InputBox(
                        "Texto de la pregunta",
                        "Titulo del diálogo",
                        "Respuesta por defecto");
                    Country country = new Country()
                    {
                        Name = texto
                    };

                    service.Create(country);

                    #endregion
                    System.Console.ReadKey();
                    // Continuar lógica y extraer métodos //
                    break;

                case '2':
                    System.Console.Clear();
                    System.Console.WriteLine("Eliminar Country");
                    #region  Eliminar Country
                    string  nombre = "venezuela";
                    Country coun   = service.Find(nombre);
                    service.Delete(coun);
                    #endregion
                    System.Console.ReadKey();
                    // Continuar lógica y extraer métodos //
                    break;

                case '3':
                    System.Console.Clear();
                    System.Console.WriteLine("Listar Country");
                    #region  Listar Country
                    List <Country> countries = service.GetAll().ToList();
                    foreach (var item in countries)
                    {
                        System.Console.WriteLine(item.Name);
                    }
                    #endregion
                    // Continuar lógica y extraer métodos //
                    System.Console.ReadKey();
                    break;

                case '4':
                    System.Console.Clear();
                    System.Console.WriteLine("Regresando al principal..   ");
                    System.Console.ReadKey();
                    seguir = 'n';
                    break;
                }
            } while (seguir == 's');
        }
示例#27
0
 public void DeleteCountry()
 {
     countryService.Delete(2);
     Assert.AreEqual(1, db.Countries.Count());
 }