本文整理汇总了C#中MockFactory.Create方法的典型用法代码示例。如果您正苦于以下问题:C# MockFactory.Create方法的具体用法?C# MockFactory.Create怎么用?C# MockFactory.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockFactory
的用法示例。
在下文中一共展示了MockFactory.Create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setup
public void Setup()
{
_factory = new MockFactory(MockBehavior.Strict);
_parserMock = _factory.Create<IConfigurationParser>();
_proxyMock = _factory.Create<IConfigurationProxyProvider>();
_sage = new Sage(_parserMock.Object, _proxyMock.Object);
}
示例2: shouldRedirectToReturnUrlWhenLoginIsSuccessfull
public void shouldRedirectToReturnUrlWhenLoginIsSuccessfull()
{
var returnUrl = "~/Home/Index";
var mockFactory = new MockFactory(MockBehavior.Strict);
var membershipService = mockFactory.Create<IMembershipBusinessLogic>();
var formsAuthenticationService = mockFactory.Create<IFormsAuthenticationService>();
membershipService.Setup(x => x.ValidateUser("username", "password")).Returns(true);
formsAuthenticationService.Setup(x => x.SignIn("username", false));
var accountController = new CarbonFitness.App.Web.Controllers.AccountController(formsAuthenticationService.Object, membershipService.Object);
var actionResult = accountController.LogOn(new LogOnModel {UserName = "username", Password = "password"}, returnUrl);
Assert.That(((RedirectResult) actionResult).Url.Contains(returnUrl));
}
示例3: Setup
public virtual void Setup()
{
CreateRunspace();
Mocks = new MockFactory(MockBehavior.Loose);
factory = Mocks.Create<IEmailApiFactory>();
EmailApiCommand.Factory = factory.Object;
client = Mocks.Create<IWebClient>();
client.SetupAllProperties();
client.Object.Headers = (Headers = new WebHeaderCollection());
factory.Setup(f => f.CreateWebClient())
.Returns(client.Object)
.AtMostOnce();
}
示例4: shouldAddIngredientToCurrentUser
public void shouldAddIngredientToCurrentUser()
{
var mockFactory = new MockFactory(MockBehavior.Loose);
var userContextMock = GetSetuppedUserContextMock(mockFactory);
var userIngredientBusinessLogicMock = mockFactory.Create<IUserIngredientBusinessLogic>();
var userIngredient = new UserIngredient {
User = new User {Username = "myUser"},
Ingredient = new Ingredient {Name = "Pannbiff"},
Measure = 100
};
userIngredientBusinessLogicMock.Setup(x => x.GetUserIngredients(It.IsAny<User>(), It.IsAny<DateTime>())).Returns(new[] {userIngredient});
userIngredientBusinessLogicMock.Setup(x => x.AddUserIngredient(It.Is<User>(u => u.Username == "myUser"), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime>())).Returns(userIngredient);
var inputFoodModel = new InputFoodModel {Ingredient = "Pannbiff", Measure = 100, Date = DateTime.Now};
var model = testController(x => x.Input(inputFoodModel), userIngredientBusinessLogicMock, userContextMock);
Assert.That(model, Is.Not.Null);
Assert.That(model.UserIngredients, Is.Not.Null);
Assert.That(model.UserIngredients.Any(x => x.Ingredient.Name == "Pannbiff"));
Assert.That(model.UserIngredients.Any(x => x.Measure == 100));
userIngredientBusinessLogicMock.VerifyAll();
}
示例5: shouldThrowIngredientInsertionExceptionWhenInsertingFails
public void shouldThrowIngredientInsertionExceptionWhenInsertingFails()
{
var factory = new MockFactory(MockBehavior.Strict);
var ingredientRepositoryMock = factory.Create<IIngredientRepository>();
ingredientRepositoryMock.Setup(x => x.SaveOrUpdate(It.IsAny<Ingredient>())).Throws(new Exception());
Assert.Throws<IngredientInsertionException>(() => new IngredientImporter(null, null, ingredientRepositoryMock.Object).SaveIngredient(new Ingredient()));
}
示例6: ShouldBeAbleToCreateAProxyForAnEnum
public void ShouldBeAbleToCreateAProxyForAnEnum()
{
var factory = new MockFactory(MockBehavior.Strict);
var @enum = factory.Create<Fixtures.Language>(MockBehavior.Strict, null, null);
@enum.Setup(e => e.IetfTag).Returns("CZ");
Assert.AreEqual("CZ", @enum.Object.IetfTag);
}
示例7: shouldGetUserFromUsername
public void shouldGetUserFromUsername()
{
var mockFactory = new MockFactory(MockBehavior.Strict);
var userRepositoryMock = mockFactory.Create<IUserRepository>();
userRepositoryMock.Setup(x => x.Get(It.IsAny<string>())).Returns(new User());
var userBusinessLogic = new UserBusinessLogic(userRepositoryMock.Object, null);
userBusinessLogic.Get("myUser");
userRepositoryMock.VerifyAll();
}
示例8: Create
public void Create(bool haveHistory = true)
{
_factory = new MockFactory(MockBehavior.Strict);
_statusUtil = _factory.Create<IStatusUtil>();
if (haveHistory)
{
_history = _factory.Create<ITextUndoHistory>();
_operationsRaw = new UndoRedoOperations(
_statusUtil.Object,
FSharpOption.Create(_history.Object));
}
else
{
_operationsRaw = new UndoRedoOperations(
_statusUtil.Object,
FSharpOption<ITextUndoHistory>.None);
}
_operations = _operationsRaw;
}
示例9: shouldImportIngredients
public void shouldImportIngredients()
{
var factory = new MockFactory(MockBehavior.Strict);
var ingredientParserMock = factory.Create<IIngredientParser>();
var ingredientFileReaderMock = factory.Create<IIngredientFileReader>();
var ingredientRepositoryMock = factory.Create<IIngredientRepository>();
const string abc = "abc";
const string fileName = "fileName";
ingredientFileReaderMock.Setup(x => x.ReadIngredientFile(fileName)).Returns(abc);
const string abborre = "Abborre";
ingredientParserMock.Setup(x => x.CreateIngredientFromFileContents(abc)).Returns(new List<Ingredient> {new Ingredient {Name = abborre}});
ingredientRepositoryMock
.Setup(x => x.SaveOrUpdate(It.Is<Ingredient>(y => y.Name == abborre)))
.Returns(null as Ingredient);
new IngredientImporter(ingredientParserMock.Object, ingredientFileReaderMock.Object, ingredientRepositoryMock.Object)
.Import(fileName);
factory.VerifyAll();
}
示例10: GetFieldByNameNoHeaderExceptionTest
public void GetFieldByNameNoHeaderExceptionTest()
{
var data = new [] { "1", "2" };
var mockFactory = new MockFactory( MockBehavior.Default );
var parserMock = mockFactory.Create<ICsvParser>();
parserMock.Setup( m => m.Read() ).Returns( () => data );
var reader = new CsvReader( parserMock.Object, new CsvReaderOptions{ HasHeaderRecord = false } );
reader.Read();
Assert.AreEqual( Convert.ToInt32( data[0] ), reader.GetField<int>( "One" ) );
}
示例11: TestPersistWithFactory
public void TestPersistWithFactory()
{
MockFactory factory = new MockFactory(MockBehavior.Strict);
//Classes work, methods have to be virtual -> not nice
var mockGateway = factory.Create<UserGateway>();
var mockValidator = factory.Create<IUserValidator>();
User user = new User();
//Excpectations
mockValidator.Setup(x => x.Validate(user)).Returns(true).AtMostOnce();
mockGateway.Setup(x => x.Persist(user)).Returns(true).AtMostOnce();
//Assign gateway
user.Gateway = mockGateway.Object;
//Test method
Assert.AreEqual(true, user.Persist(mockValidator.Object));
factory.VerifyAll();
}
示例12: shouldCallSaveOnRepository
public void shouldCallSaveOnRepository()
{
const string userName = "test";
var password = "password";
var factory = new MockFactory(MockBehavior.Strict);
var mock = factory.Create<IUserBusinessLogic>();
var userContextMock = new Mock<IUserContext>();
mock.Setup(x => x.Create(It.Is<User>(y => y.Username == userName))).Returns(new User());
var controller = new CarbonFitness.App.Web.Controllers.UserController(mock.Object, userContextMock.Object);
controller.Create(userName, password);
factory.VerifyAll();
}
示例13: GetFieldByIndexTest
public void GetFieldByIndexTest()
{
var data = new [] { "1", "2" };
var mockFactory = new MockFactory( MockBehavior.Default );
var parserMock = mockFactory.Create<ICsvParser>();
parserMock.Setup( m => m.Read() ).Returns( data );
var reader = new CsvReader( parserMock.Object );
reader.Read();
Assert.AreEqual( 1, reader.GetField<int>( 0 ) );
Assert.AreEqual( 2, reader.GetField<int>( 1 ) );
}
示例14: shouldReturnFalseWhenProvidingWrongPassword
public void shouldReturnFalseWhenProvidingWrongPassword()
{
var username = "username";
var userPassword = "sdfsdfsdf";
var providedPassword = "nåttannat";
var factory = new MockFactory(MockBehavior.Strict);
var userRepositoryMock = factory.Create<IUserRepository>();
userRepositoryMock.Setup(x => x.Get(username)).Returns(new User(username, userPassword));
var membershipProvider = new MembershipBusinessLogic(userRepositoryMock.Object);
var loginResult = membershipProvider.ValidateUser(username, providedPassword);
Assert.That(loginResult, Is.False);
}
示例15: CanBindToParameterlessInstanceFactoryMethod
public void CanBindToParameterlessInstanceFactoryMethod()
{
var factory = new MockFactory();
var module = new InlineModule(
m => m.Bind(typeof(IMock)).ToMethod(ctx => factory.Create())
);
using (var kernel = new StandardKernel(module))
{
var mock = kernel.Get<IMock>();
Assert.That(mock, Is.Not.Null);
Assert.That(mock, Is.InstanceOfType(typeof(ImplA)));
}
}