Skip to content

Commit

Permalink
Marked more tests in DataAccess with requirement ids
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasstich committed May 22, 2024
1 parent 1086cf7 commit 28e47de
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
40 changes: 21 additions & 19 deletions DataAccessTest/API/DataAccessUt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void Standard_AllPropertiesInitialized()
}

[Test]
// ANF-ID: [ASE6]
public void SaveLearningWorldToFile_CallsFileSaveHandlerWorld()
{
var mockFileSaveHandlerWorld = Substitute.For<IXmlFileHandler<LearningWorldPe>>();
Expand All @@ -69,6 +70,7 @@ public void SaveLearningWorldToFile_CallsFileSaveHandlerWorld()
}

[Test]
// ANF-ID: [ASE2]
public void LoadLearningWorldFromFile_CallsFileSaveHandlerWorld()
{
var mockFileSaveHandlerWorld = Substitute.For<IXmlFileHandler<LearningWorldPe>>();
Expand All @@ -80,6 +82,7 @@ public void LoadLearningWorldFromFile_CallsFileSaveHandlerWorld()
}

[Test]
// ANF-ID: [ASE2]
public void LoadLearningWorldFromStream_CallsFileSaveHandlerWorld()
{
var mockFileSaveHandlerWorld = Substitute.For<IXmlFileHandler<LearningWorldPe>>();
Expand Down Expand Up @@ -330,7 +333,7 @@ public async Task ExportLearningWorldToArchive_ConstructsZipCorrectly()

var expectedZip = ZipExtensions.GetZipArchive(filesystem, "C:\\export_test.zip");
Assert.That(expectedZip.Entries, Has.Count.EqualTo(3));

var png = expectedZip.Entries[1];
using var pngMemStream = new MemoryStream();
png.Open().CopyTo(pngMemStream);
Expand All @@ -343,7 +346,7 @@ public async Task ExportLearningWorldToArchive_ConstructsZipCorrectly()
using var worldMemStream = new MemoryStream();
world.Open().CopyTo(worldMemStream);
var worldData = worldMemStream.ToArray();

Assert.Multiple(() =>
{
Assert.That(png.Name, Is.EqualTo("adler_logo.png"));
Expand All @@ -370,18 +373,17 @@ public void GetAllContent_CallsContentFileHandlerAndMapper()
contentFileHandler.GetAllContent().Returns(content);
mapper.Map<ILearningContent>(content[0]).Returns(contentEntities[0]);
mapper.Map<ILearningContent>(content[1]).Returns(contentEntities[1]);

var systemUnderTest = CreateTestableDataAccess(contentHandler: contentFileHandler, mapper: mapper);

var retval = systemUnderTest.GetAllContent();

Assert.That(retval, Is.EquivalentTo(contentEntities));
contentFileHandler.Received().GetAllContent();
mapper.Received().Map<ILearningContent>(content[0]);
mapper.Received().Map<ILearningContent>(content[1]);

}

[Test]
public void RemoveContent_CallsContentFileHandlerAndMapper()
{
Expand All @@ -390,11 +392,11 @@ public void RemoveContent_CallsContentFileHandlerAndMapper()
var content = EntityProvider.GetFileContent();
var contentPe = PersistEntityProvider.GetFileContent();
mapper.Map<ILearningContentPe>(content).Returns(contentPe);

var systemUnderTest = CreateTestableDataAccess(contentHandler: contentFileHandler, mapper: mapper);

systemUnderTest.RemoveContent(content);

contentFileHandler.Received().RemoveContent(contentPe);
mapper.Received().Map<ILearningContentPe>(content);
}
Expand All @@ -407,11 +409,11 @@ public void SaveLink_CallsContentFileHandlerAndMapper()
var link = EntityProvider.GetLinkContent();
var linkPe = PersistEntityProvider.GetLinkContent();
mapper.Map<LinkContentPe>(link).Returns(linkPe);

var systemUnderTest = CreateTestableDataAccess(contentHandler: contentFileHandler, mapper: mapper);

systemUnderTest.SaveLink(link);

contentFileHandler.Received().SaveLink(linkPe);
mapper.Received().Map<LinkContentPe>(link);
}
Expand All @@ -421,9 +423,9 @@ public void GetContentFilesFolderPath_CallsContentFileHandler()
{
var contentFileHandler = Substitute.For<IContentFileHandler>();
contentFileHandler.ContentFilesFolderPath.Returns("foobarbaz");

var systemUnderTest = CreateTestableDataAccess(contentHandler: contentFileHandler);

Assert.That(systemUnderTest.GetContentFilesFolderPath(), Is.EqualTo("foobarbaz"));
}

Expand All @@ -434,9 +436,9 @@ public void GetFileInfoForPath_CallsFileSystem()
var fileInfo = Substitute.For<IFileInfo>();
filesystem.FileInfo.New("foo").Returns(fileInfo);
var systemUnderTest = CreateTestableDataAccess(fileSystem: filesystem);

var actualFileInfo = systemUnderTest.GetFileInfoForPath("foo");

Assert.That(actualFileInfo, Is.EqualTo(fileInfo));
filesystem.FileInfo.Received().New("foo");
}
Expand All @@ -446,9 +448,9 @@ public void DeleteFileByPath_CallsFileSystem()
{
var filesystem = Substitute.For<IFileSystem>();
var systemUnderTest = CreateTestableDataAccess(fileSystem: filesystem);

systemUnderTest.DeleteFileByPath("foo");

filesystem.File.Received().Delete("foo");
}

