Beispiel #1
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IPenRepository>();
            var model = new ApiPenRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Pen>())).Returns(Task.FromResult(new Pen()));
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PenModelValidatorMock.Object,
                                         mock.BOLMapperMockFactory.BOLPenMapperMock,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.BOLMapperMockFactory.BOLPetMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PenModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPenRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Pen>()));
        }
Beispiel #2
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IPenService, IPenRepository>();

            var model = new ApiPenServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Pen>())).Returns(Task.FromResult(new Pen()));
            var service = new PenService(mock.LoggerMock.Object,
                                         mock.MediatorMock.Object,
                                         mock.RepositoryMock.Object,
                                         mock.ModelValidatorMockFactory.PenModelValidatorMock.Object,
                                         mock.DALMapperMockFactory.DALPenMapperMock,
                                         mock.DALMapperMockFactory.DALPetMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.PenModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPenServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Pen>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PenCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Beispiel #3
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IPenService, IPenRepository>();
            var model         = new ApiPenServerRequestModel();
            var validatorMock = new Mock <IApiPenServerRequestModelValidator>();

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

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPenServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PenCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }