Repository navigation
Add Test coverage for XmlCommand.cs - #4201
Conversation
There was a problem hiding this comment.
This is only setting this flag in memory and has no effect on the actual file
593a693 to
a91108f
Compare
There was a problem hiding this comment.
this code is not necessary as ulong.MaxValue is a very large 64-bit number and this check is really only if it overflows
There was a problem hiding this comment.
All the tests pass on Mac
There was a problem hiding this comment.
This can be very fast, possible race condition before we do Stop?
There was a problem hiding this comment.
I can create a larger clixml file to import so that it's more likely StopProcessing() is called during operation and it hasn't completed. Also noticed Get-Process shouldn't be there.
There was a problem hiding this comment.
Used James Truher (@JamesWTruher) code instead
There was a problem hiding this comment.
Should also verify that $deserialized_one.two.three is not null
There was a problem hiding this comment.
Exception will be thrown if .three is null since I'm accessing a member
There was a problem hiding this comment.
ok, will fix
There was a problem hiding this comment.
member access does not produce exception, unless strict mode is set. Method invocation will throw null reference exception.
There was a problem hiding this comment.
Please use Join-Path
There was a problem hiding this comment.
Minor note: The loop has unnecessary nesting and duplication. Consider handling psObject != null and c != null) first to reduce nesting. Something like the following:
object result = _deserializer.Deserialize();
PSObject psObject = result as PSObject;
if (psObject != null)
{
ICollection c = psObject.BaseObject as ICollection;
if (c != null)
{
foreach (object o in c)
{
if (count >= first)
break;
if (skipped++ >= skip)
{
count++;
_cmdlet.WriteObject(o);
}
}
continue;
}
}
if (skipped++ >= skip)
{
count++;
_cmdlet.WriteObject(result);
}
There was a problem hiding this comment.
will fix
|
Steve Lee (@SteveL-MSFT) Your Microsoft org membership is not public. |
|
Travis Plunk (@TravisEz13) the only thing I noticed was that my email wasn't public which I changed |
1202d4d to
b6bf9eb
Compare
There was a problem hiding this comment.
would the following be the same?
$result = get-date | ConvertTo-Xml -NoType
$result.Objects.Object.Type | Should BeNullOrEmptyThere was a problem hiding this comment.
I don't think so. The ConvertTo-Xml cmdlet has a getter for the NoTypeInformation parameter. This is what I'm testing.
There was a problem hiding this comment.
running this in a container could fail (as there will likely not be 5 processes running)
There was a problem hiding this comment.
Good point. I'll change this to Get-Command instead.
There was a problem hiding this comment.
there's some timing issues here, would the following suffice?
$ps = [PowerShell]::Create()
$null = $ps.AddScript("1..10")
$null = $ps.AddCommand("foreach-object")
$null = $ps.AddParameter("Process", { $_; start-sleep 1 })
$null = $ps.AddCommand("Export-CliXml")
$null = $ps.AddParameter("Path", $testfile)
$null = $ps.BeginInvoke()
Start-Sleep 1
$null = $ps.Stop()
$ps.InvocationStateInfo.State | should be "Stopped"
$ps.Dispose()There was a problem hiding this comment.
Thanks, I think that'll work better
There was a problem hiding this comment.
member access does not produce exception, unless strict mode is set. Method invocation will throw null reference exception.
There was a problem hiding this comment.
an alternative approach to lines 126-135
($out2.Name) -join ":" | should be (@($out1.Keys)[1,2] -join ":")
($out2.Value) -join ":" | should be (@($out1.Values)[1,2] -join ":")There was a problem hiding this comment.
Got it, much simpler
c69cc64 to
0b6693c
Compare
|
Aditya Patwardhan (@adityapatwardhan) feedback addressed |
|
Aditya Patwardhan (@adityapatwardhan) Can you update your review? |
removed dead code form XmlCommand added tests
removed necessary get-process and increased content of xml to be imported to avoid race condition fixed issues in XmlCommand not working correctly for -First and -Skip removed dead code form XmlCommand
08286b6 to
80b6397
Compare
|
Finally successfully got updated code coverage numbers: ConvertToXmlCommand 100% |

fixed issues in XmlCommand not working correctly for -First and -Skip
removed dead code form XmlCommand
added tests
I'll see if I can get some code coverage data
Fix #4152