Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Expressium.Configurations;
using Expressium.ObjectRepositories;
using NUnit.Framework;

namespace Expressium.CodeGenerators.Java.Playwright.UnitTests
{
[TestFixture]
public class CodeGeneratorFactoryTests
{
private Configuration configuration;
private ObjectRepository objectRepository;
private ObjectRepositoryPage page;

private CodeGeneratorFactory codeGeneratorFactory;

[OneTimeSetUp]
public void Setup()
{
configuration = new Configuration();
configuration.Company = "Expressium";
configuration.Project = "Coffeeshop";

page = new ObjectRepositoryPage();
page.Name = "RegistrationPage";
page.Title = "Registration";
page.Model = true;
page.Controls.Add(new ObjectRepositoryControl() { Name = "FirstName", Type = ControlTypes.TextBox.ToString(), How = ControlHows.Name.ToString(), Using = "firstname", Value = "Hugoline" });
page.Controls.Add(new ObjectRepositoryControl() { Name = "LastName", Type = ControlTypes.TextBox.ToString(), How = ControlHows.Name.ToString(), Using = "lastname" });
page.Controls.Add(new ObjectRepositoryControl() { Name = "Country", Type = ControlTypes.ComboBox.ToString(), How = ControlHows.Name.ToString(), Using = "country", Value = "Denmark" });
page.Controls.Add(new ObjectRepositoryControl() { Name = "Male", Type = ControlTypes.RadioButton.ToString(), How = ControlHows.Id.ToString(), Using = "gender_0", Value = "False" });
page.Controls.Add(new ObjectRepositoryControl() { Name = "Female", Type = ControlTypes.RadioButton.ToString(), How = ControlHows.Id.ToString(), Using = "gender_1", Value = "True" });
page.Controls.Add(new ObjectRepositoryControl() { Name = "IAgreeToTheTermsOfUse", Type = ControlTypes.CheckBox.ToString(), How = ControlHows.Name.ToString(), Using = "agreement" });

objectRepository = new ObjectRepository();
objectRepository.AddPage(page);

codeGeneratorFactory = new CodeGeneratorFactory(configuration, objectRepository);
}

[Test]
public void CodeGeneratorFactoryJavaPlaywright_GenerateSourceCode()
{
var listOfLines = codeGeneratorFactory.GenerateSourceCode(page);

Assert.That(listOfLines.Count, Is.EqualTo(21), "CodeGeneratorFactoryJavaPlaywright GenerateSourceCode validation");
}

[Test]
public void CodeGeneratorFactoryJavaPlaywright_GeneratePackage()
{
var listOfLines = codeGeneratorFactory.GeneratePackage();

Assert.That(listOfLines.Count, Is.EqualTo(1), "CodeGeneratorFactoryJavaPlaywright GeneratePackage validation");
Assert.That(listOfLines[0], Is.EqualTo("package expressium.coffeeshop.web.api.factories;"), "CodeGeneratorFactoryJavaPlaywright GeneratePackage validation");
}

[Test]
public void CodeGeneratorFactoryJavaPlaywright_GenerateClass()
{
var listOfLines = codeGeneratorFactory.GenerateClass(page);

Assert.That(listOfLines.Count, Is.EqualTo(1), "CodeGeneratorFactoryJavaPlaywright GenerateClass validation");
Assert.That(listOfLines[0], Is.EqualTo("public class RegistrationPageModelFactory"), "CodeGeneratorFactoryJavaPlaywright GenerateClass validation");
}

[Test]
public void CodeGeneratorFactoryJavaPlaywright_GenerateDefaultMethod()
{
var listOfLines = codeGeneratorFactory.GenerateDefaultMethod(page);

Assert.That(listOfLines.Count, Is.EqualTo(14), "CodeGeneratorFactoryJavaPlaywright GenerateDefaultMethod validation");
Assert.That(listOfLines[0], Is.EqualTo("public static RegistrationPageModel getDefault() {"), "CodeGeneratorFactoryJavaPlaywright GenerateDefaultMethod validation");
Assert.That(listOfLines[1], Is.EqualTo("RegistrationPageModel model = new RegistrationPageModel();"), "CodeGeneratorFactoryJavaPlaywright GenerateDefaultMethod validation");
Assert.That(listOfLines[5], Is.EqualTo("model.setFirstName(\"Hugoline\");"), "CodeGeneratorFactoryJavaPlaywright GenerateDefaultMethod validation");
Assert.That(listOfLines[8], Is.EqualTo("model.setMale(false);"), "CodeGeneratorFactoryJavaPlaywright GenerateDefaultMethod validation");
Assert.That(listOfLines[9], Is.EqualTo("model.setFemale(true);"), "CodeGeneratorFactoryJavaPlaywright GenerateDefaultMethod validation");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Expressium.Configurations;
using Expressium.ObjectRepositories;
using NUnit.Framework;

namespace Expressium.CodeGenerators.Java.Playwright.UnitTests
{
[TestFixture]
public class CodeGeneratorModelTests
{
private Configuration configuration;
private ObjectRepository objectRepository;
private ObjectRepositoryPage page;

private CodeGeneratorModel codeGeneratorModel;

[OneTimeSetUp]
public void Setup()
{
configuration = new Configuration();
configuration.Company = "Expressium";
configuration.Project = "Coffeeshop";

page = new ObjectRepositoryPage();
page.Name = "RegistrationPage";
page.Title = "Registration";
page.Model = true;
page.Controls.Add(new ObjectRepositoryControl() { Name = "FirstName", Type = ControlTypes.TextBox.ToString(), How = ControlHows.Name.ToString(), Using = "firstname" });
page.Controls.Add(new ObjectRepositoryControl() { Name = "LastName", Type = ControlTypes.TextBox.ToString(), How = ControlHows.Name.ToString(), Using = "lastname" });
page.Controls.Add(new ObjectRepositoryControl() { Name = "Country", Type = ControlTypes.ComboBox.ToString(), How = ControlHows.Name.ToString(), Using = "country", Value = "Denmark" });
page.Controls.Add(new ObjectRepositoryControl() { Name = "Male", Type = ControlTypes.RadioButton.ToString(), How = ControlHows.Id.ToString(), Using = "gender_0", Value = "False" });
page.Controls.Add(new ObjectRepositoryControl() { Name = "Female", Type = ControlTypes.RadioButton.ToString(), How = ControlHows.Id.ToString(), Using = "gender_1", Value = "True" });
page.Controls.Add(new ObjectRepositoryControl() { Name = "IAgreeToTheTermsOfUse", Type = ControlTypes.CheckBox.ToString(), How = ControlHows.Name.ToString(), Using = "agreement" });

objectRepository = new ObjectRepository();
objectRepository.AddPage(page);

codeGeneratorModel = new CodeGeneratorModel(configuration, objectRepository);
}

[Test]
public void CodeGeneratorModelJavaPlaywright_GenerateSourceCode()
{
var listOfLines = codeGeneratorModel.GenerateSourceCode(page);

Assert.That(listOfLines.Count, Is.EqualTo(63), "CodeGeneratorModelJavaPlaywright GenerateSourceCode validation");
}

[Test]
public void CodeGeneratorModelJavaPlaywright_GeneratePackage()
{
var listOfLines = codeGeneratorModel.GeneratePackage();

Assert.That(listOfLines.Count, Is.EqualTo(1), "CodeGeneratorModelJavaPlaywright GeneratePackage validation");
Assert.That(listOfLines[0], Is.EqualTo("package expressium.coffeeshop.web.api.models;"), "CodeGeneratorModelJavaPlaywright GeneratePackage validation");
}

[Test]
public void CodeGeneratorModelJavaPlaywright_GenerateClass()
{
var listOfLines = codeGeneratorModel.GenerateClass(page);

Assert.That(listOfLines.Count, Is.EqualTo(1), "CodeGeneratorModelJavaPlaywright GenerateClass validation");
Assert.That(listOfLines[0], Is.EqualTo("public class RegistrationPageModel"), "CodeGeneratorModelJavaPlaywright GenerateClass validation");
}

[Test]
public void CodeGeneratorModelJavaPlaywright_GenerateFields()
{
var listOfLines = codeGeneratorModel.GenerateFields(page);

Assert.That(listOfLines.Count, Is.EqualTo(6), "CodeGeneratorModelJavaPlaywright GenerateFields validation");
Assert.That(listOfLines[0], Is.EqualTo("private String firstName;"), "CodeGeneratorModelJavaPlaywright GenerateFields validation");
Assert.That(listOfLines[1], Is.EqualTo("private String lastName;"), "CodeGeneratorModelJavaPlaywright GenerateFields validation");
Assert.That(listOfLines[2], Is.EqualTo("private String country;"), "CodeGeneratorModelJavaPlaywright GenerateFields validation");
Assert.That(listOfLines[3], Is.EqualTo("private boolean male;"), "CodeGeneratorModelJavaPlaywright GenerateFields validation");
Assert.That(listOfLines[4], Is.EqualTo("private boolean female;"), "CodeGeneratorModelJavaPlaywright GenerateFields validation");
Assert.That(listOfLines[5], Is.EqualTo("private boolean iAgreeToTheTermsOfUse;"), "CodeGeneratorModelJavaPlaywright GenerateFields validation");
}

[Test]
public void CodeGeneratorModelJavaPlaywright_GenerateAccessors()
{
var listOfLines = codeGeneratorModel.GenerateAccessors(page);

Assert.That(listOfLines.Count, Is.EqualTo(48), "CodeGeneratorModelJavaPlaywright GenerateAccessors validation");
Assert.That(listOfLines[0], Is.EqualTo("public String getFirstName() {"), "CodeGeneratorModelJavaPlaywright GenerateAccessors validation");
Assert.That(listOfLines[4], Is.EqualTo("public void setFirstName(String value) {"), "CodeGeneratorModelJavaPlaywright GenerateAccessors validation");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
using Expressium.Configurations;
using Expressium.ObjectRepositories;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;

namespace Expressium.CodeGenerators.Java.Playwright.UnitTests
{
[TestFixture]
public class CodeGeneratorObjectTests
{
[Test]
public void Configuration_GetPackage()
{
var configuration = new Configuration();
configuration.Company = "Expressium";
configuration.Project = "Coffeeshop";

var codeGeneratorObject = new CodeGeneratorObject(configuration, null);
var result = codeGeneratorObject.GetPackage();
var expected = "expressium.coffeeshop.web.api";

Assert.That(result, Is.EqualTo(expected), "Configuration GetPackage validate generated output");
}

[Test]
public void Configuration_GetPackagePath()
{
var configuration = new Configuration();
configuration.Company = "Expressium";
configuration.Project = "Coffeeshop";

var codeGeneratorObject = new CodeGeneratorObject(configuration, null);
var result = codeGeneratorObject.GetPackagePath();
var expected = "expressium/coffeeshop/web/api";

Assert.That(result, Is.EqualTo(expected), "Configuration GetPackagePath validate generated output");
}

[Test]
public void CodeGeneratorObject_GetSourceCodeAsFormatted()
{
var input = new List<string>
{
"public class AssetsBar extends BasePage",
"{",
"public boolean assetsBar(boolean value)",
"{",
"if (value)",
"return true;",
"else if (!value)",
"return false;",
"else",
"return false;",
"",
"if (x)",
"if (y)",
"return true;",
"",
"while (a==b)",
"continue;",
"",
"for (int i=0; i<count; i++)",
"boolean x = true;",
"}",
"}"
};

var expected = new List<string>
{
"public class AssetsBar extends BasePage",
"{",
" public boolean assetsBar(boolean value)",
" {",
" if (value)",
" return true;",
" else if (!value)",
" return false;",
" else",
" return false;",
"",
" if (x)",
" if (y)",
" return true;",
"",
" while (a==b)",
" continue;",
"",
" for (int i=0; i<count; i++)",
" boolean x = true;",
" }",
"}"
};

var result = CodeGeneratorObject.GetSourceCodeAsFormatted(input);
Assert.That(result, Is.EqualTo(expected), "CodeGeneratorObject GetSourceCodeAsFormatted validation");
}

[Test]
public void CodeGeneratorObject_GetSourceCodeAsString()
{
var input = new List<string>
{
"<Model>",
"<Attribute name='FaultLocation'>",
"</Model>"
};

var expected = "<Model>\r\n<Attribute name='FaultLocation'>\r\n</Model>";

var result = CodeGeneratorObject.GetSourceCodeAsString(input);
Assert.That(result, Is.EqualTo(expected), "CodeGeneratorObject GetSourceCodeAsString validation");
}

[Test]
public void ConfigurationObject_GenerateSourceCodeExtensionMethods()
{
var listOfLines = CodeGeneratorObject.GenerateSourceCodeExtensionMethods(null, "// region Extensions", "// endregion");

Assert.That(listOfLines.Count, Is.EqualTo(3), "CodeGeneratorObject GenerateSourceCodeExtensionMethods validation");
}

[Test]
public void ConfigurationObject_GenerateSourceCodeExtensionMethods_With_File()
{
var directory = Environment.GetEnvironmentVariable("TEMP");
var filePath = Path.Combine(directory, "SnippetJavaPlaywright.txt");
File.Delete(filePath);
File.WriteAllText(filePath, "// region Extensions\n\n// This is my life...\n\n// endregion\n");

var listOfLines = CodeGeneratorObject.GenerateSourceCodeExtensionMethods(filePath, "// region Extensions", "// endregion");

Assert.That(listOfLines.Count, Is.EqualTo(5), "CodeGeneratorObject GenerateSourceCodeExtensionMethods validation");
Assert.That(listOfLines[0], Is.EqualTo("// region Extensions"), "CodeGeneratorObject GenerateSourceCodeExtensionMethods validation");
Assert.That(listOfLines[2], Is.EqualTo("// This is my life..."), "CodeGeneratorObject GenerateSourceCodeExtensionMethods validation");
Assert.That(listOfLines[4], Is.EqualTo("// endregion"), "CodeGeneratorObject GenerateSourceCodeExtensionMethods validation");
}

[Test]
public void CodeGeneratorObject_IsSourceCodeModified_With_Comment()
{
var directory = Environment.GetEnvironmentVariable("TEMP");
var filePath = Path.Combine(directory, "ExportPageJavaPlaywright.txt");

File.Delete(filePath);
File.WriteAllText(filePath, "// TODO - Implement...");

Assert.That(CodeGeneratorObject.IsSourceCodeModified(filePath), Is.False, "CodeGeneratorObject IsSourceCodeModified validation");
}

[Test]
public void CodeGeneratorObject_IsSourceCodeModified_Without_Comment()
{
var directory = Environment.GetEnvironmentVariable("TEMP");
var filePath = Path.Combine(directory, "ImportPageJavaPlaywright.txt");

File.Delete(filePath);
File.WriteAllText(filePath, "// TODO - Updated...");

Assert.That(CodeGeneratorObject.IsSourceCodeModified(filePath), Is.True, "CodeGeneratorObject IsSourceCodeModified validation");
}
}
}
Loading