Moq.It.IsAny()

Here are the examples of the csharp api Moq.It.IsAny() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2353 Examples 7

19 View Source File : AccountControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

private static ControllerContext CreateControllerContext(ClaimsPrincipal principal = null)
        {
            principal = principal ?? new ClaimsPrincipal(new ClaimsIdenreplacedy());
            var mock = new Mock<IAuthenticationService>();
            mock.Setup(authS => authS.AuthenticateAsync(It.IsAny<HttpContext>(), It.IsAny<string>()))
                .ReturnsAsync<HttpContext, string, IAuthenticationService, AuthenticateResult>(
                    (ctx, scheme) =>
                    {
                        if (principal.Idenreplacedy.IsAuthenticated)
                        {
                            return AuthenticateResult.Success(new AuthenticationTicket(principal, scheme));
                        }
                        else
                        {
                            return AuthenticateResult.NoResult();
                        }
                    });
            return new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    RequestServices = new ServiceCollection()
                        .AddSingleton(mock.Object)
                        .BuildServiceProvider()
                }
            };
        }

19 View Source File : WebHookRegistrationsControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task Get_Returns_WebHooks()
        {
            // Arrange
            IEnumerable<WebHook> hooks = CreateWebHooks();
            _regsMock.Setup(r => r.GetWebHooksAsync(_principal, It.IsAny<Func<string, WebHook, Task>>()))
                .ReturnsAsync(hooks)
                .Verifiable();

            // Act
            var actual = await _controller.Get();

            // replacedert
            _regsMock.Verify();
            replacedert.Equal(WebHookCount, actual.Count());
        }

19 View Source File : WebHookRegistrationsControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task Get_Returns_EmptyList()
        {
            // Arrange
            _regsMock.Setup(r => r.GetWebHooksAsync(_principal, It.IsAny<Func<string, WebHook, Task>>()))
                .ReturnsAsync(new WebHook[0])
                .Verifiable();

            // Act
            var actual = await _controller.Get();

            // replacedert
            _regsMock.Verify();
            replacedert.Empty(actual);
        }

19 View Source File : WebHookRegistrationsControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task Lookup_Returns_WebHook()
        {
            // Arrange
            var hook = CreateWebHook();
            _regsMock.Setup(r => r.LookupWebHookAsync(_principal, TestUser, It.IsAny<Func<string, WebHook, Task>>()))
                .ReturnsAsync(hook)
                .Verifiable();

            // Act
            var result = await _controller.Lookup(TestUser);
            var actual = ((OkNegotiatedContentResult<WebHook>)result).Content;

            // replacedert
            replacedert.Equal(TestUser, actual.Id);
        }

19 View Source File : WebHookRegistrationsControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task Lookup_ReturnsNotFound_IfNotFoundWebHook()
        {
            // Arrange
            _regsMock.Setup(r => r.LookupWebHookAsync(_principal, TestUser, It.IsAny<Func<string, WebHook, Task>>()))
                .ReturnsAsync(null)
                .Verifiable();

            // Act
            var actual = await _controller.Lookup(TestUser);

            // replacedert
            replacedert.IsType<NotFoundResult>(actual);
        }

19 View Source File : WebHookRegistrationsControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task Post_ReturnsInternalServerError_IfStoreThrows()
        {
            // Arrange
            var webHook = CreateWebHook();
            _regsMock.Setup(s => s.AddWebHookAsync(_principal, webHook, It.IsAny<Func<string, WebHook, Task>>()))
                .Throws<Exception>();

            // Act
            var actual = await _controller.Post(webHook);

            // replacedert
            replacedert.Equal(HttpStatusCode.InternalServerError, ((ResponseMessageResult)actual).Response.StatusCode);
        }

19 View Source File : WebHookRegistrationsControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [MemberData(nameof(StatusData))]
        public async Task Post_ReturnsError_IfStoreReturnsNonsuccess(StoreResult result, Type response)
        {
            // Arrange
            var webHook = CreateWebHook();
            _regsMock.Setup(s => s.AddWebHookAsync(_principal, webHook, It.IsAny<Func<string, WebHook, Task>>()))
                .ReturnsAsync(result);

            // Act
            var actual = await _controller.Post(webHook);

            // replacedert
            replacedert.IsType(response, actual);
        }

19 View Source File : WebHookRegistrationsControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task Post_ReturnsCreated_IfValidWebHook()
        {
            // Arrange
            var webHook = CreateWebHook();
            _regsMock.Setup(s => s.AddWebHookAsync(_principal, webHook, It.IsAny<Func<string, WebHook, Task>>()))
                .ReturnsAsync(StoreResult.Success);

            // Act
            var actual = await _controller.Post(webHook);

            // replacedert
            replacedert.IsType<CreatedAtRouteNegotiatedContentResult<WebHook>>(actual);
        }

19 View Source File : WebHookRegistrationsControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task Put_ReturnsInternalServerError_IfStoreThrows()
        {
            // Arrange
            var webHook = CreateWebHook();
            _regsMock.Setup(s => s.UpdateWebHookAsync(_principal, webHook, It.IsAny<Func<string, WebHook, Task>>()))
                .Throws<Exception>();

            // Act
            var actual = await _controller.Put(TestUser, webHook);

            // replacedert
            replacedert.Equal(HttpStatusCode.InternalServerError, ((ResponseMessageResult)actual).Response.StatusCode);
        }

19 View Source File : WebHookRegistrationsControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [MemberData(nameof(StatusData))]
        public async Task Put_ReturnsError_IfStoreReturnsNonsuccess(StoreResult result, Type response)
        {
            // Arrange
            var webHook = CreateWebHook();
            _regsMock.Setup(s => s.UpdateWebHookAsync(_principal, webHook, It.IsAny<Func<string, WebHook, Task>>()))
                .ReturnsAsync(result);

            // Act
            var actual = await _controller.Put(TestUser, webHook);

            // replacedert
            replacedert.IsType(response, actual);
        }

19 View Source File : StorageManagerMock.cs
License : Apache License 2.0
Project Creator : aspnet

public static Mock<IStorageManager> Create()
        {
            var storageMock = new Mock<IStorageManager>();

            storageMock.Setup(s => s.GetAzureStorageConnectionString(It.IsAny<SettingsDictionary>()))
                .Returns(ConnectionString)
                .Verifiable();
            storageMock.Setup(s => s.GetCloudQueue(ConnectionString, AzureWebHookSender.WebHookQueue))
                .Returns(CloudQueue)
                .Verifiable();
            return storageMock;
        }

19 View Source File : AzureWebHookDequeueManagerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Theory]
        [MemberData(nameof(DequeueData))]
        public async Task DequeueAndSendWebHooks_GetsMessagesAndSubmitsToSender(int[] data)
        {
            // Arrange
            var index = 0;
            _storageMock.Setup(s => s.GetMessagesAsync(StorageManagerMock.CloudQueue, AzureWebHookDequeueManager.MaxDequeuedMessages, _messageTimeout))
                .Returns(() =>
                {
                    var count = index > data.Length ? 0 : data[index++];
                    if (count < 0)
                    {
                        throw new Exception("Catch this!");
                    }
                    var result = StorageManagerMock.CreateQueueMessages(count);
                    return Task.FromResult(result);
                })
                .Callback(() =>
                {
                    if (index > data.Length)
                    {
                        _tokenSource.Cancel();
                    }
                })
                .Verifiable();
            _dequeueManager = new AzureWebHookDequeueManagerMock(this, storageManager: _storageMock.Object, sender: _senderMock.Object);

            // Act
            await _dequeueManager.DequeueAndSendWebHooks(_tokenSource.Token);

            // replacedert
            var expected = data.Where(i => i > 0).Count();
            _senderMock.Verify(s => s.SendWebHookWorkItemsAsync(It.IsAny<IEnumerable<WebHookWorkItem>>()), Times.Exactly(expected));
        }

19 View Source File : MyGetWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_PackageAdded()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.PackageAddedMessage.json", "PackageAddedWebHookEventPayloadV1");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<PackageAddedPayload>()), Times.Once());
        }

19 View Source File : MyGetWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_PackageDeleted()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.PackageDeletedMessage.json", "PackageDeletedWebHookEventPayloadV1");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<PackageDeletedPayload>()), Times.Once());
        }

19 View Source File : MyGetWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_PackageListed()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.PackageListedMessage.json", "PackageListedWebHookEventPayloadV1");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<PackageListedPayload>()), Times.Once());
        }

19 View Source File : MyGetWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_PackagePinned()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.PackagePinnedMessage.json", "PackagePinnedWebHookEventPayloadV1");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<PackagePinnedPayload>()), Times.Once());
        }

19 View Source File : MyGetWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_PackagePushed()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.PackageListedMessage.json", "PackageListedWebHookEventPayloadV1");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<PackageListedPayload>()), Times.Once());
        }

19 View Source File : MyGetWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_BuildQueued()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.BuildQueuedMessage.json", "BuildQueuedWebHookEventPayloadV1");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<BuildQueuedPayload>()), Times.Once());
        }

19 View Source File : MyGetWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_BuildStarted()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.BuildStartedMessage.json", "BuildStartedWebHookEventPayloadV1");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<BuildStartedPayload>()), Times.Once());
        }

