public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ITestAllFieldTypesNullableService, ITestAllFieldTypesNullableRepository>();
            var model         = new ApiTestAllFieldTypesNullableServerRequestModel();
            var validatorMock = new Mock <IApiTestAllFieldTypesNullableServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiTestAllFieldTypesNullableServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new TestAllFieldTypesNullableService(mock.LoggerMock.Object,
                                                               mock.MediatorMock.Object,
                                                               mock.RepositoryMock.Object,
                                                               validatorMock.Object,
                                                               mock.DALMapperMockFactory.DALTestAllFieldTypesNullableMapperMock);

            CreateResponse <ApiTestAllFieldTypesNullableServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTestAllFieldTypesNullableServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TestAllFieldTypesNullableCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Ejemplo n.º 2
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ISelfReferenceService, ISelfReferenceRepository>();
            var model         = new ApiSelfReferenceServerRequestModel();
            var validatorMock = new Mock <IApiSelfReferenceServerRequestModelValidator>();

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

            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 <SelfReferenceDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Ejemplo n.º 3
0
        public async void Update_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IColumnSameAsFKTableService, IColumnSameAsFKTableRepository>();
            var model         = new ApiColumnSameAsFKTableServerRequestModel();
            var validatorMock = new Mock <IApiColumnSameAsFKTableServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiColumnSameAsFKTableServerRequestModel>())).Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new ColumnSameAsFKTable()));
            var service = new ColumnSameAsFKTableService(mock.LoggerMock.Object,
                                                         mock.MediatorMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         validatorMock.Object,
                                                         mock.DALMapperMockFactory.DALColumnSameAsFKTableMapperMock);

            UpdateResponse <ApiColumnSameAsFKTableServerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiColumnSameAsFKTableServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <ColumnSameAsFKTableUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }