Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Active TDD test cases after some issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
BingyuLiu committed Aug 5, 2016
1 parent fa4d64d commit 8e7928c
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,10 @@ public void SetCustomOption(string optionName, object optionValue, CimType cimTy
}
this.AssertNotDisposed();

MI_Value nativeLayerValue = ValueHelpers.ConvertToNativeLayer(optionValue, cimType);
MI_Value nativeLayerValue;
try
{
nativeLayerValue = ValueHelpers.ConvertToNativeLayer(optionValue, cimType);
ValueHelpers.ThrowIfMismatchedType(cimType.FromCimType(), nativeLayerValue);
}
catch (InvalidCastException e)
Expand Down
14 changes: 3 additions & 11 deletions test/Microsoft.Management.Infrastructure.Tests/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,9 @@ public static byte[] GetBytesFromString(string str)
/// <returns></returns>
public static byte[] GetBytesFromFile(string filePath)
{
using (FileStream fs = File.OpenRead(filePath))
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
// FileStream.close method is not supported in .net core currently.
#if !_LINUX
fs.Close();
#else
#endif
return bytes;
}
string s = File.ReadAllText(filePath);
System.Text.UTF8Encoding encoding = new UTF8Encoding();
return encoding.GetBytes(s);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,6 @@ public void Constructor_ClassDecl_Null()
#endregion Test constructor

#region Test properties
[TDDFact]
public void Properties_CimClass()
{
CimInstance cimInstance = new CimInstance("MyClassName");
MI_Class classHandle;
MI_Result result = cimInstance.InstanceHandle.GetClass(out classHandle);
Assert.Equal(cimInstance.CimClass, new CimClass(classHandle), "property CimClass is not correct");
}

[Fact]
public void Properties_IsValueModified()
{
Expand Down Expand Up @@ -288,15 +279,15 @@ public void Properties_Add_ValueAndType_UInt16()
Assert.Equal(CimType.UInt16, addedProperty.CimType, "addedProperty.CimType should be UInt16");
}

[TDDFact]
[Fact]
public void Properties_Add_ValueAndType_SInt32()
{
CimInstance cimInstance = new CimInstance("MyClassName");
CimProperty cimProperty = CimProperty.Create("MyPropertyName", 123, CimType.SInt32, CimFlags.None);
Assert.Equal("MyPropertyName", cimProperty.Name, "CimProperty.Create correctly round-trips CimProperty.Name");
Assert.True(cimProperty.Value is Int32, "CimProperty.Create preserves the type of the value");
Assert.Equal(CimType.SInt32, cimProperty.CimType, "CimProperty.Create correctly round-trips CimProperty.CimType");
Assert.Equal(CimFlags.None, cimProperty.Flags, "CimProperty.Create correctly round-trips CimProperty.Flags");
Assert.Equal(CimFlags.NotModified, cimProperty.Flags, "CimProperty.Create correctly round-trips CimProperty.Flags");

cimInstance.CimInstanceProperties.Add(cimProperty);
CimProperty addedProperty = cimInstance.CimInstanceProperties.Single();
Expand Down Expand Up @@ -558,7 +549,7 @@ public void Properties_Add_ValueAndType_Instance()
Assert.Equal("MyPropertyName", cimProperty.Name, "CimProperty.Create correctly round-trips CimProperty.Name");
Assert.True(cimProperty.Value is CimInstance, "CimProperty.Create preserves the type of the value");
Assert.Equal(CimType.Instance, cimProperty.CimType, "CimProperty.Create correctly round-trips CimProperty.CimType");
Assert.Equal(CimFlags.None, cimProperty.Flags, "CimProperty.Create correctly round-trips CimProperty.Flags");
Assert.Equal(CimFlags.NotModified, cimProperty.Flags, "CimProperty.Create correctly round-trips CimProperty.Flags");
cimInstance.CimInstanceProperties.Add(cimProperty);

CimProperty addedProperty = cimInstance.CimInstanceProperties.Single();
Expand All @@ -579,7 +570,7 @@ public void Properties_Add_ValueAndType_Instance_InferredType()
Assert.Equal(cimProperty.Name, "MyPropertyName", "CimProperty.Create correctly round-trips CimProperty.Name");
Assert.True(cimProperty.Value is CimInstance, "CimProperty.Create preserves the type of the value");
Assert.Equal(CimType.Instance, cimProperty.CimType, "CimProperty.Create correctly round-trips CimProperty.CimType");
Assert.Equal(CimFlags.None, cimProperty.Flags, "CimProperty.Create correctly round-trips CimProperty.Flags");
Assert.Equal(CimFlags.NotModified, cimProperty.Flags, "CimProperty.Create correctly round-trips CimProperty.Flags");
cimInstance.CimInstanceProperties.Add(cimProperty);

CimProperty addedProperty = cimInstance.CimInstanceProperties.Single();
Expand Down Expand Up @@ -707,7 +698,7 @@ public void Properties_Add_ValueAndType_Reference()
Assert.Equal("MyPropertyName", cimProperty.Name, "CimProperty.Create correctly round-trips CimProperty.Name");
Assert.True(cimProperty.Value is CimInstance, "CimProperty.Create preserves the type of the value");
Assert.Equal(CimType.Reference, cimProperty.CimType, "CimProperty.Create correctly round-trips CimProperty.CimType");
Assert.Equal(CimFlags.None, cimProperty.Flags, "CimProperty.Create correctly round-trips CimProperty.Flags");
Assert.Equal(CimFlags.NotModified, cimProperty.Flags, "CimProperty.Create correctly round-trips CimProperty.Flags");
cimReference.CimInstanceProperties.Add(cimProperty);

CimProperty addedProperty = cimReference.CimInstanceProperties.Single();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public void Deserialization_DMTFMof()
Assert.True(!ce.MoveNext());
}

