コード例 #1
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ILinkTypeRepository>();
            var model = new ApiLinkTypeRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new LinkTypeService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.LinkTypeModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLLinkTypeMapperMock,
                                              mock.DALMapperMockFactory.DALLinkTypeMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.LinkTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
コード例 #2
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <ILinkTypeService, ILinkTypeRepository>();
            var model = new ApiLinkTypeServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new LinkTypeService(mock.LoggerMock.Object,
                                              mock.MediatorMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.LinkTypeModelValidatorMock.Object,
                                              mock.DALMapperMockFactory.DALLinkTypeMapperMock,
                                              mock.DALMapperMockFactory.DALPostLinkMapperMock);

            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.LinkTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <LinkTypeDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
コード例 #3
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ILinkTypeService, ILinkTypeRepository>();
            var model         = new ApiLinkTypeServerRequestModel();
            var validatorMock = new Mock <IApiLinkTypeServerRequestModelValidator>();

            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 LinkTypeService(mock.LoggerMock.Object,
                                              mock.MediatorMock.Object,
                                              mock.RepositoryMock.Object,
                                              validatorMock.Object,
                                              mock.DALMapperMockFactory.DALLinkTypeMapperMock,
                                              mock.DALMapperMockFactory.DALPostLinkMapperMock);

            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 <LinkTypeDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }