Skip to content

Commit

Permalink
SC-62: Add ParagraphCollection.Add() method to add a new paragraph (S…
Browse files Browse the repository at this point in the history
  • Loading branch information
ashahabov authored Jan 23, 2021
1 parent 3c61e65 commit 5c7f57d
Show file tree
Hide file tree
Showing 51 changed files with 624 additions and 538 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Version 0.13.0 - Unreleased
### Added
- Added `CellSc.IsMergedCell` to define whether table cell belong to merged cells group.
- Added `CellSc.IsMergedCell` to define whether table cell belong to merged cells group;
- Added `ParagraphCollection.Add()` method to add a new paragraph.

## Version 0.12.0 - 2021-01-17
### Added
Expand Down
2 changes: 2 additions & 0 deletions ShapeCrawler.Tests.Unit/Helpers/PresentationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class PresentationFixture
public PresentationSc Pre008 { get; }
public PresentationSc Pre009 { get; }
public PresentationSc Pre011 { get; }
public PresentationSc Pre012 { get; }
public PresentationSc Pre013 { get; }
public PresentationSc Pre014 { get; }
public PresentationSc Pre015 { get; }
Expand All @@ -30,6 +31,7 @@ public PresentationFixture()
Pre008 = PresentationSc.Open(Properties.Resources._008, false);
Pre009 = PresentationSc.Open(Properties.Resources._009, false);
Pre011 = PresentationSc.Open(Properties.Resources._011_dt, false);
Pre012 = PresentationSc.Open(Properties.Resources._012_title_placeholder, false);
Pre013 = PresentationSc.Open(Properties.Resources._013, false);
Pre014 = PresentationSc.Open(Properties.Resources._014, false);
Pre015 = PresentationSc.Open(Properties.Resources._015, false);
Expand Down
4 changes: 2 additions & 2 deletions ShapeCrawler.Tests.Unit/Helpers/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static ParagraphSc GetParagraph(PresentationSc presentation, ElementReque
{
return presentation.Slides[paragraphRequest.SlideIndex]
.Shapes.First(sp => sp.Id == paragraphRequest.ShapeId)
.Text.Paragraphs[paragraphRequest.ParagraphIndex];
.TextBox.Paragraphs[paragraphRequest.ParagraphIndex];
}

public static ParagraphSc GetParagraph(MemoryStream presentationStream, ElementRequest paragraphRequest)
Expand All @@ -19,7 +19,7 @@ public static ParagraphSc GetParagraph(MemoryStream presentationStream, ElementR

return presentation.Slides[paragraphRequest.SlideIndex]
.Shapes.First(sp => sp.Id == paragraphRequest.ShapeId)
.Text.Paragraphs[paragraphRequest.ParagraphIndex];
.TextBox.Paragraphs[paragraphRequest.ParagraphIndex];
}
}
}
38 changes: 19 additions & 19 deletions ShapeCrawler.Tests.Unit/ParagraphPortionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void Remove_RemovesPortionFromCollection()

