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 AdministratorsAlias name AdministratorsComment Administrators have complete and unrestricted access to the computer/domainMembers-------------------------------------------------------------------------------AdministratorStuartThe 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.UnitTestingImports 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 ClassEnd Class