当前位置: 首页>>代码示例>>C#>>正文


C# Moq.Mock.Verify方法代码示例

本文整理汇总了C#中Moq.Moq.Mock.Verify方法的典型用法代码示例。如果您正苦于以下问题:C# Moq.Mock.Verify方法的具体用法?C# Moq.Mock.Verify怎么用?C# Moq.Mock.Verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Moq.Moq.Mock的用法示例。


在下文中一共展示了Moq.Mock.Verify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ActivateAd_ActivationTokenDoesNotWork_ReturnModelIsActivatedFalse

        public void ActivateAd_ActivationTokenDoesNotWork_ReturnModelIsActivatedFalse()
        {
            // Given
            BaseAd ad = new Ad()
            {
                IsActivated = false,
                ActivationToken = "AAA"
            };
            long adId = 78;

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(x => x.Get<BaseAd>(adId)).Returns(ad);

            AdActivationServices service = new AdActivationServices(repoMock.Object, null, null, null);

            // When
            AdActivationResultModel model = service.ActivateAd(adId, "BBB");

            // Then
            Assert.IsFalse(model.IsActivated);
            Assert.AreEqual(78, model.AdId);
            Assert.AreEqual("Vous ne pouvez pas activer cette annonce.", model.InfoMessage);

            repoMock.Verify(x => x.Save(ad), Moq.Times.Never());
            repoMock.Verify(x => x.Save(Moq.It.IsAny<SearchAdCache>()), Moq.Times.Never());
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:26,代码来源:AdActivationServicesTest.cs

示例2: shouldHaveSynchronizeWithGoogleFunction

		public void shouldHaveSynchronizeWithGoogleFunction() {
			var avegaContactServiceMock = new Moq.Mock<IAvegaContactService>();
			avegaContactServiceMock.Setup(x => x.SynchronizeWithGoogleContact(It.IsAny<AvegaContact>()))
				.Returns(new SynchronizationStatus(true, false, false));

			var avetaContactService = avegaContactServiceMock.Object;
			avetaContactService.SynchronizeWithGoogleContact(new AvegaContact("MyContact"));

			avegaContactServiceMock.Verify();
		}
开发者ID:yodiz,项目名称:Avega.ContactSynchronizer,代码行数:10,代码来源:IAvegaContactServiceTest.cs

示例3: ActivateAd_ActivationTokenWorks_ReturnModelIsActivatedTrueAndActivatesAd

        public void ActivateAd_ActivationTokenWorks_ReturnModelIsActivatedTrueAndActivatesAd()
        {
            // Given
            BaseAd ad = new Ad()
            {
                IsActivated = false,
                ActivationToken = "AAA",
                City = new City(),
                Category = new Category()
            };
            long adId = 78;

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(x => x.Get<BaseAd>(adId)).Returns(ad);

            AdActivationServices service = new AdActivationServices(repoMock.Object, null, null, null);

            // When
            AdActivationResultModel model = service.ActivateAd(78, "AAA");

            // Then
            Assert.IsTrue(model.IsActivated);
            Assert.AreEqual(78, model.AdId);
            Assert.AreEqual("Merci d'avoir activé votre annonce.", model.InfoMessage);

            repoMock.Verify(x => x.Save(ad), Moq.Times.Once());
            repoMock.Verify(x => x.Save(Moq.It.IsAny<SearchAdCache>()), Moq.Times.Once());
        }
开发者ID:bea-project,项目名称:bea-web,代码行数:28,代码来源:AdActivationServicesTest.cs

示例4: shouldBeAbleToGetAllAvegaContact

		public void shouldBeAbleToGetAllAvegaContact() {
			var avegaContactServiceMock = new Moq.Mock<IAvegaContactService>();
			avegaContactServiceMock.Setup(x => x.GetAllContacts())
				.Returns(new List<AvegaContact>());

			var avetaContactService = avegaContactServiceMock.Object;
			avetaContactService.GetAllContacts();

			avegaContactServiceMock.Verify();
		}
开发者ID:yodiz,项目名称:Avega.ContactSynchronizer,代码行数:10,代码来源:IAvegaContactServiceTest.cs

示例5: CancelAsync

        public void CancelAsync()
        {
            var element = new ImportNetworkElement();
            var mockMyFx = new Moq.Mock<IImportNetworkFx>();

            mockMyFx.Setup(m => m.CancelAsync());

            element.Fx = mockMyFx.Object;
            element.Cancel();
            mockMyFx.Verify(m => m.CancelAsync(), Times.Exactly(1));
        }
开发者ID:BgRva,项目名称:Blob1,代码行数:11,代码来源:ImportNetworkFixture.cs

示例6: ReadTransactionsFromFile_Valid_ObserverNeverCalled

        public void ReadTransactionsFromFile_Valid_ObserverNeverCalled()
        {
            var mockObserver = new Moq.Mock<Observer>();
            List<Observer> ol = new List<Observer>();
            ol.Add(mockObserver.Object);
            List<Product> listOfProducts = new List<Product>();
            TransactionManager tm = new TransactionManager(ol, listOfProducts);

            tm.ReadTransactionsFromFile(new StreamReader(@"C:\Users\vbhujan\Documents\Cart.txt"));

            mockObserver.Verify(o => o.update(), Times.Never);
        }
开发者ID:avinashbhujan,项目名称:SalesTaxObserverPatternWithLucene,代码行数:12,代码来源:TransactionManagerTests.cs

示例7: SafeDisposal

        public void SafeDisposal()
        {
            var exceptionHandler = new Moq.Mock<IExceptionHandler>(MockBehavior.Strict);
            exceptionHandler.Setup(x => x.Warn(It.IsAny<Exception>())).Returns<Exception>(x => x).Verifiable();

            ExceptionHandler.Initialise(exceptionHandler.Object);

            var t = new ThrowingDisposableObject();
            t.Dispose();

            Assert.That(t.DisposeUnmanagedResourcesCount, Is.EqualTo(1));
            Assert.That(t.DisposeManagedResourcesCount, Is.EqualTo(1));
            exceptionHandler.Verify(x => x.Warn(It.IsAny<Exception>()), Times.Once());
        }
开发者ID:andy-uq,项目名称:Echo,代码行数:14,代码来源:DisposableObjectTests.cs

示例8: AggregateBus_ShouldSubscribeWhenConfigured

        public void AggregateBus_ShouldSubscribeWhenConfigured()
        {
            var eventBus = new Moq.Mock<IEventBus>();
            eventBus.Setup(e => e.Subscribe<AggregateCacheCleared>(Moq.It.IsAny<Func<AggregateCacheCleared, Task>>())).Verifiable();
            var aggregateCache = new Moq.Mock<IAggregateCache>();
            //aggregateCache.Setup(x => x.Clear(Moq.It.IsAny<Guid>(), Moq.It.IsAny<Type>())).Verifiable();

            AggregateBus.Instance.Configure(eventBus.Object, aggregateCache.Object);

            AggregateBus.Instance.RegisteredAggregateCaches.Should().NotBeNull();
            AggregateBus.Instance.RegisteredAggregateCaches.Contains(aggregateCache.Object).Should().BeTrue();

            eventBus.Verify(e => e.Subscribe<AggregateCacheCleared>(Moq.It.IsAny<Func<AggregateCacheCleared, Task>>()), Moq.Times.Once);
        }
开发者ID:wallaceiam,项目名称:CQRS.Light,代码行数:14,代码来源:AggregateBusTests.cs

示例9: RequestHandlerRetriesTest

        public void RequestHandlerRetriesTest()
        {
            //This statement will fail, then we will fake the syntax error as a ReadTimeout
            var statement = new SimpleStatement("SELECT WILL FAIL").SetRetryPolicy(DowngradingConsistencyRetryPolicy.Instance);
            var request = Session.GetRequest(statement);
            //We will need a mock to fake the responses of Cassandra
            var mock = new Moq.Mock<RequestHandler<RowSet>>(Session, request, statement);
            var requestHandler = mock.Object;
            //Expect Retry method to be called with a lower consistency level
            mock.Setup(r => r.Retry(It.Is<ConsistencyLevel?>(c => c == ConsistencyLevel.Two))).Verifiable();
            //Fake a Error Result
            requestHandler.ResponseHandler(new ReadTimeoutException(ConsistencyLevel.Three, 2, 3, false), null);

            mock.Verify();
        }
开发者ID:rasmus-s,项目名称:csharp-driver,代码行数:15,代码来源:RequestHandlerTests.cs

示例10: Add_new_task

		public async Task Add_new_task()
		{
			// arrange
			var newTask = new TodoItem() { Completed = false, Title = "Test 3" };
			var serviceMock = new Moq.Mock<ITodoService>();
			serviceMock.Setup(x => x.AddAsync(newTask)).ReturnsAsync(newTask);
			var controller = new TodoController(serviceMock.Object);

			// act
			var result = await controller.AddTodo(newTask);

			// assert
			serviceMock.Verify(x => x.AddAsync(newTask), Times.Once);
			Assert.NotNull(result);
			Assert.Equal(newTask, result);
		}
开发者ID:rdacorp,项目名称:UnitTesting-Lab,代码行数:16,代码来源:US2.cs

示例11: Status_not_found_when_deleting_task_that_does_not_exist

		public async Task Status_not_found_when_deleting_task_that_does_not_exist()
		{
			// arrange
			var taskId = 1;
			var serviceMock = new Moq.Mock<ITodoService>();
			serviceMock.Setup(x => x.DeleteAsync(taskId)).ReturnsAsync(false);
			var controller = new TodoController(serviceMock.Object);

			// act
			var result = await controller.DeleteTodo(taskId);

			// assert
			serviceMock.Verify(x => x.DeleteAsync(taskId), Times.Once);
			Assert.NotNull(result);
			Assert.Equal(HttpStatusCode.NotFound, result.StatusCode);
		}
开发者ID:rdacorp,项目名称:UnitTesting-Lab,代码行数:16,代码来源:US4.cs

示例12: Delete_task

		public async Task Delete_task()
		{
			// arrange
			var taskId = 1;
			var serviceMock = new Moq.Mock<ITodoService>();
			serviceMock.Setup(x => x.DeleteAsync(taskId)).ReturnsAsync(true);
			var controller = new TodoController(serviceMock.Object);

			// act
			var result = await controller.DeleteTodo(taskId);

			// assert
			serviceMock.Verify(x => x.DeleteAsync(taskId), Times.Once);
			Assert.NotNull(result);
			Assert.Equal(HttpStatusCode.OK, result.StatusCode);
		}
开发者ID:rdacorp,项目名称:UnitTesting-Lab,代码行数:16,代码来源:US4.cs

示例13: Change_completeness_of_task

		public async Task Change_completeness_of_task()
		{
			// arrange
			var existingTask = new TodoItem() { Id = 2, Completed = true, Title = "Test 1" };
			var serviceMock = new Moq.Mock<ITodoService>();
			serviceMock.Setup(x => x.UpdateAsync(existingTask.Id, existingTask)).ReturnsAsync(existingTask);
			var controller = new TodoController(serviceMock.Object);

			// act
			var result = await controller.UpdateTodo(existingTask.Id, existingTask);

			// assert
			serviceMock.Verify(x => x.UpdateAsync(existingTask.Id, existingTask), Times.Once);
			Assert.NotNull(result);
			Assert.Equal(existingTask, result);
		}
开发者ID:rdacorp,项目名称:UnitTesting-Lab,代码行数:16,代码来源:US3.cs

示例14: Status_not_found_when_changing_task_that_does_not_exist

		public void Status_not_found_when_changing_task_that_does_not_exist()
		{
			// arrange
			var taskId = 4;
			var existingTask = new TodoItem() { Id = 2, Completed = false, Title = "Test 3" };
			var serviceMock = new Moq.Mock<ITodoService>();
			serviceMock.Setup(x => x.UpdateAsync(taskId, existingTask)).ReturnsAsync(null);
			var controller = new TodoController(serviceMock.Object);

			// act
			var exc = Assert.Throws<AggregateException>(() => controller.UpdateTodo(taskId, existingTask).Result);
			var result = exc.InnerExceptions.Cast<HttpResponseException>().FirstOrDefault();

			// assert
			serviceMock.Verify(x => x.UpdateAsync(taskId, existingTask), Times.Once);
			Assert.NotNull(result);
			Assert.Equal(HttpStatusCode.NotFound, result.Response.StatusCode);
		}
开发者ID:rdacorp,项目名称:UnitTesting-Lab,代码行数:18,代码来源:US3.cs

示例15: shouldReportBackContactFetchProgress

		public void shouldReportBackContactFetchProgress() {
			var avegaClientRepositoryMock = new Moq.Mock<IAvegaClientRepository>();
			avegaClientRepositoryMock.Setup(x => x.GetAll())
				.Returns(new List<AvegaContact>(new[] { new AvegaContact("DisplayName"), new AvegaContact("DisplayName") }));

			var avegaClientRepository = avegaClientRepositoryMock.Object;

			avegaClientRepository.ContactDataFetched += (sender, ev) => {
				Console.WriteLine(ev.TotalContacts);
				Console.WriteLine(ev.CurrentContactIndex);
				switch (ev.DataFetched) {
					case DataFetchedType.Image: break;
					case DataFetchedType.ContactInformation: break;
				}
			};

			avegaClientRepository.GetAll();
			avegaClientRepositoryMock.Verify();
		}
开发者ID:yodiz,项目名称:Avega.ContactSynchronizer,代码行数:19,代码来源:IAvegaClientRepositoryTest.cs


注:本文中的Moq.Moq.Mock.Verify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。