19 View Source File : MyGetWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_BuildFinished()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.BuildFinishedMessage.json", "BuildFinishedWebHookEventPayloadV1");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<BuildFinishedPayload>()), Times.Once());
        }

19 View Source File : MyGetWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Handles_UnknownPayloadProperty()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.UnknownMessage.json", "Unknown");

            // Act
            await _handler.ExecuteAsync(MyGetWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteUnknownPayloadAsync(MyGetWebHookReceiver.ReceiverName, _context, It.IsAny<JObject>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_BuildCompleted()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.build.complete.json", "build.complete");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<BuildCompletedPayload>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_CodeCheckedIn()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.tfvc.checkin.json", "tfvc.checkin");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<CodeCheckedInPayload>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_TeamRoomMessagePosted()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.message.posted.json", "message.posted");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<TeamRoomMessagePostedPayload>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_WorkItemCommentedOn()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.workitem.commented.json", "workitem.commented");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<WorkItemCommentedOnPayload>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_WorkItemCreated()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.workitem.created.json", "workitem.created");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<WorkItemCreatedPayload>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_WorkItemRestored()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.workitem.restored.json", "workitem.restored");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<WorkItemRestoredPayload>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_WorkItemUpdated()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.workitem.updated.json", "workitem.updated");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<WorkItemUpdatedPayload>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Handles_UnknownEventType()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.bad.notMappedEventType.json", "unknown");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<JObject>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_GitPush()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.git.push.json", "git.push");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<GitPushPayload>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_GitPullRequestCreated()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.git.pullrequest.created.json", "git.pullrequest.created");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<GitPullRequestCreatedPayload>()), Times.Once());
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_GitPullRequestUpdated()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.git.pullrequest.updated.json", "git.pullrequest.created");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<GitPullRequestCreatedPayload>()), Times.Once());
        }

19 View Source File : HttpConfigurationMock.cs
License : Apache License 2.0
Project Creator : aspnet

public static HttpConfiguration Create(Func<Type, object> getServiceInstance = null, Func<Type, IEnumerable<object>> getServiceInstances = null)
        {
            HttpConfiguration config = new HttpConfiguration();
            if (getServiceInstance == null)
            {
                getServiceInstance = type => null;
            }
            if (getServiceInstances == null)
            {
                getServiceInstances = type => Enumerable.Empty<object>();
            }

            // Set dependency resolver
            Mock<IDependencyResolver> dependencyResolverMock = new Mock<IDependencyResolver>();
            dependencyResolverMock.Setup(d => d.GetService(It.IsAny<Type>()))
                .Returns<Type>(t => getServiceInstance(t));
            dependencyResolverMock.Setup(d => d.GetServices(It.IsAny<Type>()))
                .Returns<Type>(t => getServiceInstances(t));
            config.DependencyResolver = dependencyResolverMock.Object;

            return config;
        }

19 View Source File : HttpConfigurationMock.cs
License : Apache License 2.0
Project Creator : aspnet

public static HttpConfiguration Create(IEnumerable<KeyValuePair<Type, object>> serviceInstances)
        {
            HttpConfiguration config = new HttpConfiguration();

            // Set dependency resolver
            Mock<IDependencyResolver> dependencyResolverMock = new Mock<IDependencyResolver>();
            dependencyResolverMock.Setup(d => d.GetService(It.IsAny<Type>()))
                .Returns<Type>(t => serviceInstances.FirstOrDefault(kvp => kvp.Key == t).Value);
            dependencyResolverMock.Setup(d => d.GetServices(It.IsAny<Type>()))
                .Returns<Type>(t => serviceInstances.Where(kvp => kvp.Key == t).Select(kvp => kvp.Value));
            config.DependencyResolver = dependencyResolverMock.Object;

            return config;
        }

19 View Source File : WebHookReceiverTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteWebHookAsync_InitializesContext()
        {
            // Arrange
            WebHookHandlerContext actual = null;
            var handlerMock = new Mock<IWebHookHandler>();
            handlerMock.Setup<Task>(h => h.ExecuteAsync(WebHookReceiverMock.ReceiverName, It.IsAny<WebHookHandlerContext>()))
                .Callback<string, WebHookHandlerContext>((rec, con) => actual = con)
                .Returns(Task.FromResult(true))
                .Verifiable();

            var handlers = new KeyValuePair<Type, object>[]
            {
                new KeyValuePair<Type, object>(typeof(IWebHookHandler), handlerMock.Object),
            };
            Initialize(TestSecret, handlers);
            var data = new object();
            IEnumerable<string> actions = new[] { "action" };

            // Act
            await _receiverMock.ExecuteWebHookAsync(TestId, _context, _request, actions, data);

            // replacedert
            handlerMock.Verify();
            replacedert.Equal(TestId, actual.Id);
            replacedert.Equal(_request, actual.Request);
            replacedert.Equal(_context, actual.RequestContext);
            replacedert.Equal(data, actual.Data);
            replacedert.Equal(actions, actual.Actions);
        }

19 View Source File : VstsWebHookHandlerBaseTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task ExecuteAsync_Dispatches_WorkItemDeleted()
        {
            // Arrange
            _context = GetContext("Microsoft.AspNet.WebHooks.Messages.workitem.deleted.json", "workitem.deleted");

            // Act
            await _handler.ExecuteAsync(VstsWebHookReceiver.ReceiverName, _context);

            // replacedert
            _handlerMock.Verify(h => h.ExecuteAsync(_context, It.IsAny<WorkItemDeletedPayload>()), Times.Once());
        }

19 View Source File : DefaultHttpClientFactoryTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void Factory_CreateClient_FiltersCanDecorateBuilder()
        {
            // Arrange
            var expected = new HttpMessageHandler[]
            {
                Mock.Of<DelegatingHandler>(), // Added by filter1
                Mock.Of<DelegatingHandler>(), // Added by filter2
                Mock.Of<DelegatingHandler>(), // Added by filter3
                Mock.Of<DelegatingHandler>(), // Added in options
                Mock.Of<DelegatingHandler>(), // Added by filter3
                Mock.Of<DelegatingHandler>(), // Added by filter2
                Mock.Of<DelegatingHandler>(), // Added by filter1

                Mock.Of<HttpMessageHandler>(), // Set as primary handler by options
            };

            Options.Get("github").HttpMessageHandlerBuilderActions.Add(b =>
            {
                b.PrimaryHandler = expected[7];

                b.AdditionalHandlers.Add((DelegatingHandler)expected[3]);
            });

            var filter1 = new Mock<IHttpMessageHandlerBuilderFilter>();
            filter1
                .Setup(f => f.Configure(It.IsAny<Action<HttpMessageHandlerBuilder>>()))
                .Returns<Action<HttpMessageHandlerBuilder>>(next => (b) =>
                {
                    next(b); // Calls filter2
                    b.AdditionalHandlers.Insert(0, (DelegatingHandler)expected[0]);
                    b.AdditionalHandlers.Add((DelegatingHandler)expected[6]);
                });

            var filter2 = new Mock<IHttpMessageHandlerBuilderFilter>();
            filter2
                .Setup(f => f.Configure(It.IsAny<Action<HttpMessageHandlerBuilder>>()))
                .Returns<Action<HttpMessageHandlerBuilder>>(next => (b) =>
                {
                    next(b); // Calls filter3
                    b.AdditionalHandlers.Insert(0, (DelegatingHandler)expected[1]);
                    b.AdditionalHandlers.Add((DelegatingHandler)expected[5]);
                });

            var filter3 = new Mock<IHttpMessageHandlerBuilderFilter>();
            filter3
                .Setup(f => f.Configure(It.IsAny<Action<HttpMessageHandlerBuilder>>()))
                .Returns<Action<HttpMessageHandlerBuilder>>(next => (b) =>
                {
                    b.AdditionalHandlers.Add((DelegatingHandler)expected[2]);
                    next(b); // Calls options
                    b.AdditionalHandlers.Add((DelegatingHandler)expected[4]);
                });

            var factory = new TestHttpClientFactory(Services, ScopeFactory, LoggerFactory, Options, new[]
            {
                filter1.Object,
                filter2.Object,
                filter3.Object,
            });

            // Act
            var handler = (HttpMessageHandler)factory.CreateHandlerEntry("github").Handler;

            // replacedert
            //
            // The outer-most handler is always a lifetime tracking handler.
            replacedert.IsType<LifetimeTrackingHttpMessageHandler>(handler);
            handler = replacedert.IsreplacedignableFrom<DelegatingHandler>(handler).InnerHandler;

            for (var i = 0; i < expected.Length - 1; i++)
            {
                replacedert.Same(expected[i], handler);
                handler = replacedert.IsreplacedignableFrom<DelegatingHandler>(handler).InnerHandler;
            }

            replacedert.Same(expected[7], handler);
        }

19 View Source File : DefaultProjectResolverTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void GetMiscellaneousProject_ProjectNotLoaded_CreatesProjectAndReturnsCreatedProject()
        {
            // Arrange
            DefaultProjectResolver projectResolver = null;
            var projects = new List<ProjectSnapshot>();
            var filePathNormalizer = new FilePathNormalizer();
            var snapshotManager = new Mock<ProjectSnapshotManagerBase>();
            snapshotManager.Setup(manager => manager.Projects)
                .Returns(() => projects);
            snapshotManager.Setup(manager => manager.GetLoadedProject(It.IsAny<string>()))
                .Returns<string>(filePath => projects.FirstOrDefault(p => p.FilePath == filePath));
            snapshotManager.Setup(manager => manager.ProjectAdded(It.IsAny<HostProject>()))
                .Callback<HostProject>(hostProject => projects.Add(Mock.Of<ProjectSnapshot>(p => p.FilePath == hostProject.FilePath)));
            var snapshotManagerAccessor = Mock.Of<ProjectSnapshotManagerAccessor>(accessor => accessor.Instance == snapshotManager.Object);
            projectResolver = new DefaultProjectResolver(Dispatcher, filePathNormalizer, snapshotManagerAccessor);

            // Act
            var project = projectResolver.GetMiscellaneousProject();

            // replacedert
            replacedert.Single(projects);
            replacedert.Equal(projectResolver._miscellaneousHostProject.FilePath, project.FilePath);
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void UpdateProject_ChangesProjectToUseProvidedConfiguration()
        {
            // Arrange
            var projectFilePath = "/C:/path/to/project.csproj";
            var ownerProject = TestProjectSnapshot.Create(projectFilePath);
            var projectSnapshotManager = new Mock<ProjectSnapshotManagerBase>(MockBehavior.Strict);
            projectSnapshotManager.Setup(manager => manager.GetLoadedProject(projectFilePath))
                .Returns(ownerProject);
            projectSnapshotManager.Setup(manager => manager.ProjectWorkspaceStateChanged(It.IsAny<string>(), It.IsAny<ProjectWorkspaceState>()));
            projectSnapshotManager.Setup(manager => manager.ProjectConfigurationChanged(It.IsAny<HostProject>()))
                .Callback<HostProject>((hostProject) =>
                {
                    replacedert.Same(FallbackRazorConfiguration.MVC_1_1, hostProject.Configuration);
                    replacedert.Equal(projectFilePath, hostProject.FilePath);
                });
            var projectService = CreateProjectService(Mock.Of<ProjectResolver>(), projectSnapshotManager.Object);

            // Act
            projectService.UpdateProject(projectFilePath, FallbackRazorConfiguration.MVC_1_1, "TestRootNamespace", ProjectWorkspaceState.Default, EmptyDoreplacedents);

            // replacedert
            projectSnapshotManager.VerifyAll();
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void UpdateProject_UntrackedProjectNoops()
        {
            // Arrange
            var projectFilePath = "/C:/path/to/project.csproj";
            var projectSnapshotManager = new Mock<ProjectSnapshotManagerBase>(MockBehavior.Strict);
            projectSnapshotManager.Setup(manager => manager.GetLoadedProject(projectFilePath))
                .Returns<ProjectSnapshot>(null);
            projectSnapshotManager.Setup(manager => manager.ProjectConfigurationChanged(It.IsAny<HostProject>()))
                .Throws(new XunitException("Should not have been called."));
            var projectService = CreateProjectService(Mock.Of<ProjectResolver>(), projectSnapshotManager.Object);

            // Act & replacedert
            projectService.UpdateProject(projectFilePath, FallbackRazorConfiguration.MVC_1_1, "TestRootNamespace", ProjectWorkspaceState.Default, EmptyDoreplacedents);
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void CloseDoreplacedent_ClosesDoreplacedentInOwnerProject()
        {
            // Arrange
            var expectedDoreplacedentFilePath = "/C:/path/to/doreplacedent.cshtml";
            var ownerProject = TestProjectSnapshot.Create("/C:/path/to/project.csproj");
            var projectResolver = new TestProjectResolver(
                new Dictionary<string, ProjectSnapshot>
                {
                    [expectedDoreplacedentFilePath] = ownerProject
                },
                TestProjectSnapshot.Create("//__MISC_PROJECT__"));
            var projectSnapshotManager = new Mock<ProjectSnapshotManagerBase>(MockBehavior.Strict);
            projectSnapshotManager.Setup(manager => manager.DoreplacedentClosed(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TextLoader>()))
                .Callback<string, string, TextLoader>((projectFilePath, doreplacedentFilePath, text) =>
                {
                    replacedert.Equal(ownerProject.HostProject.FilePath, projectFilePath);
                    replacedert.Equal(expectedDoreplacedentFilePath, doreplacedentFilePath);
                    replacedert.NotNull(text);
                });
            var projectService = CreateProjectService(projectResolver, projectSnapshotManager.Object);

            // Act
            projectService.CloseDoreplacedent(expectedDoreplacedentFilePath);

            // replacedert
            projectSnapshotManager.VerifyAll();
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void CloseDoreplacedent_ClosesDoreplacedentInMiscellaneousProject()
        {
            // Arrange
            var expectedDoreplacedentFilePath = "/C:/path/to/doreplacedent.cshtml";
            var miscellaneousProject = TestProjectSnapshot.Create("/__MISC_PROJECT__");
            var projectResolver = new TestProjectResolver(
                new Dictionary<string, ProjectSnapshot>(),
                miscellaneousProject);
            var projectSnapshotManager = new Mock<ProjectSnapshotManagerBase>(MockBehavior.Strict);
            projectSnapshotManager.Setup(manager => manager.DoreplacedentClosed(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TextLoader>()))
                .Callback<string, string, TextLoader>((projectFilePath, doreplacedentFilePath, text) =>
                {
                    replacedert.Equal(miscellaneousProject.FilePath, projectFilePath);
                    replacedert.Equal(expectedDoreplacedentFilePath, doreplacedentFilePath);
                    replacedert.NotNull(text);
                });
            var projectService = CreateProjectService(projectResolver, projectSnapshotManager.Object);

            // Act
            projectService.CloseDoreplacedent(expectedDoreplacedentFilePath);

            // replacedert
            projectSnapshotManager.VerifyAll();
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void OpenDoreplacedent_OpensAlreadyAddedDoreplacedentInOwnerProject()
        {
            // Arrange
            var expectedDoreplacedentFilePath = "/C:/path/to/doreplacedent.cshtml";
            var ownerProject = TestProjectSnapshot.Create("/C:/path/to/project.csproj");
            var projectResolver = new TestProjectResolver(
                new Dictionary<string, ProjectSnapshot>
                {
                    [expectedDoreplacedentFilePath] = ownerProject
                },
                TestProjectSnapshot.Create("/__MISC_PROJECT__"));
            var projectSnapshotManager = new Mock<ProjectSnapshotManagerBase>(MockBehavior.Strict);
            projectSnapshotManager.Setup(manager => manager.DoreplacedentAdded(It.IsAny<HostProject>(), It.IsAny<HostDoreplacedent>(), It.IsAny<TextLoader>()))
                .Throws(new InvalidOperationException("This shouldn't have been called."));
            projectSnapshotManager.Setup(manager => manager.DoreplacedentOpened(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<SourceText>()))
                .Callback<string, string, SourceText>((projectFilePath, doreplacedentFilePath, text) =>
                {
                    replacedert.Equal(ownerProject.HostProject.FilePath, projectFilePath);
                    replacedert.Equal(expectedDoreplacedentFilePath, doreplacedentFilePath);
                    replacedert.NotNull(text);
                });
            var doreplacedentSnapshot = Mock.Of<DoreplacedentSnapshot>();
            var doreplacedentResolver = Mock.Of<DoreplacedentResolver>(resolver => resolver.TryResolveDoreplacedent(It.IsAny<string>(), out doreplacedentSnapshot) == true);
            var projectService = CreateProjectService(projectResolver, projectSnapshotManager.Object, doreplacedentResolver);
            var sourceText = SourceText.From("Hello World");

            // Act
            projectService.OpenDoreplacedent(expectedDoreplacedentFilePath, sourceText, 1);

            // replacedert
            projectSnapshotManager.Verify(manager => manager.DoreplacedentOpened(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<SourceText>()));
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void OpenDoreplacedent_OpensAndAddsDoreplacedentToOwnerProject()
        {
            // Arrange
            var expectedDoreplacedentFilePath = "/C:/path/to/doreplacedent.cshtml";
            var ownerProject = TestProjectSnapshot.Create("/C:/path/to/project.csproj");
            var projectResolver = new TestProjectResolver(
                new Dictionary<string, ProjectSnapshot>
                {
                    [expectedDoreplacedentFilePath] = ownerProject
                },
                TestProjectSnapshot.Create("/__MISC_PROJECT__"));
            var projectSnapshotManager = new Mock<ProjectSnapshotManagerBase>(MockBehavior.Strict);
            projectSnapshotManager.Setup(manager => manager.DoreplacedentAdded(It.IsAny<HostProject>(), It.IsAny<HostDoreplacedent>(), It.IsAny<TextLoader>()))
                .Callback<HostProject, HostDoreplacedent, TextLoader>((hostProject, hostDoreplacedent, loader) =>
                {
                    replacedert.Same(ownerProject.HostProject, hostProject);
                    replacedert.Equal(expectedDoreplacedentFilePath, hostDoreplacedent.FilePath);
                    replacedert.NotNull(loader);
                });
            projectSnapshotManager.Setup(manager => manager.DoreplacedentOpened(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<SourceText>()))
                .Callback<string, string, SourceText>((projectFilePath, doreplacedentFilePath, text) =>
                {
                    replacedert.Equal(ownerProject.HostProject.FilePath, projectFilePath);
                    replacedert.Equal(expectedDoreplacedentFilePath, doreplacedentFilePath);
                    replacedert.NotNull(text);
                });
            var projectService = CreateProjectService(projectResolver, projectSnapshotManager.Object);
            var sourceText = SourceText.From("Hello World");

            // Act
            projectService.OpenDoreplacedent(expectedDoreplacedentFilePath, sourceText, 1);

            // replacedert
            projectSnapshotManager.VerifyAll();
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void AddDoreplacedent_NoopsIfDoreplacedentIsAlreadyAdded()
        {
            // Arrange
            var doreplacedentFilePath = "C:/path/to/doreplacedent.cshtml";
            var project = Mock.Of<ProjectSnapshot>();
            var projectResolver = new Mock<ProjectResolver>();
            projectResolver.Setup(resolver => resolver.TryResolvePotentialProject(It.IsAny<string>(), out project))
                .Throws(new InvalidOperationException("This shouldn't have been called."));
            var alreadyOpenDoc = Mock.Of<DoreplacedentSnapshot>();
            var doreplacedentResolver = Mock.Of<DoreplacedentResolver>(resolver => resolver.TryResolveDoreplacedent(It.IsAny<string>(), out alreadyOpenDoc));
            var projectSnapshotManager = new Mock<ProjectSnapshotManagerBase>(MockBehavior.Strict);
            projectSnapshotManager.Setup(manager => manager.DoreplacedentAdded(It.IsAny<HostProject>(), It.IsAny<HostDoreplacedent>(), It.IsAny<TextLoader>()))
                .Throws(new InvalidOperationException("This should not have been called."));
            var projectService = CreateProjectService(projectResolver.Object, projectSnapshotManager.Object, doreplacedentResolver);

            // Act & replacedert
            projectService.AddDoreplacedent(doreplacedentFilePath);
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void AddDoreplacedent_AddsDoreplacedentToOwnerProject()
        {
            // Arrange
            var doreplacedentFilePath = "/C:/path/to/doreplacedent.cshtml";
            var ownerProject = TestProjectSnapshot.Create("/C:/path/to/project.csproj");
            var projectResolver = new TestProjectResolver(
                new Dictionary<string, ProjectSnapshot>
                {
                    [doreplacedentFilePath] = ownerProject
                },
                TestProjectSnapshot.Create("/__MISC_PROJECT__"));
            var projectSnapshotManager = new Mock<ProjectSnapshotManagerBase>(MockBehavior.Strict);
            projectSnapshotManager.Setup(manager => manager.DoreplacedentAdded(It.IsAny<HostProject>(), It.IsAny<HostDoreplacedent>(), It.IsAny<TextLoader>()))
                .Callback<HostProject, HostDoreplacedent, TextLoader>((hostProject, hostDoreplacedent, loader) =>
                {
                    replacedert.Same(ownerProject.HostProject, hostProject);
                    replacedert.Equal(doreplacedentFilePath, hostDoreplacedent.FilePath);
                    replacedert.NotNull(loader);
                });
            var projectService = CreateProjectService(projectResolver, projectSnapshotManager.Object);

            // Act
            projectService.AddDoreplacedent(doreplacedentFilePath);

            // replacedert
            projectSnapshotManager.VerifyAll();
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void RemoveDoreplacedent_RemovesDoreplacedentFromMiscellaneousProject()
        {
            // Arrange
            var doreplacedentFilePath = "/C:/path/to/doreplacedent.cshtml";
            var miscellaneousProject = TestProjectSnapshot.Create("/__MISC_PROJECT__", new[] { doreplacedentFilePath });
            var projectResolver = new TestProjectResolver(
                new Dictionary<string, ProjectSnapshot>(),
                miscellaneousProject);
            var projectSnapshotManager = new Mock<ProjectSnapshotManagerBase>(MockBehavior.Strict);
            projectSnapshotManager.Setup(manager => manager.DoreplacedentRemoved(It.IsAny<HostProject>(), It.IsAny<HostDoreplacedent>()))
                .Callback<HostProject, HostDoreplacedent>((hostProject, hostDoreplacedent) =>
                {
                    replacedert.Same(miscellaneousProject.HostProject, hostProject);
                    replacedert.Equal(doreplacedentFilePath, hostDoreplacedent.FilePath);
                });
            var projectService = CreateProjectService(projectResolver, projectSnapshotManager.Object);

            // Act
            projectService.RemoveDoreplacedent(doreplacedentFilePath);

            // replacedert
            projectSnapshotManager.VerifyAll();
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void UpdateDoreplacedent_TracksKnownDoreplacedentVersion()
        {
            // Arrange
            var doreplacedentFilePath = "/C:/path/to/doreplacedent.cshtml";
            var ownerProject = TestProjectSnapshot.Create("/C:/path/to/project.csproj", new[] { doreplacedentFilePath });
            var projectResolver = new TestProjectResolver(
                new Dictionary<string, ProjectSnapshot>
                {
                    [doreplacedentFilePath] = ownerProject
                },
                TestProjectSnapshot.Create("/__MISC_PROJECT__"));
            DoreplacedentSnapshot doreplacedentSnapshot = TestDoreplacedentSnapshot.Create(doreplacedentFilePath);
            var doreplacedentResolver = Mock.Of<DoreplacedentResolver>(resolver => resolver.TryResolveDoreplacedent(It.IsAny<string>(), out doreplacedentSnapshot) == true);
            var doreplacedentVersionCache = new Mock<DoreplacedentVersionCache>(MockBehavior.Strict);
            doreplacedentVersionCache.Setup(cache => cache.TrackDoreplacedentVersion(doreplacedentSnapshot, It.IsAny<long>()))
                .Callback<DoreplacedentSnapshot, long>((snapshot, version) =>
                {
                    replacedert.Same(doreplacedentSnapshot, snapshot);
                    replacedert.Equal(1337, version);
                });
            var newText = SourceText.From("Something New");
            var projectService = CreateProjectService(
                projectResolver,
                Mock.Of<ProjectSnapshotManagerBase>(),
                doreplacedentResolver,
                doreplacedentVersionCache.Object);

            // Act
            projectService.UpdateDoreplacedent(doreplacedentFilePath, newText, 1337);

            // replacedert
            doreplacedentVersionCache.VerifyAll();
        }

19 View Source File : DefaultRazorProjectServiceTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void AddProject_AddsProjectWithDefaultConfiguration()
        {
            // Arrange
            var projectFilePath = "/C:/path/to/project.csproj";
            var miscellaneousProject = TestProjectSnapshot.Create("/__MISC_PROJECT__");
            var projectResolver = new TestProjectResolver(new Dictionary<string, ProjectSnapshot>(), miscellaneousProject);
            var projectSnapshotManager = new Mock<ProjectSnapshotManagerBase>(MockBehavior.Strict);
            projectSnapshotManager.Setup(manager => manager.ProjectAdded(It.IsAny<HostProject>()))
                .Callback<HostProject>((hostProject) =>
                {
                    replacedert.Equal(projectFilePath, hostProject.FilePath);
                    replacedert.Same(RazorDefaults.Configuration, hostProject.Configuration);
                });
            var projectService = CreateProjectService(projectResolver, projectSnapshotManager.Object);

            // Act
            projectService.AddProject(projectFilePath);

            // replacedert
            projectSnapshotManager.VerifyAll();
        }

19 View Source File : RazorDocumentSynchronizationEndpointTest.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task Handle_DidChangeTextDoreplacedent_UpdatesDoreplacedent()
        {
            // Arrange
            var doreplacedentPath = "C:/path/to/doreplacedent.cshtml";
            var sourceText = SourceText.From("<p>");
            var doreplacedentResolver = CreateDoreplacedentResolver(doreplacedentPath, sourceText);
            var projectService = new Mock<RazorProjectService>(MockBehavior.Strict);
            projectService.Setup(service => service.UpdateDoreplacedent(It.IsAny<string>(), It.IsAny<SourceText>(), It.IsAny<long>()))
                .Callback<string, SourceText, long>((path, text, version) =>
                {
                    var resultString = GetString(text);
                    replacedert.Equal("<p></p>", resultString);
                    replacedert.Equal(doreplacedentPath, path);
                    replacedert.Equal(1337, version);
                });
            var endpoint = new RazorDoreplacedentSynchronizationEndpoint(Dispatcher, doreplacedentResolver, projectService.Object, LoggerFactory);
            var change = new TextDoreplacedentContentChangeEvent()
            {
                Range = new Range(new Position(0, 3), new Position(0, 3)),
                RangeLength = 0,
                Text = "</p>"
            };
            var request = new DidChangeTextDoreplacedentParams()
            {
                ContentChanges = new Container<TextDoreplacedentContentChangeEvent>(change),
                TextDoreplacedent = new VersionedTextDoreplacedentIdentifier()
                {
                    Uri = new Uri(doreplacedentPath),
                    Version = 1337,
                }
            };

            // Act
            await Task.Run(() => endpoint.Handle(request, default));

            // replacedert
            projectService.VerifyAll();
        }

See More Examples