or
[Test]
public
void
timesheet_processor_tests_just_mock()
{
Mock.SetupStatic(
typeof
(LaborManager));
Mock.Arrange(() => LaborManager.GetTimesheetLabor(DateTime.Now, 1683)).Returns(
new
TimesheetLaborReadOnlyCollection());
var processor =
new
TimesheetProcessor();
processor.ProcessUserTimesheet(DateTime.Now, 1683);
Mock.Assert(() => LaborManager.GetTimesheetLabor(DateTime.Now, 1683), Occurs.AtLeastOnce());
}
//Timesheet Processor Class
public
void
ProcessUserTimesheet(DateTime weekEndingDate,
int
userId)
{
TimesheetsCreated =
new
List<
int
>();
TimesheetLaborReadOnlyCollection laborEntries = LaborManager.GetTimesheetLabor(weekEndingDate, userId);
if
(laborEntries.Count > 0)
ProcessTimesheetLaborUser(userId, weekEndingDate, laborEntries);
}
Mock.ArrangeSet(Sub() VbModule.MyProperty = Arg.AnyString).DoNothing()
Any help would be appreciated.
Mock.Arrange(Function() Registry.GetValue("HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Legacy App\Options", "SettingValue", String.Empty)).Returns("Test Result")
C:\Users\Stuart>net localgroup Administrators
Alias name Administrators
Comment Administrators have complete and unrestricted access to the compu
ter/domain
Members
-------------------------------------------------------------------------------
Administrator
Stuart
The command completed successfully.
public
class
TypeBeingTested
{
public
TypeBeingTested()
{
var folder =
new
DirectoryInfo(
"C:\\Program Files"
);
var folders = folder.GetDirectories(
"Microsoft Visual Studio 8"
);
if
(folders.Length == 0)
throw
new
DirectoryNotFoundException(
"Visual Studio 2005 is not installed."
);
}
}
[TestInitialize]
public
void
Mock_DirectoryInfo()
{
Mock.Partial<DirectoryInfo>().For<
string
>((folder, name) => folder.GetDirectories(name));
}
[TestMethod]
[ExpectedException(
typeof
(DirectoryNotFoundException))]
public
void
Missing_Program_Files_folder_throws_exception()
{
var folder =
new
DirectoryInfo(
"C:\\Program Files"
);
Mock.Arrange(() => folder.GetDirectories(
"Microsoft Visual Studio 8"
)).Returns(
new
DirectoryInfo[] {});
var instance =
new
TypeBeingTested();
Assert.Fail(
"No exception was raised in TypeBeingTested constructor."
);
}
I’m getting the following error when trying to mock a static function in a silverlight unit test:
“There were some problems intercepting the mock call. Optionally, please make sure that you have turned on JustMock's profiler while mocking concrete members.”
I don’t get the error in a full .NET unit test project, so, I wondered whether I was missing a setting or something?
My code from my silverlight unit test project is below. I get the error on the Mock.Arrange() line
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports Telerik.JustMock
<
TestClass
()> _
Public Class Tests
<
TestMethod
()> _
Public Sub SharedMethodMustBeCalled()
Mock.Arrange(Function() SharedStuff.GetSomething(Arg.AnyString)).MustBeCalled()
Dim SomeClass As New SomeClass
Dim ret As String = SomeClass.DoSomething()
Mock.Assert(SomeClass)
End Sub
Public Class SomeClass
Public Function DoSomething() As String
Dim ret As String = SharedStuff.GetSomething("fred")
Return ret
End Function
End Class
Public Class SharedStuff
Public Shared Function GetSomething(ByVal Name As String) As String
Return "test"
End Function
End Class
End Class
<
TestClass
()> _
Public Class MyTests
<
TestMethod
()> _
Public Sub GetValue_ValueReturnedFromDatabase()
Dim ds As IDataService = Mock.Create(Of IDataService)()
Mock.Arrange(Function() ds.GetValue(Arg.AnyString, Arg.IsAny(Of Dictionary(Of String, Object)))).Returns("test")
Dim l As New LD(ds)
Dim ret As String = l.GetValue("xxx")
Assert.AreEqual("test", ret)
End Sub
End Class
Public Interface IDataService
Function GetValue(ByVal SQL As String, ByVal Params As Dictionary(Of String, Object)) As String
End Interface
Public Class DS
Implements IDataService
Public Function GetValue(ByVal SQL As String, ByVal Params As Dictionary(Of String, Object)) As String Implements IDataService.GetValue
Return "anything"
End Function
End Class
Public Class LD
Private _DataService As IDataService
Public Sub New(ByVal DataService As IDataService)
_DataService = DataService
End Sub
Public Function GetValue(ByVal Name As String)
Dim params As New Dictionary(Of String, Object)
Dim ret As String = _DataService.GetValue("Some SQL", params)
Return ret
End Function
End Class