Exemplo n.º 1
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IPostHistoryService, IPostHistoryRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <PostHistory>(null));
            var service = new PostHistoryService(mock.LoggerMock.Object,
                                                 mock.MediatorMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.PostHistoryModelValidatorMock.Object,
                                                 mock.DALMapperMockFactory.DALPostHistoryMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Exemplo n.º 2
0
        public async void ByUserId_Not_Exists()
        {
            var mock = new ServiceMockFacade <IPostHistoryService, IPostHistoryRepository>();

            mock.RepositoryMock.Setup(x => x.ByUserId(It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <PostHistory> >(new List <PostHistory>()));
            var service = new PostHistoryService(mock.LoggerMock.Object,
                                                 mock.MediatorMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.PostHistoryModelValidatorMock.Object,
                                                 mock.DALMapperMockFactory.DALPostHistoryMapperMock);

            List <ApiPostHistoryServerResponseModel> response = await service.ByUserId(default(int));

            response.Should().BeEmpty();
            mock.RepositoryMock.Verify(x => x.ByUserId(It.IsAny <int?>(), It.IsAny <int>(), It.IsAny <int>()));
        }
Exemplo n.º 3
0
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IPostHistoryRepository>();
            var record = new PostHistory();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new PostHistoryService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.PostHistoryModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLPostHistoryMapperMock,
                                                 mock.DALMapperMockFactory.DALPostHistoryMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Exemplo n.º 4
0
        public async void All_ShouldReturnRecords()
        {
            var mock    = new ServiceMockFacade <IPostHistoryService, IPostHistoryRepository>();
            var records = new List <PostHistory>();

            records.Add(new PostHistory());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            var service = new PostHistoryService(mock.LoggerMock.Object,
                                                 mock.MediatorMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.PostHistoryModelValidatorMock.Object,
                                                 mock.DALMapperMockFactory.DALPostHistoryMapperMock);

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

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Exemplo n.º 5
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IPostHistoryRepository>();
            var model = new ApiPostHistoryRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PostHistory>())).Returns(Task.FromResult(new PostHistory()));
            var service = new PostHistoryService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.PostHistoryModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLPostHistoryMapperMock,
                                                 mock.DALMapperMockFactory.DALPostHistoryMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PostHistoryModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiPostHistoryRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <PostHistory>()));
        }
Exemplo n.º 6
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IPostHistoryRepository>();
            var model = new ApiPostHistoryRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new PostHistoryService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.PostHistoryModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLPostHistoryMapperMock,
                                                 mock.DALMapperMockFactory.DALPostHistoryMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.PostHistoryModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Exemplo n.º 7
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IPostHistoryService, IPostHistoryRepository>();
            var model = new ApiPostHistoryServerRequestModel();

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

            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.PostHistoryModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PostHistoryDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
Exemplo n.º 8
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IPostHistoryService, IPostHistoryRepository>();
            var model         = new ApiPostHistoryServerRequestModel();
            var validatorMock = new Mock <IApiPostHistoryServerRequestModelValidator>();

            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 PostHistoryService(mock.LoggerMock.Object,
                                                 mock.MediatorMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 validatorMock.Object,
                                                 mock.DALMapperMockFactory.DALPostHistoryMapperMock);

            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 <PostHistoryDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }