Skip to content

Commit

Permalink
testing to resolve error with unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
cwduncan committed Apr 15, 2024
1 parent 6e8796e commit ea2dba4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions src/Persistence.Tests/MsApp/MsappArchiveSaveTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.IO.Compression;
using Microsoft.PowerPlatform.PowerApps.Persistence.MsApp;

namespace Persistence.Tests.MsApp;
Expand Down Expand Up @@ -138,27 +139,30 @@ public void Msapp_ShouldSave_WithUniqueName()
}

[TestMethod]
[DataRow("HelloWorld", "HelloScreen")]
public void Msapp_ShouldSaveAs_NewFilePath(string appName, string screenName)
[DataRow(@"_TestData/AppsWithYaml/HelloWorld.msapp", "HelloWorld", "HelloScreen")]
public void Msapp_ShouldSaveAs_NewFilePath(string testDirectory, string appName, string screenName)
{
// Arrange
var tempFile = Path.Combine(TestContext.DeploymentDirectory!, Path.GetRandomFileName());
var tempFileTwo = Path.Combine(TestContext.DeploymentDirectory!, Path.GetRandomFileName());
using (var msappArchive = MsappArchiveFactory.Create(tempFile))
{
msappArchive.App.Should().BeNull();

// Act
var app = ControlFactory.CreateApp(appName);
app.Screens.Add(ControlFactory.CreateScreen(screenName));
msappArchive.App = app;

msappArchive.SaveAs(tempFileTwo);
// Zip archive in memory from folder
using var stream = new MemoryStream();
using (var zipArchive = new ZipArchive(stream, ZipArchiveMode.Create, true))
{
var files = Directory.GetFiles(testDirectory, "*", SearchOption.AllDirectories);
foreach (var file in files)
{
zipArchive.CreateEntryFromFile(file, file.Substring(testDirectory.Length + 1));
}
}
using var testApp = MsappArchiveFactory.Update(stream, overwriteOnSave: true);

// Save the test app to another file
testApp.SaveAs(tempFile);
// Open the app from the file
using var msappValidation = MsappArchiveFactory.Open(tempFile);

// Assert
File.Exists(tempFile).Should().BeFalse();
using var msappValidation = MsappArchiveFactory.Open(tempFileTwo);
msappValidation.App.Should().NotBeNull();
msappValidation.App!.Screens.Count.Should().Be(1);
msappValidation.App.Screens.Single().Name.Should().Be(screenName);
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/MsApp/MsappArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public void SaveAs(string filePath)
throw new InvalidOperationException("File already exists but overwrite is not enabled");
}

using var fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);
var fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);
SaveAs(fileStream);
}

Expand Down

0 comments on commit ea2dba4

Please sign in to comment.