CodeGen creates empty mapper file on the first build - mapster

When I decorate my domain class with [AdaptTo("[name]Dto"), GenerateMapper] everything works fine, but when I use:
public class MappingRegister : ICodeGenerationRegister
{
public void Register(CodeGenerationConfig config)
{
config.AdaptTo("[name]Read")
.ForType<Command>();
config.GenerateMapper("[name]Mapper")
.ForType<Command>();
}
}
it generates the same dto class as with an attribute, but the mapper class is empty:
public static partial class CommandMapper
{
}
What do I miss?
Update
So the issue that I have is not with attribute vs ICodeGenerationRegister implementation, but the fact that I have to run the build twice. The First time it generates an empty mapper class and on the second build, I get the extension methods generated.
Here is my project config
...
<Target Name="Mapster" AfterTargets="AfterBuild">
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster model -a "$(TargetDir)$(ProjectName).dll" -n Commands.Dtos -o Dtos" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -a "$(TargetDir)$(ProjectName).dll" -n Commands.Dtos -o Dtos" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a "$(TargetDir)$(ProjectName).dll" -n Commands.Dtos -o Dtos" />
</Target>
...
Mapster tool version 8.0.1

Related

ASP.Net Core React spa integration test

Asp.Net Core integration testing seems pretty simple but for the life of me I can't test the starter app with my react dev server. It runs fine from a browser so I assume node, npm and react are set up correctly but not under xUnit. It fails with the following exception:
System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Failed to start 'npm'. To resolve this:.
[1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
Current PATH enviroment variable is: {PATH}
Make sure the executable is in one of those directories, or update your PATH.
[2] See the InnerException for further details of the cause. ---> System.ComponentModel.Win32Exception: The directory name is invalid
...
I assume this is because it can't find the content root of my spa so I have tried adding to my web host builder with no luck:
.UseSolutionRelativeContentRoot( "Solution Relative Path to My App" ) );
This is my test class:
public class SampleDataControllerTest
{
private readonly TestServer server;
private readonly HttpClient client;
public SampleDataControllerTest()
{
server = new TestServer( WebHost.CreateDefaultBuilder()
.UseStartup<Startup>()
.UseSolutionRelativeContentRoot( "Solution Relative Path to My App" ) );
.UseEnvironment( "Development" );
client = server.CreateClient();
}
[Fact]
public async Task RootTest()
{
HttpResponseMessage page = await client.GetAsync( "/" );
Assert.NotNull( page );
Assert.Equal( HttpStatusCode.OK, page.StatusCode );
}
What am I missing?
The trick for me was setting the development environment variable to point to the directory where the packages.json file resides.
Below is an excerpt of the constructor of my xUnit integration test class.
Note that it first determines the solution directory (using GetExecutingAssembly().Location), and then points to the web source project folder. (In our environment, Client.React is a directory under the solution directory that contains the packages.json file).
Then, the directory is set using Directory.SetCurrentDirectory, followed by the test server being set up wit hthe UseWebRoot, again pointing to the directory where the packages.json file resides.
Startup is the ASP.NET web startup class.
/// <summary>
/// Constructor
/// </summary>
public IntegrationTest() : base()
{
var testAssemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
// Remove the "\\bin\\Debug\\netcoreapp2.1"
var solutionPath = Directory.GetParent(testAssemblyPath.Substring(0, testAssemblyPath.LastIndexOf(#"\bin\", StringComparison.Ordinal))).FullName;
var clientReactPath = Path.Join(solutionPath, "Client.React");
// Important to ensure that npm loads and is pointing to correct directory
Directory.SetCurrentDirectory(clientReactPath);
var server = new TestServer(new WebHostBuilder()
.UseEnvironment("Development")
.UseWebRoot(clientReactPath)
.UseStartup<Startup>());
_client = server.CreateClient();
}

how to proguard prevent from stripping array

I have implemented gooeymenu in a layout file:
<com.mschwartz.dailyflightbuddy.ui.GooeyMenu
android:id="#+id/gooeymenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/btn_text_cockpit"
android:layout_centerInParent="true"
android:alpha="0.8"
app:center_drawable="#drawable/ic_settings_white_48dp"
app:hide_on_start="true"
app:itemorientation="LEFT"
app:menu_reference="#array/gooeymenu_command_array" />
The menu_reference tag points to a file res/values/array.xml with the following content:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="gooeymenu_command_array">
<item>#drawable/gooey_info_item</item>
<item>#drawable/gooey_zoom_item</item>
<item>#drawable/gooey_center_item</item>
<item>#drawable/gooey_city_item</item>
<item>#drawable/gooey_airport_item</item>
<item>#drawable/gooey_configure_item</item>
</array>
</resources>
When running in the debugger everything works fine but when running from the stripped production version gooeymenu does not show any items.
I have tried to add several commands to proguard-rules.pro including the following:
-keepclassmembers class com.mschwartz.dailyflightbuddy.R$array {
*;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
but without any luck so far. So my questions are:
How can I verify if the fields have really been stripped from the
production apk or how can I make sure if a field (or more common a class/method) is included?
How can I command proguard to add the fields?
The problem was that I use an ObjectAnimator which changes the property of an object by referencing the method by its name:
'ObjectAnimator animShowAlpha = ObjectAnimator.ofFloat(circlePoint, "Alpha", 0.0f, 1.0f);'
proguard however mangles the names of the objects and hence the method CirclePoint.setAlpha(..) was renamed to a(..). So the solution was to add a line to proguard to prevent renaming the methods of the class CirclePoint:
-keep class com.mschwartz.dailyflightbuddy.ui.GooeyMenu$CirclePoint { *; }
That's it.
btw. To see if proguard renames a method or not the file 'app/build/outputs/mapping/release/mapping.txt' is of great help (and self-explanatory).

how to run cron job in cakephp

I am trying to delete data from database using cron job in cakephp . I have created a TestShell.php file at /app/Console/Command/TestShell.php with the following code:
<?php
class TestShell extends AppShell {
public $uses = array('BillsReceivable');
public function main() {
$this->BillsReceivable->deleteAll(array(
'BillsReceivable.days >='=>30,
));
$this->out('Records deleted..');
}
}
My cron command is:
/home/bigzip/public_html/TimeZip/app/Console/cake -app /home/bigzip/public_html/TimeZip/app TestShell
but its not working.please help.
cd /home/bigzip/public_html/TimeZip/app/
sudo Console/cake test
cakephp cron job
cd /full/path/to/app && Console/cake myshell myparam
-working defines the working directory
/home/bigzip/public_html/TimeZip/app/Console/cake.php -app /home/bigzip/public_html/TimeZip/app -working /home/bigzip/public_html/TimeZip/app TestShell
The above code should help you out

DebugKit.ToolbarComponent could not be found

I followed the instruction in the README.md file in the directory DebugKit. But when I add this line I am getting this error above but when i comment out the line in the AppController then everything is ok and i'm getting "DebugKit plugin is present"
<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array('DebugKit.Toolbar');
}
does anyone know how can i smooth this error out?
I have ubuntu 14.10 CakePHP 2.5
Make sure you have
\DebugKit
\Controller
\Component
\ToolbarComponent.php
In case you don't have this directory (which was the case for me)
then
cd Plugin/DebugKit
sudo mkdir Controller
sudo mkdir Component
sudo gedit ToolbarComponent.php
And then the text editor will pop up and just put the code below
<?php
class ToolbarComponent extends Component {
}

how to call testng.xml from java main method?

I have testng.xml file created.
Is there any way to run this file from java main method?
Something like -
Class test {
public static void main ( String [ ] args)
{
Run(testng.xml);
}
}
You can run testng directly from commandline, probably make a bat file on top of it or use jenkins to trigger it. Refer here
or
If you want it in main, then you can try
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add("c:/tests/testng1.xml");//path to xml..
suites.add("c:/tests/testng2.xml");
testng.setTestSuites(suites);
testng.run();
Please try below code and make sure you have testNG jar added in your jar manifest file.
public static void main(String[] args)
{
org.testng.TestNG.main(args);
}
now you can pass all the parameters to your jar which are same for testNG jar file.
e.g.
java -jar yourjar.jar testng.xml
or
java -jar yourjar.jar -testclass org.test.xyz.java
This work for me. More details here.
// Create object of TestNG Class
TestNG runner=new TestNG();
// Create a list of String
List<String> suitefiles=new ArrayList<String>();
// Add xml file which you have to execute
suitefiles.add("C:\\Automation Test\\Git\\vne_automation\\testng.xml");
// now set xml file for execution
runner.setTestSuites(suitefiles);
// finally execute the runner using run method
runner.run();
Hope this helps!
All the answers above works like a charm but there is one limitation that
it would run unless and untill you remove the scope tag in pom.xml
In pom.xml there would be maven dependancy for testNg and in there
there would be one scope tag which limits our jar to only upto test
Just remove that one
I didn't get any error and XML path is correct. But It just end execution with failed test cases. It does not open firefox browser.
I am using testng annotation (i.e. #Before Suite,#Test, #group etc ) inside classes whereas it successfully execute using Testng Suite in eclipse.
<!-- suite name="Example" parallel="methods" thread-count="2" parallel="false" preserve-order="true"> -->
<suite name="Example Donate System" verbose='1'>
<test name="Agency" >
<packages>
<package name="com.Donatesystem.AgencyController" />
</packages>
</test>
</suite>

Resources