Пример #1
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IDatabaseLogRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <DatabaseLog>(null));
            var service = new DatabaseLogService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.DatabaseLogModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLDatabaseLogMapperMock,
                                                 mock.DALMapperMockFactory.DALDatabaseLogMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Пример #2
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IDatabaseLogRepository>();
            var model = new ApiDatabaseLogRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <DatabaseLog>())).Returns(Task.FromResult(new DatabaseLog()));
            var service = new DatabaseLogService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.DatabaseLogModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLDatabaseLogMapperMock,
                                                 mock.DALMapperMockFactory.DALDatabaseLogMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.DatabaseLogModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiDatabaseLogRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <DatabaseLog>()));
        }
Пример #3
0
        public async void All()
        {
            var mock    = new ServiceMockFacade <IDatabaseLogRepository>();
            var records = new List <DatabaseLog>();

            records.Add(new DatabaseLog());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            var service = new DatabaseLogService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.DatabaseLogModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLDatabaseLogMapperMock,
                                                 mock.DALMapperMockFactory.DALDatabaseLogMapperMock);

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

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Пример #4
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IDatabaseLogRepository>();
            var model = new ApiDatabaseLogRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new DatabaseLogService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.DatabaseLogModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLDatabaseLogMapperMock,
                                                 mock.DALMapperMockFactory.DALDatabaseLogMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.DatabaseLogModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }