Example #1
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IClaspRepository>();
            var model = new ApiClaspRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Clasp>())).Returns(Task.FromResult(new Clasp()));
            var service = new ClaspService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ClaspModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLClaspMapperMock,
                                           mock.DALMapperMockFactory.DALClaspMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ClaspModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiClaspRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Clasp>()));
        }
Example #2
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IClaspService, IClaspRepository>();

            var model = new ApiClaspServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Clasp>())).Returns(Task.FromResult(new Clasp()));
            var service = new ClaspService(mock.LoggerMock.Object,
                                           mock.MediatorMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ClaspModelValidatorMock.Object,
                                           mock.DALMapperMockFactory.DALClaspMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.ClaspModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiClaspServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Clasp>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <ClaspCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Example #3
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IClaspService, IClaspRepository>();
            var model         = new ApiClaspServerRequestModel();
            var validatorMock = new Mock <IApiClaspServerRequestModelValidator>();

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

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

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