var memoryStream = new MemoryStream();
presentation.SaveAs(memoryStream);
var savedPresentation = new PresentationSc(memoryStream, false);
var savedPresentation = PresentationSc.Open(memoryStream, false);
portions = GetPortions(savedPresentation);
portions.Should().HaveCount(1);
}
Expand All @@ -52,7 +52,7 @@ public void Remove_RemovesPortionFromCollection()
public void Text_GetterReturnsParagraphPortionText()
{
// Arrange
Portion portion = _fixture.Pre009.Slides[2].Shapes.First(sp => sp.Id == 3).Table.Rows[0].Cells[0].Text
Portion portion = _fixture.Pre009.Slides[2].Shapes.First(sp => sp.Id == 3).Table.Rows[0].Cells[0].TextBoxBox
.Paragraphs[0].Portions[0];

// Act
Expand All @@ -66,8 +66,8 @@ public void Text_GetterReturnsParagraphPortionText()
public void FontName_GetterReturnsFontNameOfTheParagraphPortion()
{
// Arrange
TextSc textFrameCase1 = _fixture.Pre002.Slides[1].Shapes.First(s => s.Id == 3).Text;
TextSc textFrameCase2 = _fixture.Pre001.Slides[0].Shapes.First(s => s.Id == 4).Text;
TextBoxSc textFrameCase1 = _fixture.Pre002.Slides[1].Shapes.First(s => s.Id == 3).TextBox;
TextBoxSc textFrameCase2 = _fixture.Pre001.Slides[0].Shapes.First(s => s.Id == 4).TextBox;

// Act
string portionFontNameCase1 = textFrameCase1.Paragraphs[0].Portions[0].Font.Name;
Expand All @@ -85,7 +85,7 @@ public void FontName_SetterSetsSpecifiedFontName()
const string newFont = "Time New Roman";
Portion paragraphPortion = PresentationSc.Open(Resources._001, true).
Slides[0].Shapes.First(sp => sp.Id == 4).
Text.Paragraphs[0].Portions[0];
TextBox.Paragraphs[0].Portions[0];
// Act
paragraphPortion.Font.Name = newFont;

Expand All @@ -97,8 +97,8 @@ public void FontName_SetterSetsSpecifiedFontName()
public void FontName_SetterThrowsException_WhenAUserTrySetFontNameForPortionOfAPlaceholderShape()
{
// Arrange
TextSc textFrame = PresentationSc.Open(Resources._001, true).Slides[2].Shapes
.First(sp => sp.Id == 4).Text;
TextBoxSc textFrame = PresentationSc.Open(Resources._001, true).Slides[2].Shapes
.First(sp => sp.Id == 4).TextBox;
ParagraphCollection paragraphs = textFrame.Paragraphs;
Portion paragraphPortion = paragraphs[0].Portions[0];

Expand All @@ -113,16 +113,16 @@ public void FontName_SetterThrowsException_WhenAUserTrySetFontNameForPortionOfAP
public void FontSize_GetterReturnsFontSizeOfTheParagraphPortion()
{
// Arrange
Portion portionCase1 = _fixture.Pre020.Slides[0].Shapes.First(sp => sp.Id == 3).Text.Paragraphs[0].Portions[0];
Portion portionCase2 = _fixture.Pre015.Slides[0].Shapes.First(sp => sp.Id == 5).Text.Paragraphs[0].Portions[2];
Portion portionCase3 = _fixture.Pre015.Slides[1].Shapes.First(sp => sp.Id == 61).Text.Paragraphs[0].Portions[0];
Portion portionCase4 = _fixture.Pre009.Slides[2].Shapes.First(sp => sp.Id == 2).Text.Paragraphs[0].Portions[0];
Portion portionCase5 = _fixture.Pre009.Slides[2].Shapes.First(sp => sp.Id == 2).Text.Paragraphs[0].Portions[1];
Portion portionCase6 = _fixture.Pre009.Slides[3].Shapes.First(sp => sp.Id == 2).Text.Paragraphs[0].Portions[0];
Portion portionCase7 = _fixture.Pre009.Slides[3].Shapes.First(sp => sp.Id == 3).Text.Paragraphs[0].Portions[0];
Portion portionCase8 = _fixture.Pre019.Slides[0].Shapes.First(sp => sp.Id == 4103).Text.Paragraphs[0].Portions[0];
Portion portionCase9 = _fixture.Pre019.Slides[0].Shapes.First(sp => sp.Id == 2).Text.Paragraphs[0].Portions[0];
Portion portionCase10 = _fixture.Pre014.Slides[1].Shapes.First(sp => sp.Id == 5).Text.Paragraphs[0].Portions[0];
Portion portionCase1 = _fixture.Pre020.Slides[0].Shapes.First(sp => sp.Id == 3).TextBox.Paragraphs[0].Portions[0];
Portion portionCase2 = _fixture.Pre015.Slides[0].Shapes.First(sp => sp.Id == 5).TextBox.Paragraphs[0].Portions[2];
Portion portionCase3 = _fixture.Pre015.Slides[1].Shapes.First(sp => sp.Id == 61).TextBox.Paragraphs[0].Portions[0];
Portion portionCase4 = _fixture.Pre009.Slides[2].Shapes.First(sp => sp.Id == 2).TextBox.Paragraphs[0].Portions[0];
Portion portionCase5 = _fixture.Pre009.Slides[2].Shapes.First(sp => sp.Id == 2).TextBox.Paragraphs[0].Portions[1];
Portion portionCase6 = _fixture.Pre009.Slides[3].Shapes.First(sp => sp.Id == 2).TextBox.Paragraphs[0].Portions[0];
Portion portionCase7 = _fixture.Pre009.Slides[3].Shapes.First(sp => sp.Id == 3).TextBox.Paragraphs[0].Portions[0];
Portion portionCase8 = _fixture.Pre019.Slides[0].Shapes.First(sp => sp.Id == 4103).TextBox.Paragraphs[0].Portions[0];
Portion portionCase9 = _fixture.Pre019.Slides[0].Shapes.First(sp => sp.Id == 2).TextBox.Paragraphs[0].Portions[0];
Portion portionCase10 = _fixture.Pre014.Slides[1].Shapes.First(sp => sp.Id == 5).TextBox.Paragraphs[0].Portions[0];

// Act
int portionFontSizeCase1 = portionCase1.Font.Size;
Expand Down Expand Up @@ -155,7 +155,7 @@ public void FontSize_SetterChangesFontSizeOfParagraphPortion()
// Arrange
static Portion GetPortion(PresentationSc presentation)
{
Portion portion = presentation.Slides[0].Shapes.First(sp => sp.Id == 4).Text.Paragraphs[0].Portions[0];
Portion portion = presentation.Slides[0].Shapes.First(sp => sp.Id == 4).TextBox.Paragraphs[0].Portions[0];
return portion;
}
int newFontSize = 28;
Expand All @@ -179,7 +179,7 @@ static Portion GetPortion(PresentationSc presentation)
private static PortionCollection GetPortions(PresentationSc presentation)
{
var shape5 = presentation.Slides[1].Shapes.First(x => x.Id == 5);
var portions = shape5.Text.Paragraphs.First().Portions;
var portions = shape5.TextBox.Paragraphs.First().Portions;
return portions;
}
}
Expand Down
23 changes: 0 additions & 23 deletions ShapeCrawler.Tests.Unit/Presentation25Fixture.cs

This file was deleted.

8 changes: 4 additions & 4 deletions ShapeCrawler.Tests.Unit/PresentationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Open_ThrowsPresentationIsLargeException_WhenThePresentationContentSi
// Act
Action act = () => PresentationSc.Open(bytes, false);

// Arrange
// Assert
act.Should().Throw<PresentationIsLargeException>();
}

Expand Down Expand Up @@ -66,15 +66,15 @@ public void SlidesRemove_RemovesSlideFromPresentation_WhenSlideInstanceIsPassedI
{
// Arrange
var stream = new MemoryStream(Properties.Resources._007_2_slides);
var presentation = new PresentationSc(stream, true);
var presentation = PresentationSc.Open(stream, true);
var removingSlide = presentation.Slides.First();

// Act
presentation.Slides.Remove(removingSlide);
presentation.Close();

// Assert
presentation = new PresentationSc(stream, false);
presentation = PresentationSc.Open(stream, false);
presentation.Slides.Should().HaveCount(1);
}

Expand Down Expand Up @@ -104,7 +104,7 @@ public void SlideMasterShapesCount_ReturnsNumberOfShapesOnTheMasterSlide()
int slideMasterShapesCount = presentation.SlideMasters[0].Shapes.Count;

// Assert
slideMasterShapesCount.Should().Be(5);
slideMasterShapesCount.Should().Be(7);
}
}
}
Binary file modified ShapeCrawler.Tests.Unit/Resource/001.pptx
Binary file not shown.
2 changes: 1 addition & 1 deletion ShapeCrawler.Tests.Unit/ShapeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void HasTextFrame_ReturnsFalse_WhenTheShapeDoesNotContainText()
ShapeSc shape = _fixture.Pre009.Slides[4].Shapes.First(sp => sp.Id == 5);

