Beispiel #1
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <ISaleTicketsRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <SaleTickets>(null));
            var service = new SaleTicketsService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLSaleTicketsMapperMock,
                                                 mock.DALMapperMockFactory.DALSaleTicketsMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Beispiel #2
0
        public async void ByTicketId_Not_Exists()
        {
            var mock = new ServiceMockFacade <ISaleTicketsRepository>();

            mock.RepositoryMock.Setup(x => x.ByTicketId(It.IsAny <int>())).Returns(Task.FromResult <List <SaleTickets> >(new List <SaleTickets>()));
            var service = new SaleTicketsService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLSaleTicketsMapperMock,
                                                 mock.DALMapperMockFactory.DALSaleTicketsMapperMock);

            List <ApiSaleTicketsResponseModel> response = await service.ByTicketId(default(int));

            response.Should().BeEmpty();
            mock.RepositoryMock.Verify(x => x.ByTicketId(It.IsAny <int>()));
        }
Beispiel #3
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISaleTicketsRepository>();
            var model = new ApiSaleTicketsRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <SaleTickets>())).Returns(Task.FromResult(new SaleTickets()));
            var service = new SaleTicketsService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLSaleTicketsMapperMock,
                                                 mock.DALMapperMockFactory.DALSaleTicketsMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSaleTicketsRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <SaleTickets>()));
        }
Beispiel #4
0
        public async void All()
        {
            var mock    = new ServiceMockFacade <ISaleTicketsRepository>();
            var records = new List <SaleTickets>();

            records.Add(new SaleTickets());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            var service = new SaleTicketsService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLSaleTicketsMapperMock,
                                                 mock.DALMapperMockFactory.DALSaleTicketsMapperMock);

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

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Beispiel #5
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ISaleTicketsRepository>();
            var model = new ApiSaleTicketsRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new SaleTicketsService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLSaleTicketsMapperMock,
                                                 mock.DALMapperMockFactory.DALSaleTicketsMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Beispiel #6
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <ISaleTicketsService, ISaleTicketsRepository>();
            var model = new ApiSaleTicketsServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new SaleTicketsService(mock.LoggerMock.Object,
                                                 mock.MediatorMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.SaleTicketsModelValidatorMock.Object,
                                                 mock.DALMapperMockFactory.DALSaleTicketsMapperMock);

            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.SaleTicketsModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SaleTicketsDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
Beispiel #7
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ISaleTicketsService, ISaleTicketsRepository>();
            var model         = new ApiSaleTicketsServerRequestModel();
            var validatorMock = new Mock <IApiSaleTicketsServerRequestModelValidator>();

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

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

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