Skip to content

Commit

Permalink
Add CONTRIBUTING file (ShapeCrawler#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashahabov authored Sep 14, 2021
1 parent e8f10ad commit 8aa78e2
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 23 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Recomended tools
The internal structure of PowerPoint presentation is one the most difficult among other documents from the Microsoft Office suite. For example, the slide presented for a user is not a single document but only top on Slide Layout and Slide Master slides. Even just that levels frequently lead to confusion. The following is a list of tools and notes that should simplify your development while working on ShapeCrawler's issue.

- **[OOXML Viewer](https://marketplace.visualstudio.com/items?itemName=yuenm18.ooxml-viewer)** — extension for Visual Studio Code allowing to view Open XML package. One of the good features of this extension is track changes of modified presentation.
- **[Open XML SDK 2.5 Productivity Tool](https://github.com/OfficeDev/Open-XML-SDK/releases/tag/v2.5)** — application for generating C#-code from Open XML document. It can be useful, for example, when you wanna know what C#-code is needed to add a new shape or slide.
- **.pptx is ZIP** — do not forget that .pptx-file is a zip file as well as other Open XML documents. Thus you can rename the extension of the presentation file on .zip and watch his internals:

![.pptx is zip](/resources/pptx_is_zip.gif)
2 changes: 1 addition & 1 deletion ShapeCrawler.Tests.Unit/ChartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void CategoryName_SetterShouldChangeValueOfCorrespondingExcelCell()
public void CategoryName_SetterChangeName_OfSecondaryCategoryInMultiCategoryBarChart()
{
// Arrange
Stream preStream = TestFiles.Presentations.pre025_byteArray.ToStream();
Stream preStream = TestFiles.Presentations.pre025_byteArray.ToResizeableStream();
IPresentation presentation = SCPresentation.Open(preStream, true);
IChart barChart = (IChart)presentation.Slides[0].Shapes.First(sp => sp.Id == 4);
const string newCategoryName = "Clothing_new";
Expand Down
25 changes: 6 additions & 19 deletions ShapeCrawler.Tests.Unit/Helpers/TestFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,16 @@ public static class Presentations
{
public static byte[] pre001 => Resources._001;

public static Stream pre001_stream
{
get
{
var stream = new MemoryStream();
stream.Write(Resources._001, 0, Resources._001.Length);
return stream;
}
}
public static Stream pre001_stream => Resources._001.ToResizeableStream();

public static byte[] pre025_byteArray => Resources._025;

public static Stream pre025_pptxStream
{
get
{
var stream = new MemoryStream();
stream.Write(Resources._025, 0, Resources._025.Length);
return stream;
}
}

public static byte[] pre009 => Resources._009;
}

public class Audio
{
public static Stream TestMp3 => Resources.test_mp3.ToResizeableStream();
}
}
}
2 changes: 1 addition & 1 deletion ShapeCrawler.Tests.Unit/Helpers/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static IPortion GetParagraphPortion(SCPresentation presentation, SlideEle
return autoShape.TextBox.Paragraphs[elementRequest.ParagraphIndex].Portions[elementRequest.PortionIndex];
}

public static MemoryStream ToStream(this byte[] byteArray)
public static MemoryStream ToResizeableStream(this byte[] byteArray)
{
var stream = new MemoryStream();
stream.Write(byteArray, 0, byteArray.Length);
Expand Down
10 changes: 10 additions & 0 deletions ShapeCrawler.Tests.Unit/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ShapeCrawler.Tests.Unit/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<data name="test_image_2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resource\test-image-2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="test_mp3" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resource\test-mp3.mp3;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="_001" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resource\001.pptx;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down
Binary file added ShapeCrawler.Tests.Unit/Resource/test-mp3.mp3
Binary file not shown.
32 changes: 32 additions & 0 deletions ShapeCrawler.Tests.Unit/SlideTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using FluentAssertions;
using ShapeCrawler.Audio;
using ShapeCrawler.Collections;
using ShapeCrawler.Drawing;
using ShapeCrawler.Shapes;
using ShapeCrawler.Tests.Unit.Helpers;
Expand Down Expand Up @@ -145,6 +148,35 @@ public void ShapesCount_ReturnsNumberOfShapesOnTheSlide(ISlide slide, int expect
shapesCount.Should().Be(expectedShapesCount);
}

[Fact(Skip = "In Progress")]
public void Shapes_AddNewAudio_AddsAudio()
{
// Arrange
//Stream preStream = TestFiles.Presentations.pre001_stream;
//IPresentation presentation = SCPresentation.Open(preStream, true);
File.Copy(@"c:\Documents\ShapeCrawler\Issues\SC-159_Add API to add audio content on slide\base.pptx",
@"c:\temp\base.pptx", true);
IPresentation presentation = SCPresentation.Open(@"c:\temp\base.pptx", true);
IShapeCollection shapes = presentation.Slides[0].Shapes;
Stream audioStream = TestFiles.Audio.TestMp3;
string customText = Guid.NewGuid().ToString();

// Act
IAudioShape audioShape = shapes.AddNewAudio(50, 50, audioStream);
presentation.SaveAs(@"c:\temp\modified.pptx");
presentation.Close();
return;
//audioShape.CustomData = customText;
//presentation.Save();
//presentation.Close();

//presentation = SCPresentation.Open(preStream, false);
//audioShape = presentation.Slides[0].Shapes.OfType<IAudioShape>().FirstOrDefault(sp => sp.CustomData == customText);

//// Assert
//audioShape.Should().NotBeNull();
}

public static IEnumerable<object[]> TestCasesShapesCount()
{
SCPresentation presentation = SCPresentation.Open(Properties.Resources._009, false);
Expand Down
8 changes: 8 additions & 0 deletions ShapeCrawler/Audio/IAudioShape.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using ShapeCrawler.Shapes;

namespace ShapeCrawler.Audio
{
public interface IAudioShape : IShape
{
}
}
4 changes: 4 additions & 0 deletions ShapeCrawler/Collections/IShapeCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.IO;
using ShapeCrawler.Audio;
using ShapeCrawler.Shapes;

namespace ShapeCrawler.Collections
Expand All @@ -19,5 +21,7 @@ public interface IShapeCollection : IEnumerable<IShape>
/// Gets the generic enumerator that iterates through the collection.
/// </summary>
IEnumerator<IShape> GetEnumerator();

IAudioShape AddNewAudio(int x, int y, Stream audioStream);
}
}
Loading

0 comments on commit 8aa78e2

Please sign in to comment.