// Act
bool hasTextFrame = shape.HasTextFrame;
bool hasTextFrame = shape.HasTextBox;

// Assert
hasTextFrame.Should().BeFalse();
Expand Down
39 changes: 29 additions & 10 deletions ShapeCrawler.Tests.Unit/SlideMasterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,52 @@ public void ShapeWidthAndHeight_ReturnWidthAndHeightSizesOfTheMaster()
shapeHeight.Should().Be(1325563);
}

[Fact]
public void MasterAutoShapePlaceholderType_ReturnPlaceholderTypeOfTheMasterShape_WhenTheMasterShapeIsPlaceholder()
[Fact(Skip = "The feature is in progress.")]
public void MasterShapePlaceholderType_ReturnPlaceholderTypeOfTheMasterShape_WhenTheMasterShapeIsPlaceholder()
{
// Arrange
SlideMasterSc slideMaster = _fixture.Pre001.SlideMasters[0];
BaseShape shape = slideMaster.Shapes.First(sp => sp.Id == 2);
MasterAutoShape masterAutoShape = (MasterAutoShape) shape;
MasterShape masterAutoShapeCase1 = (MasterShape)slideMaster.Shapes.First(sp => sp.Id == 2);
MasterShape masterAutoShapeCase2 = (MasterShape)slideMaster.Shapes.First(sp => sp.Id == 8);
MasterShape masterAutoShapeCase3 = (MasterShape)slideMaster.Shapes.First(sp => sp.Id == 7);

// Act
PlaceholderType? shapePlaceholderType = masterAutoShape.PlaceholderType;
PlaceholderType? shapePlaceholderTypeCase1 = masterAutoShapeCase1.PlaceholderType;
PlaceholderType? shapePlaceholderTypeCase2 = masterAutoShapeCase2.PlaceholderType;
PlaceholderType? shapePlaceholderTypeCase3 = masterAutoShapeCase3.PlaceholderType;

// Assert
shapePlaceholderType.Should().Be(PlaceholderType.Title);
shapePlaceholderTypeCase1.Should().Be(PlaceholderType.Title);
shapePlaceholderTypeCase2.Should().BeNull();
shapePlaceholderTypeCase3.Should().BeNull();
}

