I am running tests on a project where I want to mock (or mole) the class DirectoryEntry from System.DirectoryServices so I can override the Rename() and CommitChanges() methods with a moled method of that class. I added the Moles assembly for System.DirectoryServices, and it did create a class called MDirectoryEntry, but only a couple of the methods that DirectoryEntry exposes are showing up. Can anyone tell me why, and how I can do this? I am running Moles v.0.94.51023.0 and Visual Studio 2010 (RTM release).
Thank you!
OK, I figured it out. The methods I was trying to access were instance-based, not static. I just found the AllInstances property and - voila! - there are all of the methods I was trying to find!
I hope this can help someone else new to Moles!
Related
I've been practicing Caliburn.micro with mvvm pattern.. till I noticed that I have named the folder"ViewModels" ModelViews which in regards to caliburn doesn't work unless you specify the standard names, but after renaming it I noticed it that visual studio still uses the old path for example when I try to call the class LoginViewModel it automatically calls this path:
using Login2.ModelViews;
event if I try to manually type using Login2.ViewModels;
it doesn't recognize it.
Any suggestion would be appreciated I don't want to restart my project.
I just solved the problem by naming the namespace of the ViewModel classes
from namespace Login2.ModelViews to namespace Login2.ViewModels hopes this will help someone in the future ^-^
I created a VS 2010 class library. Marked the assembly for Com Visibility. Signed the assembly with a strong key. Created my class, have my entry point method available.
The library works fine from a test project in C#.
I regasm the class library to gac, via:
c:\windows\microsoft.net\framework\v4.0.30319\regasm testdll.dll /tlb: testdll.tlb /codebase
Include the tlb file as a reference in my VB6 project. I find it through resources 'browse' so its there.
When i try to instantiate the class... its empty. the public method that should be available via the public class doesn't show.
Dim objTest as testdll.testclass
set objTest = new testdll.testclass
objTest.testmethod <--- this 'testmethod' doesn't display in intellisense... nothing does.
In addition i tried calling the 'testdll.testclass' via CreateObject, i get the error "ActiveX component can't create object"
Now i have other projects i've done COM visibility for and i've tried comparing the difference, but i don't see any. I can't understand why it isn't working.
Any clues??? tx very much.
Just use an interface... one you define or to use the [ClassInterface(ClassInterfaceType.AutoDual)]
there are comments online you can find that indicate not to use autodual, but if you control the complete usage of your library, it seems like an 'ok' way to go.
I tried all sorts of ways to simulate / understand why my one project didn't need an interface to be visible by an vb project, without success. i had originally thought perhaps possible that it was because that project implemented an IDisposable Interface (the ONLY interface used in the C# projects that is com visible) but that didn't turn out to be the reason. Anyway I don't want to waste anyone else's time on this. thanks for the responses.
this link provides ample information on the subject:
http://anturcynhyrfus.blogspot.com/2011/03/creating-com-visible-c-component.html
I can refactor a big code to a new method which automatically sets the parameters, return type, if static or not etc in the same class. Is there a way that I can move the code to a new function in a different class if I could specify the class somehow? May be I'm missing something silly.
In VIsual Studio there is no possibility to move methods between classes. But if you use ReSharper from JetBrains, you can move static methods between classes with Move To Another Type command.
I am fairly new to development, and Visual Studio 2010.
I have a solution with a Test Project:
In my solution, there are two projects: "TPS" and "TPS.Tests"
In the TPS project, in the namespace "TPS.Models" I have defined a bunch of classes, and two interfaces.
I have created a Test Class in the TPS.Tests project, and have added "using TPS.Models;"
I attempt to implement the interface by typing it out (e.g. public class FakeObjectClass : IObjectClass), but it isn't recognised (so I can't get the auto-implement going, which would be handy as I have over 100 methods)
Typing in the class, in Intellisense, I can see all the objects defined in my model, but none of the interfaces.
Google has been unusually silent on the search combinations I have tried. I am hoping there is some simple explanation/fix?
Thanks in advance for your time.
Tim.
If you haven't specified an access modifier when defining the Interface, it will default to internal and not be visible to other assemblies.
Make sure that you defined your interface as
public interface IMyInterface
A few things to check:
- Does your "TPS.Tests" project have a reference to the "TPS" project?
- Are your interfaces in the "TPS.Models" namespace? Putting the files in a sub-directory of the project, such as "Interfaces", can affect their namespace.
- Are the interfaces marked as Public?
Also, I would suggest using an Isolation (aka "Mocking" framework) to create your fake objects, such as Moq, Rhino.Mocks, etc, rather than rolling your own fake objects for most situations.
Getting an odd problem with a unit test in my solution. One of the test always fails with the following error message:
The member specified (BuildMap) could not be found. You might need to regenerate your private accessor,
or the member may be private and defined on a base class. If the latter is true, you need to pass the type
that defines the member into PrivateObject's constructor.
BuildMap is private and I have tried regenerating the accessor, changing it to public and recreating the unit test and it continuously fails. The other methods (both public and private) all work fine. BuildMap is also not defined in a base class.
Also tried all the usual things in case VS is messing about, restarting it, clean assemblies, rebuild etc...
Any ideas on the cause?
update 1: This is in Visual Studio 2008 or on the command line mstest tool.
update 2: Tried renaming the BuildMap method and the tests would not build stating it was missing. Appears that Visual Studio/MSBuild is doing the right thing, but somewhere between it and mstest it is breaking.
Oddly enough when I changed the method from static to not static the issue resolved itself. Other private static methods work fine though.
Still not sure of the cause but that is the resolution.