moq

EF6 DbSet<T> returns null in Moq

我只是一个虾纸丫 提交于 2019-12-10 03:24:39
问题 I have a typical Repository Pattern setup in my application with a DbContext (EF6): public class MyDbContext : EFContext<MyDbContext> { public MyDbContext () { } public virtual DbSet<CartItem> Cart { get; set; } and a repository: public class GenericEFRepository<TEntity, TContext> where TEntity : class, new() where TContext : EFContext<TContext> { private readonly TContext _context; public GenericEFRepository(TContext context) { _context = context; } //... public virtual TEntity Insert

Verifying Mock method was called inside Task.Run

。_饼干妹妹 提交于 2019-12-10 03:19:26
问题 How can I verify that a method was called on a mock when the method itself is called in a delegate passed to Task.Run ? By time mock.Verify is called the Task still hasn't executed. I have tried await Task.Delay just before mock.Verify but this seems to leave the test runner hanging. The reason for using Task.Run is to offload the logic to prevent an attacker from being able to differentiate whether the email address exists in the system by the time to execute. using System.Threading.Tasks;

Adding MOQ to a .NET 4.0 project is not possible

你说的曾经没有我的故事 提交于 2019-12-10 02:34:51
问题 I want to add MOQ .net library to a .NET 4.0 project. I get an error message that I should convert the project to something smaller than 4.0. I need to use .NET 4.0 also because of other project dependencies. How can I make MOQ work with a .NET 4.0 project in VS2010 ? 回答1: Make sure you have NuGet package manager installed (Tools/Extension Manager). Right click on Solution Explorer/References, choose Manage NuGet Packages. Type Moq in the search box. Install and enjoy. 回答2: The latest version

How to mock rows in a Excel VSTO plugin?

拈花ヽ惹草 提交于 2019-12-10 01:45:55
问题 I am trying to put a mocked Range (which contains cells with values) inside the rows of a new Range . But when I try to access a specific element from the Range , a exception is thrown. I've tried everything, does anyone have a idea what I am doing wrong here? Exception Message: Test method xxx.MockUtilsTest.MockRowsTest threw exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot apply indexing with [] to an expression of type 'Castle.Proxies.RangeProxy' Test [TestMethod]

What is the DynamicProxyGenAssembly2 assembly?

瘦欲@ 提交于 2019-12-10 01:08:17
问题 I use Moq for my unit tests. To test internal interfaces I have to declare the InternalsVisibleTo attribute to the DynamicProxyGenAssembly2 assembly. We run our tests obfuscated, which is useful because we could found some problems with obfuscation with this approach. Caused by the DynamicProxyGenAssembly2 assembly my component is not obfuscated. Therefore I need to know what is the DynamicProxyGenAssembly2 assembly? I could not found it anywhere on my disk. Is it compiled into the moq.dll or

Can not instantiate proxy…Could not find a parameterless constructor

痞子三分冷 提交于 2019-12-10 01:06:42
问题 I am trying to create a unit test using Moq which tests the MongoDB.AspNet.Identity V2 provider. This line is giving me grief: var appUser = new Mock<PreRegistrationMVC.Models.ApplicationUser>(); var userStore = new Mock<MongoDB.AspNet.Identity.UserStore<PreRegistrationMVC.Models.ApplicationUser>>(); It seems the userStore won't instantiate properly here is the error. Castle.DynamicProxy.InvalidProxyConstructorArgumentsException was unhandled by user code HResult=-2147024809 Message=Can not

ASP.NET MVC Controller Unit Testing - Problem with UrlHelper Extension

核能气质少年 提交于 2019-12-10 00:58:33
问题 Trying to do some controller unit-testing in my ASP.NET MVC 3 web application. My test goes like this: [TestMethod] public void Ensure_CreateReviewHttpPostAction_RedirectsAppropriately() { // Arrange. var newReview = CreateMockReview(); // Act. var result = _controller.Create(newReview) as RedirectResult; // Assert. Assert.IsNotNull(result, "RedirectResult was not returned"); } Pretty simple. Basically testing a [HttpPost] action to ensure it returns a RedirectResult (PRG pattern). I'm not

How to mock ApplicationUserManager from AccountController in MVC5

被刻印的时光 ゝ 提交于 2019-12-09 18:34:30
问题 I am trying to write Unit Test for Register Method at AccountController I am using moq and what is the correct way to mock ApplicationUserManager, ApplicationRoleManager and ApplicationSignInManager from Unit Test. public AccountController(ApplicationUserManager userManager, ApplicationRoleManager roleManager, ApplicationSignInManager signInManager) { UserManager = userManager; RoleManager = roleManager; SignInManager = signInManager; } public ApplicationUserManager UserManager { get { return

Mocking Datasets with Moq

大憨熊 提交于 2019-12-09 16:48:32
问题 I'm trying to get started with Moq and having trouble finding any good resources to do what I need. I have a Data Interface class that has a Get method which returns a Dataset via Stored Procedure. This is the way the code was written and I can't change it at the moment so it has to be done this way. I want to test this class by Mocking the Dataset and returning data so I don't have to actually make a database call. Is anyone doing this and if so where is a good place to get started doing it?

Use Moq to mock Constructor?

前提是你 提交于 2019-12-09 14:04:21
问题 I have such a set of Constructors: public BusinessObjectContext() : this(CloudStorageAccount.FromConfigurationSetting("DataConnectionString").TableEndpoint.ToString(), CloudStorageAccount.FromConfigurationSetting("DataConnectionString").Credentials) {} public BusinessObjectContext(string dataConnectionString) : this(CloudStorageAccount.Parse(dataConnectionString).TableEndpoint.ToString(), CloudStorageAccount.Parse(dataConnectionString).Credentials) { } public BusinessObjectContext(String