Exemplo n.º 1
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IEventStatusRepository>();
            var model = new ApiEventStatusRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <EventStatus>())).Returns(Task.FromResult(new EventStatus()));
            var service = new EventStatusService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLEventStatusMapperMock,
                                                 mock.DALMapperMockFactory.DALEventStatusMapperMock,
                                                 mock.BOLMapperMockFactory.BOLEventMapperMock,
                                                 mock.DALMapperMockFactory.DALEventMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiEventStatusRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <EventStatus>()));
        }
Exemplo n.º 2
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IEventStatusService, IEventStatusRepository>();

            var model = new ApiEventStatusServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <EventStatus>())).Returns(Task.FromResult(new EventStatus()));
            var service = new EventStatusService(mock.LoggerMock.Object,
                                                 mock.MediatorMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Object,
                                                 mock.DALMapperMockFactory.DALEventStatusMapperMock,
                                                 mock.DALMapperMockFactory.DALEventMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiEventStatusServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <EventStatus>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <EventStatusCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Exemplo n.º 3
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IEventStatusService, IEventStatusRepository>();
            var model         = new ApiEventStatusServerRequestModel();
            var validatorMock = new Mock <IApiEventStatusServerRequestModelValidator>();

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

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

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