using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Virinco.WATS.Interface;
using Virinco.WATS;
namespace WATS_API_Test
{
///
/// Summary description for UnitTest1
///
[TestClass]
public class TestApi
{
private static TDM _watsAPI;
private static TDM watsAPI
{
get
{
if (_watsAPI == null) _watsAPI = new TDM();
return _watsAPI;
}
}
public TestApi()
{
}
private TestContext testContextInstance;
///
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext) { watsAPI.InitializeAPI(true); }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
private string randomSerialNumber
{
get
{
Random r = new Random();
return "WAPI" + r.Next(100000).ToString();
}
}
private UUTReport uut;
[TestMethod]
public void CreateUUTReport()
{
SequenceCall repairTest;
StringValueStep repairThisStep=null;
for (int i = 0; i < 1; i++)
{
//Create a UUT Report with minimum information
//uut = watsAPI.CreateUUTReport("testoper", "Partnumber1", "3.4", randomSerialNumber, watsAPI.GetOperationType("10"), "SequenceFile1", "3.4.3");
uut = watsAPI.CreateUUTReport("testoper", "Partnumber1", "3.4", "V-0000000030", watsAPI.GetOperationType("10"), "SequenceFile1", "3.4.3");
//Additional properties can be set
uut.Comment = "Created by Test API program";
uut.BatchSerialNumber = "B1";
uut.FixtureId = "Fix1";
//Add some misc UUT info
uut.AddMiscUUTInfo("SWVer1", "4.2", 0);
//Same way goes for Partinfo:
uut.AddUUTPartInfo("SubPart", "2480230", "9834593458", "2.4");
SequenceCall setup = uut.GetRootSequenceCall().AddSequenceCall("Setup");
//Make this the setup group
setup.StepGroup = StepGroupEnum.Setup;
setup.AddGenericStep(GenericStepTypes.Action,"Set Vin=20V");
setup.AddGenericStep(GenericStepTypes.Wait, "Wait");
setup.AddGenericStep(GenericStepTypes.Action, "Connect CAN");
//Back to the root sequence - create sub-sequence called PowerOn
SequenceCall powerOn = uut.GetRootSequenceCall().AddSequenceCall("PowerOn");
NumericLimitStep internalVoltages = powerOn.AddNumericLimitStep("Internal voltages");
internalVoltages.AddMultipleTest(5.91246554266032, CompOperatorType.GELE, 4, 6.18, "V", "VCC +5V");
internalVoltages.AddMultipleTest(-5.97246554266032, CompOperatorType.GELE, -6.18, -4, "V", "VCC -5V");
internalVoltages.AddMultipleTest(3.76651619730696, CompOperatorType.GELE, 2.5, 4.09, "V", "Reg ref");
NumericLimitStep auxPower = powerOn.AddNumericLimitStep("AUX Power");
auxPower.AddTest(3.53984506724961, CompOperatorType.GELE, 0.1, 9.97, "V");
//Now create chart
Chart chart=auxPower.AddChart(ChartType.LineLogXY, "Test chart", "X-AxisLabel", "X-AxistUnit", "Y-AxisLabel", "Y-Units");
//Populate some values
double[] yValues = new double[100];
Random r = new Random();
for (int x = 0; x < yValues.GetLength(0); x++)
yValues[x] = (double)r.Next(1000);
//Add to chart
chart.AddSeries("Dataset1", yValues);
for (int x = 0; x < yValues.GetLength(0); x++)
yValues[x] = (double)r.Next(1000);
chart.AddSeries("Dataset2", yValues);
SequenceCall temp = uut.GetRootSequenceCall().AddSequenceCall("Temp");
NumericLimitStep numtemp = temp.AddNumericLimitStep("Temp");
numtemp.AddMultipleTest(83.8609375, "", "Mean");
numtemp.AddMultipleTest(84.5, CompOperatorType.LE, 115, "°C", "Max");
numtemp.AddMultipleTest(80.765625, CompOperatorType.GE, 20, "°C", "Min");
chart = numtemp.AddChart(ChartType.Line, "Temp", "Time", "Minutes", "ModuleTemp", "°C");
double[] xValues = new double[5];
yValues = new double[5];
xValues[0]=0; yValues[0]=81;
xValues[1]=50; yValues[1]=84;
xValues[2]=150; yValues[2]=84;
xValues[3]=250; yValues[3]=84.5;
xValues[4]=400; yValues[4]=84;
chart.AddSeries("Temperature", xValues, yValues);
//Like chart, an attachment file can be connected to any step type.
StringValueStep attachFileTest = uut.GetRootSequenceCall().AddStringValueStep("Test attachment (file)");
attachFileTest.AddTest("File attached to string value test");
attachFileTest.AttachFile("WATS_API_Test.dll.config", false);
//Like chart, an attachment byte array can be connected to any step type.
StringValueStep attachByteTest = uut.GetRootSequenceCall().AddStringValueStep("Test attachment (byte)");
attachByteTest.AddTest("Byte array attached to string value test");
attachByteTest.AttachByteArray("This is a string", Encoding.UTF8.GetBytes("Oh yes it is"), "text/plain");
//Pass fail test
uut.GetRootSequenceCall().AddPassFailStep("PassFail").AddTest(true);
//String value test
uut.GetRootSequenceCall().AddStringValueStep("String test").AddTest(CompOperatorType.EQ, "StringValue", "StringValue");
uut.GetRootSequenceCall().AddCallExeStep("Call an exe", 5);
uut.GetRootSequenceCall().AddGenericStep(GenericStepTypes.Semaphore, "Semafor");
uut.GetRootSequenceCall().AddPropertyLoaderStep("PropertyLoader", 2, 3);
SequenceCall failTest = uut.GetRootSequenceCall().AddSequenceCall("WillNotFailTest");
//Do not fail the test even if sequence fails
failTest.FailParentOnFail = false;
failTest.AddNumericLimitStep("FailTest").AddTest(5, CompOperatorType.EQ, 4, "V");
repairTest = uut.GetRootSequenceCall().AddSequenceCall("Step to repair");
repairTest.AddPassFailStep("OKStep").AddTest(true);
repairThisStep = repairTest.AddStringValueStep("FailStep");
repairThisStep.AddTest(CompOperatorType.EQ, "OneValue", "AnotherValue");
//Submit report to WATS
watsAPI.Submit(uut);
}
//Create repair report
UURReport uur = watsAPI.CreateUURReport("repoper", watsAPI.GetRepairTypes()[0], uut);
//Create sub-part
UURPartInfo part2=uur.AddUURPartInfo("SPN1", "0293842", "2.9");
uur.Comment = "Test API Report";
FailCode fc = uur.GetChildFailCodes(uur.GetRootFailcodes()[0])[0];
uur.MiscUURInfo[0].DataString = "WO2974932";
uur.MiscUURInfo[1].DataString = "Gråterudveien 1, Drammen";
//Connect one error to Root step
uur.AddFailure(fc, "R23", "No comment", uut.GetRootSequenceCall().StepOrderNumber);
uur.AddFailure(uur.GetChildFailCodes(uur.GetRootFailcodes()[1])[1], "U13", "Wrong string", repairThisStep.StepOrderNumber);
part2.AddFailure(uur.GetChildFailCodes(uur.GetRootFailcodes()[0])[0],"U27","Replaced",uut.GetRootSequenceCall().StepOrderNumber);
watsAPI.Submit(uur);
}
}
}