Expand Down
9 changes: 5 additions & 4 deletions DataAccessTest/Persistence/LearningWorldSavePathsHandlerUt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ public void Constructor_InitializesAllProperties()
Assert.That(systemUnderTest.FileSystem, Is.EqualTo(fileSystem));
});
}

[Test]
// ANF-ID: [ASE5]
public void GetSavedLearningWorldPaths_ReturnsAllWorldFiles()
{
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
{
{ApplicationPaths.SavedWorldsFolder + "/world1.awf", new MockFileData("world1")},
{ApplicationPaths.SavedWorldsFolder + "/world2.awf", new MockFileData("world2")},
{ApplicationPaths.SavedWorldsFolder + "/world3.txt", new MockFileData("world3")},
{ ApplicationPaths.SavedWorldsFolder + "/world1.awf", new MockFileData("world1") },
{ ApplicationPaths.SavedWorldsFolder + "/world2.awf", new MockFileData("world2") },
{ ApplicationPaths.SavedWorldsFolder + "/world3.txt", new MockFileData("world3") },
});
var systemUnderTest = CreateTestableLearningWorldSavePathsHandler(fileSystem: fileSystem);

Expand Down
5 changes: 5 additions & 0 deletions DataAccessTest/Persistence/PersistenceCt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PersistenceCt
private const string FilePath = "awesomefile.txt";

[Test]
// ANF-ID: [ASE2, ASE6]
public void Persistence_SaveAndLoadWorld_Stream_ObjectsAreEquivalent()
{
var world = PersistEntityProvider.GetLearningWorld();
Expand Down Expand Up @@ -167,6 +168,7 @@ public void Persistence_SaveAndLoadElement_Stream_ObjectsAreEquivalent()
}

[Test]
// ANF-ID: [ASE2, AWA0022, AHO66]
public void Persistence_SaveAndLoadWorld_File_ObjectsAreEquivalent()
{
var world = PersistEntityProvider.GetLearningWorld();
Expand Down Expand Up @@ -354,6 +356,7 @@ static ILearningElementPe[] GetAllLearningElementTypes()
}

[Test]
// ANF-ID: [ASE2, AWA0022, AWA0019]
public void SaveAndLoadWorld_WithExactSameElementInTwoSpaces_ElementIsEqualObject()
{
var content = PersistEntityProvider.GetFileContent();
Expand Down Expand Up @@ -392,6 +395,7 @@ public void SaveAndLoadWorld_WithExactSameElementInTwoSpaces_ElementIsEqualObjec
}

[Test]
// ANF-ID: [ASE2, AWA0018]
public void SaveAndLoadWorld_WithTwoEquivalentElementsInTwoSpaces_ElementIsNotEqualObject()
{
var content = PersistEntityProvider.GetFileContent();
Expand Down Expand Up @@ -431,6 +435,7 @@ public void SaveAndLoadWorld_WithTwoEquivalentElementsInTwoSpaces_ElementIsNotEq
}

[Test]
// ANF-ID: [ASE2, AWA0019]
public void SaveAndLoadWorld_WithAdaptivityContentElement_RestoresCorrectly()
{
var content = PersistEntityProvider.GetAdaptivityContentFullStructure();
Expand Down

0 comments on commit 28e47de

Please sign in to comment.