test
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"displayName": "Exercise 6: Solution",
|
||||
"description": "In this exercise, you will get practical experience in using the NUnit attributes [SetUp] and [TearDown] in order to reduce code duplication in your tests.",
|
||||
"interactiveImport": true
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14e6e809c045e5b4dadbe47647d8bbd1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MyExercise_6s
|
||||
{
|
||||
public class FileCreator
|
||||
{
|
||||
public const string k_Directory = "OutputFiles";
|
||||
|
||||
public void CreateEmptyFile(string fileName)
|
||||
{
|
||||
CreateFile(fileName, String.Empty);
|
||||
}
|
||||
|
||||
public void CreateFile(string fileName, string content)
|
||||
{
|
||||
using (var stream = File.CreateText(Path.Combine(k_Directory, fileName)))
|
||||
{
|
||||
stream.Write(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 268200e5ee9f8c74b9b960e1bda14838
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "MyExercise_6s"
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb1b776c26fe35d4da82f4975553aa33
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d15077de0c05c843af7b2378165d0f9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,52 @@
|
||||
using System.IO;
|
||||
using MyExercise_6s;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests_6s
|
||||
{
|
||||
internal class FileCreatorTests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Directory.CreateDirectory(FileCreator.k_Directory);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatesEmptyFile()
|
||||
{
|
||||
var fileCreatorUnderTest = new FileCreator();
|
||||
var expectedFileName = "MyEmptyFile.txt";
|
||||
|
||||
fileCreatorUnderTest.CreateEmptyFile(expectedFileName);
|
||||
|
||||
var files = Directory.GetFiles(FileCreator.k_Directory);
|
||||
Assert.That(files.Length, Is.EqualTo(1), "Expected one file.");
|
||||
var expectedFilePath = Path.Combine(FileCreator.k_Directory, expectedFileName);
|
||||
Assert.That(files[0], Is.EqualTo(expectedFilePath));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatesFile()
|
||||
{
|
||||
var fileCreatorUnderTest = new FileCreator();
|
||||
var expectedFileName = "MyFile.txt";
|
||||
var expectedContent = "TheFileContent";
|
||||
|
||||
fileCreatorUnderTest.CreateFile(expectedFileName, expectedContent);
|
||||
|
||||
var files = Directory.GetFiles(FileCreator.k_Directory);
|
||||
Assert.That(files.Length, Is.EqualTo(1), "Expected one file.");
|
||||
var expectedFilePath = Path.Combine(FileCreator.k_Directory, expectedFileName);
|
||||
Assert.That(files[0], Is.EqualTo(expectedFilePath));
|
||||
var content = File.ReadAllText(expectedFilePath);
|
||||
Assert.That(content, Is.EqualTo(expectedContent));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void Teardown()
|
||||
{
|
||||
Directory.Delete(FileCreator.k_Directory, true);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3978b4d8f721a034c94bdbf371445dc0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "Tests_6s",
|
||||
"references": [
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"MyExercise_6s"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": []
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7867a14d4bc9ff645959561ed757454d
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user