Ejemplo n.º 1
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IFamilyService, IFamilyRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Family>(null));
            var service = new FamilyService(mock.LoggerMock.Object,
                                            mock.MediatorMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Object,
                                            mock.DALMapperMockFactory.DALFamilyMapperMock,
                                            mock.DALMapperMockFactory.DALStudentMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Ejemplo n.º 2
0
        public async void Get()
        {
            var mock   = new ServiceMockFacade <IFamilyRepository>();
            var record = new Family();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new FamilyService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.FamilyModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLFamilyMapperMock,
                                            mock.DALMapperMockFactory.DALFamilyMapperMock,
                                            mock.BOLMapperMockFactory.BOLStudentMapperMock,
                                            mock.DALMapperMockFactory.DALStudentMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public void FamilyService_Get_ByPage_Overload_Returns_PagedList_Of_Familys()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Family>>();
            mockRepository.Setup(r => r.Get(It.IsAny<int>())).Returns(GetFamilys(TestConstants.PAGE_TotalCount));
            _mockUnitOfWork.Setup(u => u.GetRepository<Family>()).Returns(mockRepository.Object);

            _service = new FamilyService(_mockUnitOfWork.Object);
            const int treeId = TestConstants.TREE_Id;

            //Act
            var familys = _service.Get(treeId, t => true, 0, TestConstants.PAGE_RecordCount);

            //Assert
            Assert.IsInstanceOf<IPagedList<Family>>(familys);
            Assert.AreEqual(TestConstants.PAGE_TotalCount, familys.TotalCount);
            Assert.AreEqual(TestConstants.PAGE_RecordCount, familys.PageSize);
        }
        public void FamilyService_Get_ByPage_Overload_Calls_Repository_Get()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Family>>();
            _mockUnitOfWork.Setup(u => u.GetRepository<Family>()).Returns(mockRepository.Object);

            _service = new FamilyService(_mockUnitOfWork.Object);
            const int treeId = TestConstants.TREE_Id;

            //Act
            _service.Get(treeId, t => true, 0, TestConstants.PAGE_RecordCount);

            //Assert
            mockRepository.Verify(r => r.Get(It.IsAny<int>()));
        }
        public void FamilyService_Get_ByPage_Overload_Throws_On_Negative_TreeId()
        {
            //Arrange
            _service = new FamilyService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<IndexOutOfRangeException>(() => _service.Get(-1, t => true, 0, TestConstants.PAGE_RecordCount));
        }
        public void FamilyService_Get_Overload_Throws_On_Negative_TreeId()
        {
            //Arrange
            _service = new FamilyService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<IndexOutOfRangeException>(() => _service.Get(-1));
        }
        public void FamilyService_Get_Returns_Null_On_InValid_Id()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Family>>();
            mockRepository.Setup(r => r.Get(It.IsAny<int>())).Returns(GetFamilys(TestConstants.PAGE_TotalCount));
            _mockUnitOfWork.Setup(u => u.GetRepository<Family>()).Returns(mockRepository.Object);

            _service = new FamilyService(_mockUnitOfWork.Object);
            const int id = TestConstants.ID_NotFound;

            //Act
            var family = _service.Get(id, It.IsAny<int>());

            //Assert
            Assert.IsNull(family);
        }
        public void FamilyService_Get_Calls_Repository_Get()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Family>>();
            _mockUnitOfWork.Setup(u => u.GetRepository<Family>()).Returns(mockRepository.Object);

            _service = new FamilyService(_mockUnitOfWork.Object);
            const int id = TestConstants.ID_Exists;

            //Act
            _service.Get(id, It.IsAny<int>());

            //Assert
            mockRepository.Verify(r => r.Get(It.IsAny<int>()));
        }
        public void FamilyService_Get_Throws_On_Negative_Id()
        {
            //Arrange
            _service = new FamilyService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<IndexOutOfRangeException>(() => _service.Get(-1, It.IsAny<int>()));
        }