本文整理汇总了C#中Moq.Mock.VerifyAll方法的典型用法代码示例。如果您正苦于以下问题:C# Moq.Mock.VerifyAll方法的具体用法?C# Moq.Mock.VerifyAll怎么用?C# Moq.Mock.VerifyAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Moq.Mock
的用法示例。
在下文中一共展示了Moq.Mock.VerifyAll方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Dispose_WithValidHubReference_UnregistersWithHub
public void Dispose_WithValidHubReference_UnregistersWithHub()
{
var messengerMock = new Moq.Mock<ITinyMessengerHub>();
messengerMock.Setup((messenger) => messenger.Unsubscribe<TestMessage>(Moq.It.IsAny<TinyMessageSubscriptionToken>())).Verifiable();
var token = new TinyMessageSubscriptionToken(messengerMock.Object, typeof(TestMessage));
token.Dispose();
messengerMock.VerifyAll();
}
示例2: TestGetOrCreateHomeWithExingHomeShouldReturnThatInstance
public void TestGetOrCreateHomeWithExingHomeShouldReturnThatInstance()
{
var mockPersistance = new Moq.Mock<IPersistanceFramework>();
mockPersistance.Setup(m => m.CreateQueryContext<Home>()).Returns(
TestHomes);
var repository = new HomeRepository(mockPersistance.Object);
var results = repository.GetOrCreateHome("first address",1,1);
Assert.AreEqual(TestHomes.First().Id, results.Id);
mockPersistance.VerifyAll();
}
示例3: GetTimeClock_CallRepositoryGetAll
public void GetTimeClock_CallRepositoryGetAll()
{
//arrange
var mockTimeClockRepository = new Moq.Mock<ITimeClockRepository>();
mockTimeClockRepository.Setup(x => x.GetAll());
var timeClockController = new TimeClockController(mockTimeClockRepository.Object);
//act
timeClockController.GetTimeClock();
//assert
mockTimeClockRepository.VerifyAll();
}
示例4: GetTimeClock_PassingAnUserNameThatDoesntExistis_ReturnNull
public void GetTimeClock_PassingAnUserNameThatDoesntExistis_ReturnNull()
{
//arrange
var userName = "Nobody";
var mockTimeClockRepository = new Moq.Mock<ITimeClockRepository>();
mockTimeClockRepository.Setup(x => x.GetByUserName(userName)).Returns<TimeClock>(null);
var timeClockController = new TimeClockController(mockTimeClockRepository.Object);
//act
timeClockController.GetTimeClock(userName);
//assert
mockTimeClockRepository.VerifyAll();
}
示例5: ShouldCallConverterForEachFile
public void ShouldCallConverterForEachFile()
{
var converter = new Moq.Mock<ICsvToSqlInsertConverter>();
var tableFactory = new Moq.Mock<ICsvTableFactory>();
var table1 = new Moq.Mock<ICsvTable>().Object;
var table2 = new Moq.Mock<ICsvTable>().Object;
tableFactory.Setup(tf => tf.CreateCsvTable("a")).Returns(table1);
tableFactory.Setup(tf => tf.CreateCsvTable("b")).Returns(table2);
converter.Setup(c => c.Convert(table1));
converter.Setup(c => c.Convert(table2));
new CsvFileProcessor(new string[] {"a", "b"}, converter.Object, tableFactory.Object).Process();
tableFactory.VerifyAll();
converter.VerifyAll();
}
示例6: TestGetOrCreateHomeWithNewHomeShouldCreateANewHome
public void TestGetOrCreateHomeWithNewHomeShouldCreateANewHome()
{
var mockPersistance = new Moq.Mock<IPersistanceFramework>();
mockPersistance.Setup(m => m.CreateQueryContext<Home>()).Returns(
TestHomes);
var homeToBeCreated = new Home();
mockPersistance.Setup(m => m.Create<Home>()).Returns(homeToBeCreated);
var repository = new HomeRepository(mockPersistance.Object);
var results = repository.GetOrCreateHome("new address", 1, 1);
Assert.AreNotEqual(TestHomes.First().Id, results.Id);
homeToBeCreated.AddressFull = "new address";
mockPersistance.VerifyAll();
}
示例7: PostClocking_WithoutKnownTimeClock_ShouldCreateATimeClock
public void PostClocking_WithoutKnownTimeClock_ShouldCreateATimeClock()
{
//arrange
var clocking = new Clocking() { Date = "10-10-2012 11:11", UserName = "Testador" };
var expectedTimeClock = new TimeClock(clocking.UserName);
expectedTimeClock.AddTime(clocking.Date);
var mockTimeClockRepository = new Moq.Mock<ITimeClockRepository>();
mockTimeClockRepository.Setup(x => x.GetByUserName(clocking.UserName)).Returns<TimeClock>(null);
mockTimeClockRepository.Setup(x => x.Store(expectedTimeClock));
var clockingController = new ClockingController(mockTimeClockRepository.Object);
//act
clockingController.PostClocking(clocking);
//assert
mockTimeClockRepository.VerifyAll();
}
示例8: Search_Wildcard
public void Search_Wildcard()
{
var foundFiles = new string[] { "z:\\abc\\def.exe" };
var wildcard = "*.exe";
var s = new DumbSearch.Service.Searcher();
var m = new Moq.Mock<DumbSearch.Service.IExplorer>(MockBehavior.Strict);
m.Setup(e => e.Explore(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), wildcard))
.Returns(new List<string>(foundFiles));
s.Explorer = m.Object;
var expected = new List<string>(foundFiles);
var actual = s.Search(wildcard);
Assert.AreEqual(expected.Count, actual.Count);
Assert.AreEqual(expected[0], actual[0]);
m.VerifyAll();
}
示例9: TestCreatingUserHomeWithNewHome
public void TestCreatingUserHomeWithNewHome()
{
var mock = new Moq.Mock<IPersistanceFramework>();
var controller = new UserHomeController();
new PrivateObject(controller).SetFieldOrProperty("Persistance",mock.Object);
mock.Setup(p => p.CreateQueryContext<Home>()).Returns(HomesList);
var newHomeThatShouldBeCreated = new Home();
mock.Setup(p => p.Create<Home>()).Returns(newHomeThatShouldBeCreated);
mock.Setup(p => p.SaveChanges());
var enteredHome = new UserHome();
enteredHome.Name = "TestName";
var userId = Guid.NewGuid();
controller.CreateChildByAddress(userId, enteredHome, "TestAddress", 1, 1);
Assert.AreEqual(userId, enteredHome.AppUserId);
Assert.AreEqual("TestAddress", enteredHome.Home.AddressFull);
mock.VerifyAll();
}
示例10: CreateOrUpdateFreeStandardAccount_InvalidEmailAddress_Test
public void CreateOrUpdateFreeStandardAccount_InvalidEmailAddress_Test()
{
//arrange
//mock email helper
var mockEmailHelper = new Moq.Mock<IEmailHelper>();
mockEmailHelper.Setup(a => a.IsValidEmail(Moq.It.IsAny<String>()))
.Returns(false);
//moq unit of work
var mockUnitOfWork = new Moq.Mock<IUnitOfWork>();
var service = new AccountsService(mockUnitOfWork.Object, mockEmailHelper.Object);
//act
//create user
var result = service.CreateOrUpdateFreeStandardAccount("[email protected]");
//assert
Assert.IsNull(result);
mockEmailHelper.VerifyAll();
}
示例11: CreateOrUpdateFreeStandardAccount_CreateAccount_Test
public void CreateOrUpdateFreeStandardAccount_CreateAccount_Test()
{
//arrange
//mock email helper
var mockEmailHelper = new Moq.Mock<IEmailHelper>();
mockEmailHelper.Setup(a => a.IsValidEmail(Moq.It.IsAny<String>()))
.Returns(true);
//mock account repository
var mockAccountsRepository = new Moq.Mock<IAccountsRepository>();
mockAccountsRepository.Setup(a => a.Where(Moq.It.IsAny<Func<Account, bool>>())).Returns(new List<Account>());
mockAccountsRepository.Setup(a => a.Create(Moq.It.IsAny<Account>())).Returns(new Account());
//mock account type repository
var mockAccountsTypeRepository = new Moq.Mock<IAccountTypesRepository>();
mockAccountsTypeRepository.Setup(a => a.Where(Moq.It.IsAny<Func<AccountType, bool>>())).Returns(() =>
{
var accounts = new List<AccountType>();
accounts.Add(new AccountType()
{
AccountTypeID = Guid.NewGuid(),
Type = "Standard"
});
return accounts;
});
//mock account payment plan account repository
var mockPaymentPlanAccountsRepository = new Moq.Mock<IPaymentPlanAccountsRepository>();
mockPaymentPlanAccountsRepository.Setup(a => a.Where(Moq.It.IsAny<Func<PaymentPlanAccount, bool>>())).Returns(() =>
{
var accounts = new List<PaymentPlanAccount>();
accounts.Add(new PaymentPlanAccount()
{
PaymentPlanAccountID = Guid.NewGuid(),
Name = "Free"
});
return accounts;
});
//mock account status type repository
var mockAccountStatusTypeRepository = new Moq.Mock<IAccountStatusTypesRepository>();
mockAccountStatusTypeRepository.Setup(a => a.Where(Moq.It.IsAny<Func<AccountStatusType, bool>>())).Returns(() =>
{
var accountStatusTypes = new List<AccountStatusType>();
accountStatusTypes.Add(new AccountStatusType()
{
AccountStatusTypeID = Guid.NewGuid(),
Type = "Active"
});
return accountStatusTypes;
});
//mock account meta data repository
var mockAccountMetaDataRepository = new Moq.Mock<IAccountMetaDatasRepository>();
mockAccountMetaDataRepository.Setup(a => a.Create(Moq.It.IsAny<AccountMetaData>())).Returns(new AccountMetaData());
//moq unit of work
var mockUnitOfWork = new Moq.Mock<IUnitOfWork>();
mockUnitOfWork.Setup(a => a.AccountsRepository).Returns(mockAccountsRepository.Object);
mockUnitOfWork.Setup(a => a.AccountTypesRepository).Returns(mockAccountsTypeRepository.Object);
mockUnitOfWork.Setup(a => a.PaymentPlanAccountsRepository).Returns(mockPaymentPlanAccountsRepository.Object);
mockUnitOfWork.Setup(a => a.AccountMetaDatasRepository).Returns(mockAccountMetaDataRepository.Object);
mockUnitOfWork.Setup(a => a.AccountStatusTypesRepository).Returns(mockAccountStatusTypeRepository.Object);
//service
var service = new AccountsService(mockUnitOfWork.Object, mockEmailHelper.Object);
//act
var result = service.CreateOrUpdateFreeStandardAccount("[email protected]");
//assert
Assert.NotNull(result);
mockPaymentPlanAccountsRepository.VerifyAll();
mockAccountsTypeRepository.VerifyAll();
mockAccountsRepository.VerifyAll();
mockEmailHelper.VerifyAll();
mockAccountMetaDataRepository.VerifyAll();
mockAccountStatusTypeRepository.VerifyAll();
}
示例12: CreateOrUpdateFreeStandardAccount_AccountExists_UpdateTimestamp_Test
public void CreateOrUpdateFreeStandardAccount_AccountExists_UpdateTimestamp_Test()
{
//arrange
//mock email helper
var mockEmailHelper = new Moq.Mock<IEmailHelper>();
mockEmailHelper.Setup(a => a.IsValidEmail(Moq.It.IsAny<String>()))
.Returns(true);
//mock account repository
var mockAccountsRepository = new Moq.Mock<IAccountsRepository>();
mockAccountsRepository.Setup( a => a.Where(Moq.It.IsAny<Func<Account,bool>>())).Returns(()=>{
var accounts = new List<Account>();
accounts.Add(new Account(){
Email = "[email protected]"
});
return accounts;
});
//update timestamp
mockAccountsRepository.Setup( a => a.Update(Moq.It.IsAny<Account>())).Returns(new Account());
//moq unit of work
var mockUnitOfWork = new Moq.Mock<IUnitOfWork>();
mockUnitOfWork.Setup(a => a.AccountsRepository).Returns(mockAccountsRepository.Object);
var service = new AccountsService(mockUnitOfWork.Object, mockEmailHelper.Object);
//act
var result = service.CreateOrUpdateFreeStandardAccount("test_u[email protected]");
//assert
Assert.NotNull(result);
mockEmailHelper.VerifyAll();
mockAccountsRepository.VerifyAll();
mockUnitOfWork.VerifyAll();
}
示例13: CreateFreeStandardAccount_CreateAccount_Test
public void CreateFreeStandardAccount_CreateAccount_Test()
{
//arrange
var newAccountGuid = Guid.NewGuid();
//mock account repository
var mockAccountsRepository = new Moq.Mock<IAccountsRepository>();
mockAccountsRepository.Setup(a => a.Create(Moq.It.IsAny<Account>())).Returns(new Account()
{
AccountID = newAccountGuid
});
//mock account type repository
Func<AccountType, bool> actualAccountsTypeExpression = null;
Func<AccountType, bool> expectedAccountsTypeExpression = at => at.Type == "Standard";
var mockAccountsTypeRepository = new Moq.Mock<IAccountTypesRepository>();
mockAccountsTypeRepository.Setup(a => a.Where(Moq.It.IsAny<Func<AccountType, bool>>())).Returns(() =>
{
var accounts = new List<AccountType>();
accounts.Add(new AccountType()
{
AccountTypeID = Guid.NewGuid(),
Type = "Standard"
});
return accounts;
}).Callback((Func<AccountType, bool> x) => actualAccountsTypeExpression = x);
//mock account payment plan account repository
Func<PaymentPlanAccount, bool> actualPaymentPlanAccountsExpression = null;
Func<PaymentPlanAccount, bool> expectedPaymentPlanAccountsExpression = ppa => ppa.Name == "Free";
var mockPaymentPlanAccountsRepository = new Moq.Mock<IPaymentPlanAccountsRepository>();
mockPaymentPlanAccountsRepository.Setup(a => a.Where(Moq.It.IsAny<Func<PaymentPlanAccount, bool>>())).Returns(() =>
{
var accounts = new List<PaymentPlanAccount>();
accounts.Add(new PaymentPlanAccount()
{
PaymentPlanAccountID = Guid.NewGuid(),
Name = "Free"
});
return accounts;
}).Callback((Func<PaymentPlanAccount, bool> x) => actualPaymentPlanAccountsExpression = x);
//mock account status type repository
Func<AccountStatusType, bool> actualAccountStatusTypeExpression = null;
Func<AccountStatusType, bool> expectedAccountStatusTypeExpression = ast => ast.Type == "Active";
var mockAccountStatusTypeRepository = new Moq.Mock<IAccountStatusTypesRepository>();
mockAccountStatusTypeRepository.Setup(a => a.Where(Moq.It.IsAny<Func<AccountStatusType, bool>>())).Returns(() =>
{
var accounts = new List<AccountStatusType>();
accounts.Add(new AccountStatusType()
{
AccountStatusTypeID = Guid.NewGuid(),
Type = "Active"
});
return accounts;
}).Callback((Func<AccountStatusType, bool> x) => actualAccountStatusTypeExpression = x);
//mock account meta data repository
var mockAccountMetaDataRepository = new Moq.Mock<IAccountMetaDatasRepository>();
mockAccountMetaDataRepository.Setup(a => a.Create(Moq.It.IsAny<AccountMetaData>())).Returns(new AccountMetaData());
//moq unit of work
var mockUnitOfWork = new Moq.Mock<IUnitOfWork>();
mockUnitOfWork.Setup(a => a.AccountsRepository).Returns(mockAccountsRepository.Object);
mockUnitOfWork.Setup(a => a.AccountTypesRepository).Returns(mockAccountsTypeRepository.Object);
mockUnitOfWork.Setup(a => a.PaymentPlanAccountsRepository).Returns(mockPaymentPlanAccountsRepository.Object);
mockUnitOfWork.Setup(a => a.AccountMetaDatasRepository).Returns(mockAccountMetaDataRepository.Object);
mockUnitOfWork.Setup(a => a.AccountStatusTypesRepository).Returns(mockAccountStatusTypeRepository.Object);
//service
var service = new AccountsService(mockUnitOfWork.Object);
//act
var result = service.CreateFreeStandardAccount("[email protected]");
//assert
Assert.AreEqual(result.AccountID, newAccountGuid);
mockPaymentPlanAccountsRepository.VerifyAll();
mockAccountsTypeRepository.VerifyAll();
mockAccountsRepository.VerifyAll();
mockAccountMetaDataRepository.VerifyAll();
mockAccountStatusTypeRepository.VerifyAll();
//make sure that the input of the Func<T,bool> are the expected inputs
Assert.AreEqual(expectedAccountsTypeExpression.ToString(), actualAccountsTypeExpression.ToString());
Assert.AreEqual(expectedPaymentPlanAccountsExpression.ToString(), actualPaymentPlanAccountsExpression.ToString());
Assert.AreEqual(expectedAccountStatusTypeExpression.ToString(), actualAccountStatusTypeExpression.ToString());
}