本文整理汇总了C#中Mock.VerifyAll方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.VerifyAll方法的具体用法?C# Mock.VerifyAll怎么用?C# Mock.VerifyAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mock
的用法示例。
在下文中一共展示了Mock.VerifyAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateFrequencyTest
public void CalculateFrequencyTest()
{
var view = new Mock<IMainGameView>();
var controller = new MainGameController(view.Object);
controller.LoadKeysResources(TestKeyFileResource);
view.Setup(x => x.PlaySound(It.Is<int>(f => f == 110), 100));
controller.ProcessKey(Keys.Q); //key#0
view.VerifyAll();
view.Reset();
view.Setup(x => x.PlaySound(It.Is<int>(f => f == 117), 100));
controller.ProcessKey(Keys.W); //key#0
view.VerifyAll();
view.Reset();
view.Setup(x => x.PlaySound(It.Is<int>(f => f == 175), 100));
controller.ProcessKey(Keys.O); //key#8
view.VerifyAll();
view.Reset();
view.Setup(x => x.PlaySound(It.Is<int>(f => f == 185), 100));
controller.ProcessKey(Keys.P); //key#9
view.VerifyAll();
}
示例2: Test_ExecuteScripts_TwoFileContent
public void Test_ExecuteScripts_TwoFileContent()
{
const bool expectedResult = true;
const string fileContent = @"create table BackendUser (BackendUserId int, Username nvarchar(30))
;
insert into BackendUser values(1, ""I must go home.""))
;";
var dbConnectionMock = new Mock<IDbConnection>();
var databaseMock = new Mock<IDatabase>();
var dbCommandMock = new Mock<IDbCommand>();
databaseMock.Setup(t => t.GetDbConnection()).Returns(dbConnectionMock.Object);
databaseMock.Setup(t => t.GetDbCommand()).Returns(dbCommandMock.Object);
dbConnectionMock.Setup(t => t.Open());
dbCommandMock.Setup(t => t.ExecuteNonQuery());
IDbProvider provider = new FireBirdDbProvider(databaseMock.Object);
var actualResult = provider.ExecuteScript(fileContent);
dbCommandMock.VerifyAll();
databaseMock.VerifyAll();
dbCommandMock.VerifyAll();
Assert.Equal(expectedResult, actualResult);
}
示例3: Test_ExecuteScripts_TwoFileContent_WithGo
public void Test_ExecuteScripts_TwoFileContent_WithGo()
{
const string fileContent = @"create table BackendUser (BackendUserId int, Username nvarchar(30))
go
create table Company (CompanyId int, Name nvarchar(30))
go";
const bool expectedResult = true;
var dbConnectionMock = new Mock<IDbConnection>();
var databaseMock = new Mock<IDatabase>();
var dbCommandMock = new Mock<IDbCommand>();
databaseMock.Setup(t => t.GetDbConnection()).Returns(dbConnectionMock.Object);
databaseMock.Setup(t => t.GetDbCommand()).Returns(dbCommandMock.Object);
dbConnectionMock.Setup(t => t.Open());
dbCommandMock.Setup(t => t.ExecuteNonQuery());
IDbProvider provider = new MsSqlDbProvider(databaseMock.Object);
var actualResult = provider.ExecuteScript(fileContent);
dbCommandMock.VerifyAll();
databaseMock.VerifyAll();
dbCommandMock.VerifyAll();
Assert.Equal(expectedResult, actualResult);
}
示例4: CreatesMockForAccessedPropertyWithSetterWithValue
public void CreatesMockForAccessedPropertyWithSetterWithValue()
{
var mock = new Mock<IFoo>();
mock.SetupSet(m => m.Bar.Value = 5);
Assert.NotNull(mock.Object.Bar);
Assert.Throws<MockVerificationException>(() => mock.VerifyAll());
mock.Object.Bar.Value = 5;
mock.VerifyAll();
}
示例5: Fetch
public void Fetch()
{
var person = EntityCreator.Create<E.Person>();
var people = new InMemoryDbSet<E.Person> { person };
var context = new Mock<IEntityContext>(MockBehavior.Strict);
context.Setup(_ => _.People).Returns(people);
context.Setup(_ => _.Dispose());
var personViewFactory = new Mock<IObjectFactory<IPersonView>>(MockBehavior.Strict);
personViewFactory
.Setup(_ => _.FetchChild(It.Is<int>(__ => __ == person.Id)))
.Returns(Mock.Of<IPersonView>());
var container = new ContainerBuilder();
container.Register<IEntityContext>(_ => context.Object);
container.Register<IObjectFactory<IPersonView>>(_ => personViewFactory.Object);
using (container.Build().Bind(() => IoC.Container))
{
var actual = DataPortal.Fetch<PersonCollectionView>();
Assert.IsNotNull(actual);
Assert.AreEqual(1, actual.Count, "Count");
}
context.VerifyAll();
personViewFactory.VerifyAll();
}
示例6: LogActivity_Complete_writes_current_method_name
public void LogActivity_Complete_writes_current_method_name()
{
var methodName = MethodBase.GetCurrentMethod().Name;
var observer = new Mock<IObserver<LogEntry>>();
observer
.Setup(
o => o.OnNext(
It.Is<LogEntry>(
e => e.CallingMethod == methodName &&
e.EventType == TraceEventType.Stop)));
var helper = new AsyncTestHelper();
using (var activity = Log.Enter(() => { }))
using (TestHelper.LogToConsole())
using (observer.Object.SubscribeToLogEvents())
{
var result = helper.BeginSomething(
_ => activity.Complete(() => { }),
activity);
helper.EndSomething(result);
}
observer.VerifyAll();
}
示例7: TestExecuteClearsDataIfElementIsFound
public void TestExecuteClearsDataIfElementIsFound()
{
var propData = new Mock<IPropertyData>(MockBehavior.Strict);
propData.Setup(p => p.ClearData());
// ReSharper disable once RedundantAssignment
IPropertyData element = null;
var locator = new Mock<IElementLocator>(MockBehavior.Strict);
locator.Setup(p => p.TryGetElement("myitem", out element)).Returns(false);
locator.Setup(p => p.GetProperty("myitem")).Returns(propData.Object);
var getItemAction = new ClearDataAction
{
ElementLocator = locator.Object
};
var context = new ClearDataAction.ClearDataContext("myitem");
var result = getItemAction.Execute(context);
Assert.AreEqual(true, result.Success);
locator.VerifyAll();
propData.VerifyAll();
}
示例8: ShouldBeAbleToPullExistingInfoFromCache
public void ShouldBeAbleToPullExistingInfoFromCache()
{
var monitorConfig = new MonitorConfig { Name = "Test" };
var reduceLevels = new List<ReduceLevel>();
var connection = new Mock<IDbConnection>();
var connectionInstance = connection.Object;
var storageCommands = new Mock<IStorageCommands>();
storageCommands.Setup(x => x.CreateConfigAndReduceLevels(monitorConfig, reduceLevels, connectionInstance));
var setupSystemTables = new Mock<ISetupSystemTables>();
setupSystemTables.Setup(x => x.ValidateAndCreateDataTables(connectionInstance)).Verifiable();
var monitorConfigsDictionary = new ConcurrentDictionary<string, MonitorConfig>();
var cache = new Mock<IDataCache>();
cache.SetupGet(x => x.MonitorConfigs).Returns(monitorConfigsDictionary).Verifiable();
var storageFactory = new Mock<IStorageFactory>();
storageFactory.Setup(x => x.CreateConnection()).Returns(connectionInstance).Verifiable();
var settings = BuildSettings();
var defaults = new SetupMonitorConfig(storageCommands.Object, setupSystemTables.Object, cache.Object, storageFactory.Object, settings.Object);
defaults.CreateDefaultReduceLevels(monitorConfig, reduceLevels);
Assert.Equal(1, monitorConfigsDictionary.Count);
Assert.True(monitorConfigsDictionary.ContainsKey("Test"));
storageCommands.VerifyAll();
setupSystemTables.VerifyAll();
storageFactory.VerifyAll();
cache.VerifyAll();
}
示例9: ShouldCallExceptionHandlerOnUncaughtException
public void ShouldCallExceptionHandlerOnUncaughtException()
{
var ex = new Exception();
var exceptionHandlerMock = new Mock<IExceptionHandler<object>>();
_batchEventProcessor.SetExceptionHandler(exceptionHandlerMock.Object);
_batchHandlerMock.Setup(bh => bh.OnEvent(_ringBuffer[0], 0, true))
.Throws(ex); // OnNext raises an expcetion
exceptionHandlerMock.Setup(bh => bh.HandleEventException(ex, 0, _ringBuffer[0]))
.Callback(() => _countDownEvent.Signal()); // Exception should be handled here and signal the CDE
var thread = new Thread(_batchEventProcessor.Run);
thread.Start();
_ringBuffer.Publish(_ringBuffer.Next());
_countDownEvent.Wait(50);
_batchEventProcessor.Halt();
thread.Join();
_batchHandlerMock.VerifyAll();
exceptionHandlerMock.VerifyAll();
}
示例10: GetRecommendations_PerformsCorrectRequest
public void GetRecommendations_PerformsCorrectRequest()
{
//Setup
UserReqStub request = new UserReqStub("ExternalID", "DevKey", "api.careerbuilder.com", "", "");
//Mock crap
RestResponse<List<RecommendJobResult>> response = new RestResponse<List<RecommendJobResult>>();
response.Data = new List<RecommendJobResult>();
var restReq = new Mock<IRestRequest>();
restReq.Setup(x => x.AddParameter("DeveloperKey", "DevKey"));
restReq.Setup(x => x.AddParameter("ExternalID", "ExternalID"));
restReq.SetupSet(x => x.RootElement = "RecommendJobResults");
var restClient = new Mock<IRestClient>();
restClient.SetupSet(x => x.BaseUrl = "https://api.careerbuilder.com/v1/recommendations/foruser");
restClient.Setup(x => x.Execute<List<RecommendJobResult>>(It.IsAny<IRestRequest>())).Returns(response);
request.Request = restReq.Object;
request.Client = restClient.Object;
//Assert//
List<RecommendJobResult> resp = request.GetRecommendations();
restReq.VerifyAll();
restClient.VerifyAll();
}
开发者ID:stevenwu2012,项目名称:Careerbuilder.com-API-for-.Net,代码行数:26,代码来源:UserRecommendationsRequestTest.cs
示例11: AssociationSetDiscoveryConvention_AddsBindingForBaseAndDerivedNavigationProperties
public void AssociationSetDiscoveryConvention_AddsBindingForBaseAndDerivedNavigationProperties()
{
// Arrange
ODataModelBuilder builder = new ODataModelBuilder();
EntityTypeConfiguration vehicle = builder.AddEntity(typeof(Vehicle));
EntityTypeConfiguration car = builder.AddEntity(typeof(Car)).DerivesFrom(vehicle);
NavigationPropertyConfiguration carNavigationProperty = car.AddNavigationProperty(typeof(Car).GetProperty("Manufacturer"), EdmMultiplicity.ZeroOrOne);
EntityTypeConfiguration motorcycle = builder.AddEntity(typeof(Motorcycle)).DerivesFrom(vehicle);
NavigationPropertyConfiguration motorcycleNavigationProperty = motorcycle.AddNavigationProperty(typeof(Motorcycle).GetProperty("Manufacturer"), EdmMultiplicity.ZeroOrOne);
EntityTypeConfiguration manufacturer = builder.AddEntity(typeof(Manufacturer));
EntityTypeConfiguration motorcycleManufacturer = builder.AddEntity(typeof(MotorcycleManufacturer)).DerivesFrom(manufacturer);
EntityTypeConfiguration carManufacturer = builder.AddEntity(typeof(CarManufacturer)).DerivesFrom(manufacturer);
EntitySetConfiguration manufacturers = builder.AddEntitySet("manufacturers", manufacturer);
Mock<EntitySetConfiguration> entitySet = new Mock<EntitySetConfiguration>(MockBehavior.Strict);
entitySet.Setup(v => v.EntityType).Returns(vehicle);
entitySet.Setup(v => v.AddBinding(motorcycleNavigationProperty, manufacturers)).Returns<NavigationPropertyConfiguration>(null);
entitySet.Setup(v => v.AddBinding(carNavigationProperty, manufacturers)).Returns<NavigationPropertyConfiguration>(null);
// Act
_convention.Apply(entitySet.Object, builder);
// Assert
entitySet.VerifyAll();
}
示例12: EditCommentTest
public async Task EditCommentTest(
EditCommentMode mode,
string fileExtension,
string commentStart,
string commentEnd = null)
{
// Arrange
string commentName = "CommentName";
string filePath = @"C:\Project\File" + fileExtension;
Mock<IFileSystemService> fileSystemServiceMock = new Mock<IFileSystemService>(MockBehavior.Strict);
fileSystemServiceMock
.Setup(x => x.FileExists(It.Is<string>(y => string.Equals(y, filePath))))
.Returns(true);
fileSystemServiceMock
.Setup(x => x.FileReadAllLines(It.Is<string>(y => string.Equals(y, filePath))))
.Returns(Task.FromResult(GetInputLines(commentName, commentStart, commentEnd)));
fileSystemServiceMock
.Setup(x => x.FileWriteAllLines(
It.Is<string>(y => string.Equals(y, filePath)),
It.Is<IEnumerable<string>>(y => Enumerable.SequenceEqual(y, GetOutputLines(mode, commentStart, commentEnd)))))
.Returns(Task.FromResult<object>(null));
IProjectService projectService = new ProjectService(fileSystemServiceMock.Object, @"C:\Project\Project.xproj");
// Act
await projectService.EditComment(commentName, mode, "File" + fileExtension);
// Assert
fileSystemServiceMock.VerifyAll();
}
示例13: op_Verify_IRepository
public void op_Verify_IRepository()
{
var key = AlphaDecimal.Random();
var obj = new RepositoryMatchKey<RandomObject>
{
Record1 =
{
Key = key
}
};
var repository = new Mock<IRepository<RandomObject>>();
repository
.Setup(x => x.Insert(obj.Record1))
.Returns(obj.Record1)
.Verifiable();
repository
.Setup(x => x.Match(key, obj.Record1.Etag))
.Returns(true)
.Verifiable();
obj.Verify(repository.Object);
repository.VerifyAll();
}
示例14: AddPostValidModel_ReturnsRedirect
public void AddPostValidModel_ReturnsRedirect()
{
var volunteerFake = new Volunteer
{
Id = Guid.NewGuid(),
};
var recipientFake = new Recipient
{
Active = true,
FirstName = "Dan",
Id = Guid.NewGuid(),
};
var dataServiceMock = new Mock<IDataService<Recipient>>();
dataServiceMock.Setup(d => d.Insert(It.IsAny<Recipient>(), It.IsAny<Guid>())).Verifiable();
var formsAuthenticationServiceMock = new Mock<IFormsAuthenticationService>();
formsAuthenticationServiceMock.Setup(f => f.GetVolunteerID(null))
.Returns(volunteerFake.Id);
var controller = new RecipientController(dataServiceMock.Object,
new Mock<IDataService<Volunteer>>().Object,
formsAuthenticationServiceMock.Object);
ActionResult result = controller.Add(recipientFake);
dataServiceMock.VerifyAll();
Assert.IsInstanceOf(typeof (RedirectToRouteResult), result);
}
示例15: Given_that_request_is_valid_When_mark_hazard_as_deleted_Then_should_call_correct_methods
public void Given_that_request_is_valid_When_mark_hazard_as_deleted_Then_should_call_correct_methods()
{
//Given
var target = CreateNonEmployeeervice();
var hazard = new Mock<Hazard>();
hazard.Setup(x => x.MarkForDelete(_user.Object));
var request = new MarkCompanyDefaultAsDeletedRequest(1, 2, Guid.NewGuid());
_userRepository
.Setup(x => x.GetByIdAndCompanyId(request.UserId, request.CompanyId))
.Returns(_user.Object);
_repo
.Setup(x => x.GetByIdAndCompanyId(request.CompanyDefaultId, request.CompanyId))
.Returns(hazard.Object);
//When
target.MarkHazardAsDeleted(request);
//Then
hazard.VerifyAll();
_repo.Verify(x => x.SaveOrUpdate(It.IsAny<Hazard>()));
}