|
Hello,
I am writing a program that sends mail and let the user mange his mail locally in his computer.The second requirement is a little hard how can I use the IMAP protocol to connect to the remote mail server and download the mail like outlook using C#.
Thanks.
Dad
|
|
|
|
|
There are some articles on POP3 and IMAP available, for instance check out this one[^].
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
How to run a DTSx package in the .NET framework 2.0 using com object
Thanks in Advance
Regards & Thanks,
Paresh
Paresh Gujararathi
modified on Thursday, July 10, 2008 8:37 AM
|
|
|
|
|
I am just starting my adventure with test driven development (thanks to ASP.NET MVC!) and have a concern, I need to clarify something.
I have an interface like this...
public interface IUserRepository
{
IUser FetchByID(int userID);
}
and a class which implements that interface:
public class UserRepository : IUserRepository
{
public IUser FetchByID(int userID)
{
User user = null;
return user;
}
}
I want to test the FetchByID() method. I can mock IUserRepository and return a dummy User object, which is fine and works well. But this means the concrete class (UserRepository ) is never tested, so even if I didn't implement that class whatsoever, or I had throw new NotImplementedException() in that method the unit test would still pass since it's using a mock object. I thought you don't want to hit the database (or other external resources) while running your tests and that's the main reason to use mock objects, but that way you never can tell if you implemented that class correctly (or at all!). My colleague told me that when I'm testing that method I should use the concrete class and actually hit the database, and that I should mock IUserRepository only when it's needed in other tests (which are not testing FetchByID() but need data from it). Is that the correct approach?
If so, then my tests will get slower and rely on whether the test DB was properly setup, etc. Perhaps such tests should be placed in a separate project (integration tests)?
|
|
|
|
|
Pawel Krakowiak wrote: I thought you don't want to hit the database (or other external resources) while running your tests and that's the main reason to use mock objects
The concept is; "Each test should be isolated". AFAIK, the way you are testing "FetchById " is not correct. When you are testing FetchById , mocking IUserRepository won't make any sense. You will always get the expected "IUser" instance and as you said, it is not testing the real method. You have to mock only items that are nondeterministic in behaviour.
Pawel Krakowiak wrote: My colleague told me that when I'm testing that method I should use the concrete class and actually hit the database, and that I should mock IUserRepository only when it's needed in other tests (which are not testing FetchByID() but need data from it). Is that the correct approach?
Not exactly. As I said earlier, tests should be isolated. So if you are hitting database for each time, or the database you are using is a shared one, the test which executed successfully one time won't get executed next time as the data in database might have changed. So if you are not testing databases, mock/stub the data access which will help to get the test running quickly.
Consider the modified code
public class UserRepository : IUserRepository
{
IUserDataContainer container;
public UserRepository(IUserDataContainer container)
{
this.container = container;
}
public IUser FetchByID(int userID)
{
User user = null;
UserDTO dto = dataContainer.FetchUserFrom(userId);
user = UserConverter.ConvertFrom(dto);
return user;
}
} I have added a "IDataContainer" to your example which is for fetching the data. Added a parameterized constructor which can be used inject the "IDataContainer" (Dependency Injection).
According to "FetchById" method, getting data is from an external source. So that has to be mocked. So if you follow the example what I given, you can easily mock the data access and test "FetchByid" alone.
If in any other places "FetchById" is using, then you should mock "IUserRepository" and set expectations on "FetchById" method.
Are you using inbuilt testing tools in VS or tools like NUnit ? From my experience, I think MVP is better than MVC for testing.
Hope this helps
|
|
|
|
|
When I re-read your post, I had a feeling that you are not using TDD. You are writing tests but it's not test driven, is it ? If you write the test case in the begining, you might have avoided this confusion.
Initially you write the test something like
[Test]
public void CanFetchUserById()
{
UserRepository repository = new UserRepository();
IUser user = repository.FetchUserById(1);
Assert.That(user != NULL);
Assert.AreEqual(user.Id,1);
Assert.AreEqual(user.Name,"Jim");
} Now to make this test compile, you add a skeleton "FetchById" method to "UserRepository" class.
public IUser FetchByID(int userID)
{
throw new NotImplementedException();
} Now your test will compile, but it will fail. Now come back to your "FetchById" method and add it's implementation. You find that it needs an external source like database to complete processing. So you mock the database access to make your test isolated.
Hope this makes it more clear.
|
|
|
|
|
Hey, I'll answer both of your posts in one place, OK?
N a v a n e e t h wrote: Are you using inbuilt testing tools in VS or tools like NUnit ?
I'm using MSTest which is built-in in VS2008 and moq[^].
I'm not using the database directly, though, I am using SubSonic[^] to generate my DAL classes, it's an ORM tool (perhaps you know it) and inside the FetchByID implementation I would have something like this (to simplify I'm not checking for nulls, etc.):
public IUser FetchByID(int userID)
{
IUser user =
new UserController().FetchByID(userID).ExecuteTypedList<User>()[0];
return user;
}
UserController is a generated class, internally it calls a database, retrieves records from it and maps to result to a typed list of User instances (because I tell it to by invoking the ExecuteTypedList method).
N a v a n e e t h wrote: You are writing tests but it's not test driven, is it ?
It IS test driven. Actually my coding/thought process was exactly the same as yours, I wrote my test first (CanFetchUserById here) and then implemented the FetchByID user on my UserRepository class (see above for the actual implementation using SubSonic) - and that's where I am blocked. I saw that I need to call SubSonic there, but I don't want to access the database in a unit test and didn't know how to do this. I mocked the IUserRepository interface but just as you say this wasn't testing the real method - the FetchByID() method on the mocked object would always return correct data, because after all I'm telling it to (through expectations), right?
I don't know how much of this discussion is clear to you, because it would help if you knew SubSonic a little (I don't know if you do) or another similar ORM with its query syntax. What I think of doing is not using SubSonic in my repository classes directly, but to move it down to the DAL and use it only there, so I would have something like this:
o DAL, which has SubSonic generated classes. Here I would introduce several "providers", e.g. UserProvider which implements IUserProvider which has FetchByID() method.
o Services/BLL which has my own repository classes, which have constructors accepting interfaces, e.g. a UserRepository class which implements IUserRepository and has a constructor which accepts a IUserProvider instance, so I can use dependency injection.
Let's see a "working" example of this...
namespace Example.Data
{
public interface IUserProvider
{
UserDTO FetchByID(int userID);
}
public class UserProvider : IUserProvider
{
public UserDTO FetchByID(int userID)
{
UserDTO user =
new UserController().FetchByID(userID).ExecuteTypedList<UserDTO>()[0];
return user;
}
}
}
namespace Example.Services
{
public interface IUserRepository
{
IUser FetchByID(int userID);
}
public class UserRepository
{
private _provider = null;
public UserRepository(IUserProvider provider)
{
this._provider = provider;
}
public IUser FetchByID(int userID)
{
UserDTO dto = _provider.FetchByID(userID);
User user = UserConverter.ConvertFrom(dto);
return user;
}
}
}
namespace Example.Tests
{
[TestClass]
public UserRepositoryTest
{
[TestMethod]
public void FetchByID_ReturnsUser()
{
var provider = new Mock<IUserProvider>();
provider.Expect(p => p.FetchByID(1)).Returns(new User("John", "Doe"));
IUserRepository rep = new UserRepository(provider);
IUser user = rep.FetchByID(1);
Assert.IsNotNull(user);
Assert.IsEqual("John", user.FirstName);
Assert.IsEqual("Doe", user.LastName);
provider.VerifyAll();
}
}
}
Is that more or less what I need? But now another question comes to mind - do I test the UserProvider? It uses SubSonic... It might as well use ADO.NET, I think it's not so important if it's SubSonic or not. Essentially after adding all this nice code I'm still at the same point - I know how to test UserRepository , but I just added UserProvider in my DAL and don't know what to do with THAT. The question is - where does all this testing end? Where's the boundary?
|
|
|
|
|
Hello all,
I posted a question recently on using a SDK from an ASP.NET application and got some answers that made me rethink how i should approach an application i need to build.
Basically I have an ASP.NET application that needs to interact with a piece of hardware when either a user wants to interact (they tell the hardware to do something e.g. turn on turn off) or periodically (we poll for information from the hardware). Unfortunately the SDK only allows one call at a time so I need to provide my own locking around the SDK to ensure firstly that two asp clients attempt to interact with the hardware at the same time and secondly that a user doesn’t try to interact whilst a periodic action is taking place.
After some research and some questions on various forums I have decided to create a windows service which will create static instance of the SDK and the call these methods from the ASP.NET application through IPC remoting channels. From what I have read I will need to create two DLL’s one to interact with the SDK and contain the business logic and a DLL which will be used for the remoting objects.
Am just wondering if this seems the most logical way to tackle this problem or if anyone can think of a different/more efficient way or can see any holes in my solution. Am completely lost by this now as i can't find any examples of doing this it all seems to be about using web services but because i want to keep the state of the SDK object i didnt think i could use these??!!
Thanks,
Adam
|
|
|
|
|
Where is the hardware, on the server ? If it's not, I'm not sure how you'd make this work ?
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
The hardware is communicated to via TCP/IP.
If it helps the hardware is a door controller which manages locking and unlocking doors.
The information that i poll from it is about access transactions.
Why do you think this will not work?!
|
|
|
|
|
b/c I expected you were connecting to something via USB or something, a lot of people get confused about what code runs on the server and what runs on the client, while they develop. If it's using TCP/IP, I guess that would work fine.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
If you need to periodically poll the device for information (and then store it in a database) then a Windows Service is likely the best way to do that.
For allowing users to send commands to the device you could have a table of such commands/requests.
The client would insert a request (perhaps via a WebService), the Windows Service would then perform (or deny) them. This would form an audit trail of such events.
|
|
|
|
|
I'm trying to check if a CD had been burnt using ISO 9660 level 1. I've looked at using win32_CDROMDrive but can't identify what whould tell me the format type. I thought maybe it would be in win32_diskPartition but I don't seem to be able to see any CD information using that (just my 2 partitions on the fixed disk).
Is there a reasonably simple way of identifying the filesystem on the disk?
Thanks
Arron
|
|
|
|
|
Hello all,
i have install my applicatin on the client pc , he is using windows vista
there is some reports "Crystal built in FrameWrork 2.0" ,in some reports fields there is ? marks insted of the data.
these reports shows arabic language ,
But those feilds is defined in data bas as varchar(50)
should i redifen it as nvarchar(50) to hold arabic language?
note : i dont suffer from this problem m using windows xp!!!
Thx.
|
|
|
|
|
If you use varchar, the charset in the database has to match the charset of the system, and that charset has to support the characters that you want to use. By a fluke you seem to have gotten all that right on your system.
If you use nvarchar, the data is unicode, and supports any characters.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
SO sick of good answers being downvoted. I 5d you
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
|
Hi,
I have a .NET Project written in C# which is communicating with a server. I got it all bundled in a zip file (including a msi and setup.exe) file which installs fine.
The users can download this setup from a web server. Now what I need to do is to customize the setup to include user specific information. The setup should set values in the registry depending on the data the user entered in the website. Hence I need some way to automatically include the user data (e.g. as xml file?) in the setup.
Does anyone has an idea how to do this?
Thank you,
Torsten
|
|
|
|
|
Create one Visual Studio Deployment Projects and add your current solution to it. now you can add your own dialogus and code routines to customize the setup wizard.
this might help[^]
|
|
|
|
|
Hi all,
Is it possible to have a text's fontstyle property to Bold, Italic and underline at the same time.
If yes then how?????
Thanks in advance
Rana Krishnraj
|
|
|
|
|
The documentation says:
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
So yes it is possible.
|
|
|
|
|
the Coding Way:
create a new Font(new FontFamily("Tahoma"), 12.75f); (for Example)
and change what ever u want in it
then assgin it to text's font property
The Designer View Way :
or Go To the component in the Design View and click on the Font Property
then Cahnge What ever u Like
Have Fun
Never forget it
|
|
|
|
|
ya that's correct.
But if font have already Bold property set to true and now i want to set its italic property then resulted output text would have both Bold and italic property set to true, instead of only one that is either bold or italic.
any way thanks for replying...I got the hint. let me do it
Rana Krishnraj
|
|
|
|
|
FontStyle fs = FontStyle.Bold;
fs |= FontStyle.Italic;
|
|
|
|
|
In code you can combine them using bitwise operations:
FontStyle.Bold | FontStyle.Italic
modified 12-Sep-18 21:01pm.
|
|
|
|