public void FactService_Add_Throws_On_Null_Fact()
        {
            //Arrange
            _service = new FactService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<ArgumentNullException>(() => _service.Add(null));
        }
Exemple #2
0
        private async Task TestGetEnglishFacts_WithTestData_ShouldReturnNull()
        {
            var context     = PMGDbContextInMemoryFactory.CreateDbContext();
            var factService = new FactService(context);

            var philosophyFacts = (await factService.GetEnglishFactsAsync()).FirstOrDefault();

            Assert.True(philosophyFacts == null, "Method GetEnglishFacts() does not work correctly");
        }
        public void TestGetRandomFacts()
        {
            List <Fact> facts = Task.Run(() => FactService.GetRandomFacts()).Result;

            facts.ForEach(fact =>
            {
                Console.WriteLine(fact.Joke);
            });
        }
Exemple #4
0
        private async Task TestGetEnglishFact_WithTestData_ShouldReturnContent()
        {
            var context     = PMGDbContextInMemoryFactory.CreateDbContext();
            var factService = new FactService(context);

            await SeedFacts(context);

            var englishSlang    = (await factService.GetEnglishFactsAsync()).FirstOrDefault();
            var expectedContent = "To turn into peaces";
            var expectedAuthor  = "Break";

            var actualContent = englishSlang.Content;
            var actualAuthor  = englishSlang.Author;

            Assert.Equal(expectedContent, actualContent);
            Assert.Equal(expectedAuthor, actualAuthor);
        }
Exemple #5
0
        private async Task TestGetPhilosophyFacts_WithTestData_ShouldReturnContent()
        {
            var context     = PMGDbContextInMemoryFactory.CreateDbContext();
            var factService = new FactService(context);

            await SeedFacts(context);

            var philosophyFact  = (await factService.GetPhilosophyFactsAsync()).FirstOrDefault();
            var expectedContent = "Който не обича самотата не обича и свободата";
            var expectedAuthor  = "Шопенхауер";

            var actualContent = philosophyFact.Content;
            var actualAuthor  = philosophyFact.Author;

            Assert.Equal(expectedContent, actualContent);
            Assert.Equal(expectedAuthor, actualAuthor);
        }
Exemple #6
0
        private async Task TestGetPhysicsFact_WithTestData_ShouldReturnContent()
        {
            var context     = PMGDbContextInMemoryFactory.CreateDbContext();
            var factService = new FactService(context);

            await SeedFacts(context);

            var physicsFact     = (await factService.GetPhysicsFactsAsync()).FirstOrDefault();
            var expectedContent = "Physics is beautiful";
            var expectedAuthor  = "Man";

            var actualContent = physicsFact.Content;
            var actualAuthor  = physicsFact.Author;

            Assert.Equal(expectedContent, actualContent);
            Assert.Equal(expectedAuthor, actualAuthor);
        }
Exemple #7
0
        private async Task TestGetMathematicsFact_WithTestData_ShouldReturnContent()
        {
            var context     = PMGDbContextInMemoryFactory.CreateDbContext();
            var factService = new FactService(context);

            await SeedFacts(context);

            var mathematicsFact = (await factService.GetMathematicsFactsAsync()).FirstOrDefault();
            var expectedContent = "Math is life";
            var expectedAuthor  = "Somebody";

            var actualContent = mathematicsFact.Content;
            var actualAuthor  = mathematicsFact.Author;

            Assert.Equal(expectedContent, actualContent);
            Assert.Equal(expectedAuthor, actualAuthor);
        }
        public void FactService_Add_Calls_Repository_Add_Method_With_The_Same_Fact_Object_It_Recieved()
        {
            // Create test data
            var newFact = new Fact
            {
                Date = "Foo",
                Place = "Bar"
            };

            //Create Mock
            var mockRepository = new Mock<IRepository<Fact>>();
            _mockUnitOfWork.Setup(d => d.GetRepository<Fact>()).Returns(mockRepository.Object);

            //Arrange
            _service = new FactService(_mockUnitOfWork.Object);

            //Act
            _service.Add(newFact);

            //Assert
            mockRepository.Verify(r => r.Add(newFact));
        }
        public void FactService_Get_Throws_On_Negative_Id()
        {
            //Arrange
            _service = new FactService(_mockUnitOfWork.Object);

            //Assert
            Assert.Throws<IndexOutOfRangeException>(() => _service.Get(-1, It.IsAny<int>()));
        }
        public void FactService_Add_Calls_UnitOfWork_Commit_Method()
        {
            // Create test data
            var newFact = new Fact
            {
                Date = "Foo",
                Place = "Bar"
            };

            //Create Mock
            var mockRepository = new Mock<IRepository<Fact>>();
            _mockUnitOfWork.Setup(d => d.GetRepository<Fact>()).Returns(mockRepository.Object);

            //Arrange
            _service = new FactService(_mockUnitOfWork.Object);

            //Act
            _service.Add(newFact);

            //Assert
            _mockUnitOfWork.Verify(db => db.Commit());
        }
        public void FactService_Update_Calls_Repository_Update_Method_With_The_Same_Fact_Object_It_Recieved()
        {
            // Create test data
            var fact = new Fact { Id = TestConstants.ID_Exists, Date = "Foo", Place = "Bar" };

            //Create Mock
            var mockRepository = new Mock<IRepository<Fact>>();
            _mockUnitOfWork.Setup(d => d.GetRepository<Fact>()).Returns(mockRepository.Object);

            //Arrange
            _service = new FactService(_mockUnitOfWork.Object);

            //Act
            _service.Update(fact);

            //Assert
            mockRepository.Verify(r => r.Update(fact));
        }
        public void FactService_Get_Calls_Repository_Get()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Fact>>();
            _mockUnitOfWork.Setup(u => u.GetRepository<Fact>()).Returns(mockRepository.Object);

            _service = new FactService(_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 FactService_Get_ByPage_Overload_Returns_PagedList_Of_Facts()
        {
            //Arrange
            var mockRepository = new Mock<IRepository<Fact>>();
            mockRepository.Setup(r => r.Get(It.IsAny<int>())).Returns(GetFacts(TestConstants.PAGE_TotalCount));
            _mockUnitOfWork.Setup(u => u.GetRepository<Fact>()).Returns(mockRepository.Object);

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

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

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

            _service = new FactService(_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 FactService_Get_ByPage_Overload_Throws_On_Negative_TreeId()
        {
            //Arrange
            _service = new FactService(_mockUnitOfWork.Object);

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

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

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

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

            //Assert
            Assert.IsNull(fact);
        }