Ejemplo n.º 1
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <ICallStatusService, ICallStatusRepository>();

            var model = new ApiCallStatusServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <CallStatus>())).Returns(Task.FromResult(new CallStatus()));
            var service = new CallStatusService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.CallStatusModelValidatorMock.Object,
                                                mock.DALMapperMockFactory.DALCallStatusMapperMock,
                                                mock.DALMapperMockFactory.DALCallMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.CallStatusModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiCallStatusServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <CallStatus>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <CallStatusCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 2
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ICallStatusService, ICallStatusRepository>();
            var model         = new ApiCallStatusServerRequestModel();
            var validatorMock = new Mock <IApiCallStatusServerRequestModelValidator>();

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

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

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