[Fact(Skip = "The feature is in progress")]
[Fact]
public void ShapeGeometryType_ReturnsShapesGeometryFormType()
{
// Arrange
SlideMasterSc slideMaster = _fixture.Pre001.SlideMasters[0];
BaseShape shape = slideMaster.Shapes.First(sp => sp.Id == 2);
BaseShape shapeCase1 = slideMaster.Shapes.First(sp => sp.Id == 2);
BaseShape shapeCase2 = slideMaster.Shapes.First(sp => sp.Id == 8);

// Act
GeometryType shapeGeometryType = shape.GeometryType;
GeometryType geometryTypeCase1 = shapeCase1.GeometryType;
GeometryType geometryTypeCase2 = shapeCase2.GeometryType;

// Assert
shapeGeometryType.Should().Be(GeometryType.Rectangle);
geometryTypeCase1.Should().Be(GeometryType.Rectangle);
geometryTypeCase2.Should().Be(GeometryType.Custom);
}

[Fact]
public void MasterAutoShapeTextBoxText_ReturnsText_WhenTheAutoShapesTextBoxIsNotEmpty()
{
// Arrange
SlideMasterSc slideMaster = _fixture.Pre001.SlideMasters[0];
IAutoShape autoShape = (IAutoShape)slideMaster.Shapes.First(sp => sp.Id == 8);

// Act-Assert
autoShape.TextBox.Text.Should().BeEquivalentTo("id8");
}
}
}
6 changes: 3 additions & 3 deletions ShapeCrawler.Tests.Unit/SlideTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void SaveScheme_CreatesAndSavesSlideSchemeImageInSpecifiedStream()
public async void BackgroundSetImage_ChangesBackground_WhenImageStreamIsPassed()
{
// Arrange
var pre = new PresentationSc(Properties.Resources._009);
var pre = PresentationSc.Open(Properties.Resources._009, true);
var backgroundImage = pre.Slides[0].Background;
var imgStream = new MemoryStream(Properties.Resources.test_image_2);
var bytesBefore = await backgroundImage.GetImageBytes();
Expand Down Expand Up @@ -103,15 +103,15 @@ public void CustomData_ReturnsData_WhenCustomDataWasAssigned()
const string customDataString = "Test custom data";
var origPreStream = new MemoryStream();
origPreStream.Write(Properties.Resources._001);
var originPre = new PresentationSc(origPreStream, true);
var originPre = PresentationSc.Open(origPreStream, true);
var slide = originPre.Slides.First();

// Act
slide.CustomData = customDataString;

var savedPreStream = new MemoryStream();
originPre.SaveAs(savedPreStream);
var savedPre = new PresentationSc(savedPreStream, false);
var savedPre = PresentationSc.Open(savedPreStream, false);
var customData = savedPre.Slides.First().CustomData;

// Assert
Expand Down
Loading

0 comments on commit 5c7f57d

Please sign in to comment.