Task2.3P CodeV2
Task2.3P CodeV2
IdentifiableObject.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SwinAdventure
{
public class IdentifiableObject
{
List<string> _identifiers;
namespace SwinAdventure
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
UnitTest
UnitTest1.cs
/*
* File: NunitTemplate.cs
* Author: Joshua Wright
* Date: 16/08/2019
* Unit: COS20007 Object Oriented Programming
* Institution: Swinburne University of Technology
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework; //Don't forget this.
using SwinAdventure;
/// <summary>
/// SETUP
/// Use this method to setup the objects you are going to use for each test.
/// This method will be executed before each test is run, "resetting" your
objects/data.
/// </summary>
//For Example:
[SetUp]
public void SetUp()
{
_testableObject = new object();
_testableString = "Some string.";
}
/// <summary>
/// TESTS
/// Use these methods to run tests with only one scenario.
/// Remember to name your test methods appropriately.
/// </summary>
//For Example:
[Test]
public void TestAreYou()
{
IdentifiableObject id = new IdentifiableObject(new string[] { "Ray",
"James" });
bool result = id.AreYou("Ray");
Assert.IsTrue(result);
}
[Test]
public void TestAreYouNot()
{
IdentifiableObject id = new IdentifiableObject(new string[] { "Ray",
"James" });
bool result = id.AreYou("Allen");
Assert.IsFalse(result);
}
[Test]
public void TestAreYouCaseSensitive()
{
IdentifiableObject id = new IdentifiableObject(new string[] { "Ray",
"James" });
bool result = id.AreYou("RAY");
Assert.IsTrue(result);
}
[Test]
public void TestAddID()
{
IdentifiableObject id = new IdentifiableObject(new string[] { "Ray",
"James" });
id.AddIdentifier("Allen");
bool result = id.AreYou("Allen");
Assert.IsTrue(result);
}
/// <summary>
/// TESTCASES
/// Use these methods to run tests when you have multiple scenarios you want
to test.
/// Create parameters to allow you to pass in the unique data you will be
testing
/// against for each scenario.
/// Pass your unique data for each scenario as arugments in each TestCase.
/// Please Note: The data you pass in must be static and cannot be a pointer
to an
/// object instance.
/// The test will run once per TestCase.
/// </summary>
//For Example:
[TestCase("Some string.")] //Scenario 1: Exact match.
[TestCase("SOME sTrInG.")] //Scenario 2: Contains uppercase characters.
[TestCase("some string.")] //Scenario 3: All lowercase characters.
public void TestString(string toTest)
{
StringAssert.AreEqualIgnoringCase(toTest, _testableString, "Testing the
strings are actually the same.");
}
/*
* Don't forget to run the tests using the test explorer.
* How you do this differs slightly depending on what version of VS you are
running
* and what OS you have.
* If you are unsure how to do this, have a google or seek help in the
discussion
* board or at the help desk.
* Happy Testing! :)
*/
}
}
Program.cs
using System;
namespace UnitTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}