or
Hi,
I want to mock the StreamReader constructor below so the unit test can pass that statement without failing. All the samples of mocking mscorlib relies on mocking a method, but I want to mock the constructor, how do I do that?
I don't want to create a valid file and pass a valid pathToFile.
We are currently using version 2013.1.507, please provide a sample that works on this version.
Thanks,
Gustavo
public class MyClass
{
public static string DoSomething(string pathToFile)
{
TextReader xmlTextReader = new StreamReader(pathToFile);
//some method logic
//returns a string
}
}
CalculatePreviewArea
like that:public
partial
class
Control_Inside : UserControl
{
//some properties...
//(private) method1()
//(private) method2()
private
void
CalculatePreviewArea(
out
double
width,
out
double
height)
{
//some logic here...
//FillArea is dependency property of User Control
width = FillArea.Width;
height =FillArea.Height;
double
Sys_Width = SystemParameters.WorkArea.Width;
double
Sys_Height = SystemParameters.WorkArea.Height;
Window window = Application.Current.MainWindow;
Point location_From_Screen = window.PointToScreen(
new
Point(0.0, 0.0));
if
(location_From_Screen.X + width - Fill_Area.X >= Sys_Width)
width =Sys_Width + (location_From_Screen.X - Fill_Area.X);
//....
}
CalculatePreviewArea
) using JustMock. I created a mock user control , I also set FillArea value successfull, but there is no way to access Application.Current.Windows. When I debug the test,it always return null. I need your helps to test this, thanks.
w System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
w System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
w System.Reflection.Emit.TypeBuilder.CreateType()
w Telerik.JustMock.DynamicProxy.TypeEmitter.CreateType()
w Telerik.JustMock.DynamicProxy.Proxy.CreateType()
w Telerik.JustMock.DynamicProxy.ProxyFactory.Create()
w Telerik.JustMock.DynamicProxy.Fluent.FluentProxy.NewInstance()
w Telerik.JustMock.DynamicProxy.Proxy.Create(Type target, Action`1 action)
w Telerik.JustMock.MockManager.CreateProxy(Type targetType, Container container)
w Telerik.JustMock.MockManager.CreateInstance(Container container)
w Telerik.JustMock.MockManager.SetupMock(Behavior behavior, Boolean
static
)
w Telerik.JustMock.MockManager.CreateInstance()
w Telerik.JustMock.Mock.Create(Type target, Behavior behavior, Object[] args)
w Telerik.JustMock.Mock.Create[T](Behavior behavior, Object[] args)
w Xtd.Tests.SomeClassTests.Initialize()
Mock.Create<SomeClass<Period, Container>.SomeSubClass>(Telerik.JustMock.Behavior.CallOriginal);
public
static
class
MyStaticClass
{
public
static
string
MyStaticMethod()
{
return
Datetime.Now.ToString() +
"anotherRandomString"
;
}
}
/// <
summary
>
/// Represents the Automatic Warehouse add in
/// </
summary
>
/// /// <
seealso
cref
=
""
/>
public class AutomaticWarehouseKpiAddInn: IKeyPerformanceIndicatorAddIn
{
/// <
summary
>
/// Gets or sets the configuration extension service.
/// </
summary
>
[Dependency]
public IConfigurationExtensionService ConfigurationExtensionService { get; set; }
public void Initialize()
{
ConfigurationExtensionService.RegisterExtension(typeof(AutomaticWarehouseCommanderAddInConfiguration),
new AutomaticWarehouseCommanderConveyorConfigConverter());
}
}
[TestMethod]
public void InitializeRegisterExtensionCorrectly()
{
IConfigurationExtensionService configurationExtensionService = Mock.Create<
ConverterConfigurationBuilder
>();
AutomaticWarehouseKpiAddInn automaticWarehouseKpiAddInn = new AutomaticWarehouseKpiAddInn
{
ConfigurationExtensionService = configurationExtensionService
};
Mock.Arrange(() => configurationExtensionService.RegisterExtension(null, null)).MustBeCalled();
automaticWarehouseKpiAddInn.Initialize();
Mock.Assert(configurationExtensionService);
}