Example #1
0
        public void ServiceGeneratePoemSuccessTest()
        {
            //Arrange
            int               testSchemaId     = 1;
            string            expectedPoemText = "poem";
            Mock <PoemSchema> mockPoemSchema   = new Mock <PoemSchema>();

            mockPoemRepository.Setup(m => m.GetSchemaById(testSchemaId)).Returns(mockPoemSchema.Object);

            string testFilePath = "rules.csv";

            mockConfig.Setup(m => m.SyntaxConfigFile).Returns(testFilePath);

            Mock <IPoemSyntaxRuleDocument> mockDocument = new Mock <IPoemSyntaxRuleDocument>();

            mockParser.Setup(m => m.Parse(testFilePath)).Returns(mockDocument.Object);
            mockPoemGenerator.Setup(m => m.GeneratePoem(mockPoemSchema.Object, mockDocument.Object)).Returns(expectedPoemText);

            //Act
            PoemService poemService    = new PoemService(mockParser.Object, mockPoemRepository.Object, mockConfig.Object, mockPoemGenerator.Object);
            string      actualPoemText = poemService.GeneratePoem(testSchemaId);

            //Assert
            Assert.AreEqual(expectedPoemText, actualPoemText);

            mockPoemRepository.Verify(m => m.GetSchemaById(It.IsAny <int>()), Times.Exactly(1));
            mockConfig.Verify(mock => mock.SyntaxConfigFile, Times.AtLeast(1));
            mockParser.Verify(m => m.Parse(It.IsAny <string>()), Times.Exactly(1));
            mockPoemGenerator.Verify(m => m.GeneratePoem(It.IsAny <PoemSchema>(), It.IsAny <IPoemSyntaxRuleDocument>()), Times.Exactly(1));
        }
Example #2
0
        public void ServiceGetAllPoemSchemasSuccessTest()
        {
            //Arrange
            List <PoemSchema> expectedSchemas = new List <PoemSchema>();

            mockPoemRepository.Setup(m => m.GetAllSchemas()).Returns(expectedSchemas);
            PoemService poemService = new PoemService(mockParser.Object, mockPoemRepository.Object, mockConfig.Object, mockPoemGenerator.Object);

            //Act
            List <PoemSchema> actualSchemas = poemService.GetAllPoemSchemas();

            //Assert
            Assert.AreEqual(expectedSchemas, actualSchemas);

            mockPoemRepository.Verify(m => m.GetAllSchemas(), Times.Exactly(1));
        }
Example #3
0
        public Poem WritePoem()
        {
            var pService = new PoemService();

            return(pService.WritePoem());
        }