コード例 #1
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IFollowerRepository>();
            var model = new ApiFollowerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Follower>())).Returns(Task.FromResult(new Follower()));
            var service = new FollowerService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.FollowerModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLFollowerMapperMock,
                                              mock.DALMapperMockFactory.DALFollowerMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.FollowerModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFollowerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Follower>()));
        }
コード例 #2
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IFollowerService, IFollowerRepository>();

            var model = new ApiFollowerServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Follower>())).Returns(Task.FromResult(new Follower()));
            var service = new FollowerService(mock.LoggerMock.Object,
                                              mock.MediatorMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.FollowerModelValidatorMock.Object,
                                              mock.DALMapperMockFactory.DALFollowerMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.FollowerModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFollowerServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Follower>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <FollowerCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
コード例 #3
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IFollowerService, IFollowerRepository>();
            var model         = new ApiFollowerServerRequestModel();
            var validatorMock = new Mock <IApiFollowerServerRequestModelValidator>();

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

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

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