or
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);
}
[TestClass]
public class MsCorlibFixture
{
static MsCorlibFixture()
{
Mock.Replace(() => Stopwatch.GetTimestamp()).In<
MsCorlibFixture
>(x => x.ShouldAssertCustomValueForDateTime());
}
[TestMethod]
public void ShouldAssertCustomValueForDateTime()
{
Mock.Arrange(() => Stopwatch.GetTimestamp()).Returns(100);
var now = Stopwatch.GetTimestamp()
Assert.AreEqual(100, now);
}
}