示例#1
0
        public void DeleteDocumentFromDb_ExpectedParametersAndParagraphToDelete_Ok()
        {
            Margin margin = new Margin(MarginAlign.HEADER, "aStyleClass");

            margin.SetText(new Text());
            aDocumentPart.PutTextAtLast(new Text());
            document.AddDocumentParagraphAtLast(aDocumentPart);
            document.SetDocumentMargin(margin.Align, margin);
            documentDataAccess.Add(document);

            documentDataAccess.Delete(document.Id);

            Document  obtained          = documentDataAccess.Get(document.Id);
            Paragraph paragraphObtained = paragraphDataAccess.Get(aDocumentPart.Id);

            ITextDataAccess txtDA = new TextDataAccess();

            Text text1 = txtDA.Get(margin.GetText().Id);
            Text text2 = txtDA.Get(aDocumentPart.GetTextAt(0).Id);

            Assert.IsNull(obtained);
            Assert.IsNull(paragraphObtained);
            Assert.IsNull(text1);
            Assert.IsNull(text2);
        }
示例#2
0
        public void CreateTextBL_WithParameters_Ok()
        {
            ITextDataAccess textDataAccess = new TextDataAccess();
            IBodyDataAccess bodyDataAccess = new BodyDataAccess();

            ITextBusinessLogic textBL = new TextBusinessLogic(textDataAccess);

            Assert.IsNotNull(textBL);
        }
示例#3
0
        public void SaveTextTest()
        {
            string        filePath = "filepath";
            List <string> lines    = new List <string>()
            {
                "dlkfjwoeitupisposf, ", "sjdlfujrtppqepoiqq", "fccoviuoeqlkjwe"
            };

            List <string> result = TextDataAccess.SaveText(filePath, lines);

            Assert.Equal(lines, result);
        }
示例#4
0
        public void SaveTextTest2()
        {
            string filePath = "lskdfjkdjfkdjflkdjlfkdjlskdjfpwierpweurppppppppppppppppppppppppppppppppppppppppppppppp" +
                              "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" +
                              "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo";
            List <string> lines = new List <string>()
            {
                "dlkfjwoeitupisposf, ", "sjdlfujrtppqepoiqq", "fccoviuoeqlkjwe"
            };

            Action testCode = () => { List <string> result = TextDataAccess.SaveText(filePath, lines); };
            var    ex       = Record.Exception(testCode);

            Assert.IsType <PathTooLongException>(ex);
        }
        public void SaveText_WhenCalled_ShouldExecuteWriteAllText()
        {
            FakeWriteText  mockWrite      = new FakeWriteText();
            TextDataAccess textDataAccess = new TextDataAccess(mockWrite);
            List <string>  lines          = new List <string>
            {
                "First line",
                "Second line",
                "Third line"
            };

            string filePath = $"write.txt";

            textDataAccess.SaveText(filePath, lines);

            Assert.True(mockWrite.Done);
        }
示例#6
0
        public void IntegrationTest_ExpectedParameters_Ok()
        {
            TextDataAccess    textDA = new TextDataAccess();
            BodyDataAccess    bodyDA = new BodyDataAccess();
            TextBusinessLogic textBL = new TextBusinessLogic(textDA);
            Text text1 = Utils.CreateTextForTest();
            Text text2 = Utils.CreateTextForTest();

            textBL.AddText(text1);
            textBL.AddText(text2);

            text2.OwnStyleClass = "Other style";
            textBL.ModifyText(text2);

            textBL.DeleteText(text1.Id);

            Text         text2Obtained = textBL.GetText(text2.Id);
            IList <Text> textsObtained = textBL.GetTexts();

            Assert.IsTrue(!textsObtained.Contains(text1) && textsObtained.Contains(text2Obtained));
        }
        public void SaveText_Normal()
        {
            List <string> lines = new List <string>
            {
                "Test one",
                "Test 2",
                "Test III"
            };

            string filePath = @"C:\Temp\Test.txt";
            string fileName = "Test.txt";

            var mock = new Mock <IWriteToText>();

            mock.Setup(x => x.WriteToFile(fileName, It.IsAny <List <string> >())).Verifiable();

            TextDataAccess dataAccess = new TextDataAccess();

            dataAccess.SaveText(filePath, lines, mock.Object);

            mock.Verify();
        }
        public void SaveText_ShouldThrowException()
        {
            WriteText      writeText      = new WriteText();
            TextDataAccess textDataAccess = new TextDataAccess(writeText);
            List <string>  lines          = new List <string>
            {
                "First line",
                "Second line",
                "Third line"
            };

            string filePath =
                $"This path is too long with 261     characters" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890" +
                $"qwertyuiopasdfghjklzxcvbnm1234567890";

            TestDelegate testDelegate = () => textDataAccess.SaveText(filePath, lines);

            Assert.Throws <PathTooLongException>(testDelegate);
        }
        public void SaveText_InvalidPathShouldThrowException()
        {
            List <string> lines = new List <string>
            {
                "Test one",
                "Test 2",
                "Test III"
            };

            string filePath = @"C:\Temp\Testendkjnewdjnwekdjnwkendwkjendkjwnedkjwnedkjwnedkjnwekdjnfvnkjtnrtnkrnvkjernvkjwnefnwefnwjenfkjwkjervkjnrkjvnekjrvbkwjenfkjwne
			jrbfkwrfkjbekrjfbekrbfkerfkebrfberfbehrbktnbmeprnvwnvwnowirnvpwmboientoivnernvoiwrncoiwnvoierpvowpfvbeoubvbeorivnworinvowrinvoiwrnvoiwnrviowrvniowrnvoiwrvwi
			jwnrfonworivnwoirnvoienrvoineworvneoinvoienvoienvoineorivnowirmfpoqke[fompevineonburbnoeirmgpowgviwnepfomqpeofmcwpoefmotibnoeinvwimcxwmewcwerneoirvnowiernvo
			iernviernnowirnv.txt"            ;
            string fileName = "Test.txt";

            var mock = new Mock <IWriteToText>();

            mock.Setup(x => x.WriteToFile(fileName, It.IsAny <List <string> >())).Verifiable();

            TextDataAccess dataAccess = new TextDataAccess();

            Assert.Throws <PathTooLongException>(
                () => dataAccess.SaveText(filePath, lines, mock.Object));
        }
示例#10
0
 public TextDataAccessTests()
 {
     _fileWriter     = new DummyFileWriter();
     _textDataAccess = new TextDataAccess(_fileWriter);
 }