public async void Delete() { var mock = new ServiceMockFacade <IBadgeRepository>(); var model = new ApiBadgeRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new BadgeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLBadgeMapperMock, mock.DALMapperMockFactory.DALBadgeMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IBadgeService, IBadgeRepository>(); var model = new ApiBadgeServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new BadgeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.BadgeModelValidatorMock.Object, mock.DALMapperMockFactory.DALBadgeMapperMock); 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.BadgeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <BadgeDeletedNotification>(), It.IsAny <CancellationToken>())); }
/// <summary> /// Handles the Delete event of the gBadge control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gBadge_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); var badgeService = new BadgeService(rockContext); var badge = badgeService.Get(e.RowKeyId); if (badge != null) { string errorMessage; if (!badgeService.CanDelete(badge, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } badgeService.Delete(badge); rockContext.SaveChanges(); } BindGrid(); }
public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IBadgeService, IBadgeRepository>(); var model = new ApiBadgeServerRequestModel(); var validatorMock = new Mock <IApiBadgeServerRequestModelValidator>(); 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 BadgeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALBadgeMapperMock); 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 <BadgeDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }