Esempio n. 1
0
        public async void Update_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IPipelineStatusService, IPipelineStatusRepository>();
            var model         = new ApiPipelineStatusServerRequestModel();
            var validatorMock = new Mock <IApiPipelineStatusServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiPipelineStatusServerRequestModel>())).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 PipelineStatus()));
            var service = new PipelineStatusService(mock.LoggerMock.Object,
                                                    mock.MediatorMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    validatorMock.Object,
                                                    mock.DALMapperMockFactory.DALPipelineStatusMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiPipelineStatusServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PipelineStatusUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Esempio n. 2
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IPipelineStatusService, IPipelineStatusRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PipelineStatus>(null));
            var service = new PipelineStatusService(mock.LoggerMock.Object,
                                                    mock.MediatorMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.PipelineStatusModelValidatorMock.Object,
                                                    mock.DALMapperMockFactory.DALPipelineStatusMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineMapperMock);

            ApiPipelineStatusServerResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Esempio n. 3
0
        public async void PipelinesByPipelineStatusId_Not_Exists()
        {
            var mock = new ServiceMockFacade <IPipelineStatusService, IPipelineStatusRepository>();

            mock.RepositoryMock.Setup(x => x.PipelinesByPipelineStatusId(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <Pipeline> >(new List <Pipeline>()));
            var service = new PipelineStatusService(mock.LoggerMock.Object,
                                                    mock.MediatorMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.PipelineStatusModelValidatorMock.Object,
                                                    mock.DALMapperMockFactory.DALPipelineStatusMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineMapperMock);

            List <ApiPipelineServerResponseModel> response = await service.PipelinesByPipelineStatusId(default(int));

            response.Should().BeEmpty();
            mock.RepositoryMock.Verify(x => x.PipelinesByPipelineStatusId(default(int), It.IsAny <int>(), It.IsAny <int>()));
        }
Esempio n. 4
0
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IPipelineStatusRepository>();
            var record = new PipelineStatus();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new PipelineStatusService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.PipelineStatusModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLPipelineStatusMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineStatusMapperMock,
                                                    mock.BOLMapperMockFactory.BOLPipelineMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineMapperMock);

            ApiPipelineStatusResponseModel response = await service.Get(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Esempio n. 5
0
        public async void All_ShouldReturnRecords()
        {
            var mock    = new ServiceMockFacade <IPipelineStatusService, IPipelineStatusRepository>();
            var records = new List <PipelineStatus>();

            records.Add(new PipelineStatus());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            var service = new PipelineStatusService(mock.LoggerMock.Object,
                                                    mock.MediatorMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.PipelineStatusModelValidatorMock.Object,
                                                    mock.DALMapperMockFactory.DALPipelineStatusMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineMapperMock);

            List <ApiPipelineStatusServerResponseModel> response = await service.All();

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Esempio n. 6
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IPipelineStatusRepository>();
            var model = new ApiPipelineStatusRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PipelineStatus>())).Returns(Task.FromResult(new PipelineStatus()));
            var service = new PipelineStatusService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.PipelineStatusModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLPipelineStatusMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineStatusMapperMock,
                                                    mock.BOLMapperMockFactory.BOLPipelineMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PipelineStatusModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPipelineStatusRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PipelineStatus>()));
        }
Esempio n. 7
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IPipelineStatusRepository>();
            var model = new ApiPipelineStatusRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new PipelineStatusService(mock.LoggerMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.PipelineStatusModelValidatorMock.Object,
                                                    mock.BOLMapperMockFactory.BOLPipelineStatusMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineStatusMapperMock,
                                                    mock.BOLMapperMockFactory.BOLPipelineMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.PipelineStatusModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Esempio n. 8
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IPipelineStatusService, IPipelineStatusRepository>();
            var model = new ApiPipelineStatusServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new PipelineStatusService(mock.LoggerMock.Object,
                                                    mock.MediatorMock.Object,
                                                    mock.RepositoryMock.Object,
                                                    mock.ModelValidatorMockFactory.PipelineStatusModelValidatorMock.Object,
                                                    mock.DALMapperMockFactory.DALPipelineStatusMapperMock,
                                                    mock.DALMapperMockFactory.DALPipelineMapperMock);

            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.PipelineStatusModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PipelineStatusDeletedNotification>(), It.IsAny <CancellationToken>()));
        }