[TDDFact]
[Fact]
public void Deserialization_CimClass_MintMof()
{
uint offset = 0;
Expand All @@ -549,7 +549,7 @@ public void Deserialization_CimClass_MintMof()
}
}

[TDDFact]
[Fact]
public void Deserialization_CimInstance_MintMof()
{
uint offset = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,123 @@
[Abstract,
version("1.0.0"),
Description (
"Credential to use for DSC configuration providers." )]
class MSFT_BaseCredential
{
[Description
("UserName is the name of the user for an authorization service to map to an identity." ),
MaxLen ( 256 )]
string UserName;
[Description
("UserPassword property may contain a passwordused to access resources." )]
string Password;
};

[version("1.0.0"), Description ("Credential to use for DSC configuration providers on Windows")]
class MSFT_WindowsCredential : MSFT_BaseCredential
{
[Description
("Domain name of the user if it below to a LDAP directory." ),
MaxLen ( 256 )]
string Domain;
};

[Abstract, version("1.0.0"),
Description (
"Base schema for all configuration providers that will be imported by powershell extension." )]
class MSFT_BaseResourceConfiguration
{
[required,
Description (
"Unique Id for a resource instance." )]
string ResourceId;

[write,
Description (
"Source Info to correlate it back to powershell configuration script." )]
string SourceInfo;

[write,
Description (
"List of resources this resource depends on." )]
string Requires[];

[write,
Description (
"Whether to reapply the config even if it is not changed." )]
Boolean Force;
};


class MSFT_FileDirectoryConfiguration:MSFT_BaseResourceConfiguration
{
[Key, Description("File name and path on target node to copy or create.")]
string DestinationPath;

[Write, Values{"File", "Directory", "Absent"}, Description("Defines how to evaluate the existents of the destination file.")]
string Ensure;

[Write, Description("File name and path of file to copy from.")]
string SourcePath;

[Write, Description("Contains the contents as string for the file. To create empty file contents must contain empty string. Contents written and compared using UTF-8 character encoding.")]
string Contents;

[Write, Values{"SHA-1", "SHA-256", "SHA-512", "CreatedDate", "ModifiedDate"}, Description("The checksum type to use when determining whether two files are the same.")]
string Checksum;

[Write, Description("ACLs - Security descriptor for file / directory. Format as SDDL string.")]
string SecurityDescriptor;

[Write, Description("Recurse all child directories")]
boolean Recurs;

[Write, Description("Whether unmanaged files should be purged from target. ")]
boolean Purge;

[Write, EmbeddedInstance("MSFT_WindowsCredential"), Description("Credential to access remote resources.")]
string credential;

[Read, Description("Created date")]
datetime CreatedDate;

[Read, Description("Modified date")]
datetime ModifiedDate;

//We are using definitions of FileAttributes enumaration in .NET, except "Device" which is reserved for future use
[Write, Values{"ReadOnly", "Hidden", "System", "Archive"},
Description("Attributes for file / directory")]
string Attributes[];

[Read, Description("")]
uint64 Size;
};

Class MSFT_ConfigurationDocument
{
[Description (
"Configuration document version information, configuration engine can use to log." )]
String Version;

[Description (
"Configuration document Author information." )]
String Author;

[Description (
"Configuration document Copyright information." )]
String Copyright;

[Description (
"Configuration document Help URI." )]
String HelpInfoUri;
};
instance of MSFT_WindowsCredential as $x
{
UserName="AAA";
Password="BBB";
Domain="CCC";
};


instance of MSFT_FileDirectoryConfiguration
{
ResourceId="R1";
Expand Down

0 comments on commit 8e7928c

Please sign in to comment.