Moq.Mock.Setup(System.Linq.Expressions.Expression)

Here are the examples of the csharp api Moq.Mock.Setup(System.Linq.Expressions.Expression) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2153 Examples 7

19 View Source File : Tests.cs
License : MIT License
Project Creator : adamped

[Fact]
		public void Test()
		{
			Mock<IService> serviceMock = new Mock<IService>();
			serviceMock.Setup(x => x.Login("username", "preplacedword"))
					   .Returns(true);

			var model = new AuthenticationModel(serviceMock.Object);

			replacedert.True(model.IsAuthenticated(), "User was not authenticated");
		}

19 View Source File : MockFactories.cs
License : GNU General Public License v3.0
Project Creator : andysal

public static IHtmlHelper CreateFakeHtmlHelper()
        {
            var vd = new ViewDataDictionary();
            var mockViewContext = new Mock<ViewContext>(
                                                    new ControllerContext(
                                                        new Mock<HttpContext>().Object,
                                                        new RouteData(),
                                                        new Mock<ControllerBase>().Object),
                                                    new Mock<IView>().Object,
                                                    vd,
                                                    new TempDataDictionary(),
                                                    new Mock<TextWriter>().Object);
            var mockViewDataContainer = new Mock<IViewDataContainer>();
            mockViewDataContainer
                .Setup(v => v.ViewData)
                .Returns(vd);
            return new HtmlHelper(mockViewContext.Object, mockViewDataContainer.Object);
        }

19 View Source File : MockFactories.cs
License : GNU General Public License v3.0
Project Creator : andysal

public static HtmlHelper<T> CreateFakeHtmlHelper<T>()
        {
            var vd = new ViewDataDictionary();
            var mockViewContext = new Mock<ViewContext>(
                                                    new ControllerContext(
                                                        new Mock<HttpContext>().Object,
                                                        new RouteData(),
                                                        new Mock<ControllerBase>().Object),
                                                    new Mock<IView>().Object,
                                                    vd,
                                                    new TempDataDictionary(),
                                                    new Mock<TextWriter>().Object);
            mockViewContext
                .Setup(c => c.ClientValidationEnabled)
                .Returns(true);
            mockViewContext
                .Setup(c => c.UnobtrusiveJavaScriptEnabled)
                .Returns(true);
            mockViewContext
                .Setup(c => c.FormContext)
                .Returns(new FormContext());
            var mockViewDataContainer = new Mock<IViewDataContainer>();
            mockViewDataContainer
                .Setup(v => v.ViewData)
                .Returns(vd);
            return new HtmlHelper<T>(mockViewContext.Object, mockViewDataContainer.Object);
        }

19 View Source File : MarketingServicesTest.cs
License : GNU General Public License v3.0
Project Creator : andysal

private static Mock<ICustomerRepository> BuildCustomerRepository(decimal generatedIncome, string customerId)
        {
            var custMockBuilder = new Mock<Customer>();
            custMockBuilder.Setup(c => c.CalculateTotalIncome()).Returns(generatedIncome);
            var repoMockBuilder = new Mock<ICustomerRepository>();
            repoMockBuilder.Setup(r => r.FindById(customerId)).Returns(custMockBuilder.Object);
            return repoMockBuilder;
        }

19 View Source File : MarketingServicesTest.cs
License : GNU General Public License v3.0
Project Creator : andysal

[TestMethod]
        public void Suggested_Discount_Rate_Should_Be_Zero_For_New_Customers()
        {
            string customerId = "FAKE1";
            Customer c = Customer.CreateNewCustomer(customerId, "Managed Designs", "Andrea Saltarello");
            var repo = new Mock<ICustomerRepository>();
            repo.Setup(r => r.FindById(customerId)).Returns(c);

            MarketingServices target = new MarketingServices(repo.Object);
            replacedert.AreEqual<decimal>(0, target.CalculateSuggestedDiscountRate(customerId));
        }

19 View Source File : HomeControllerTest.cs
License : GNU General Public License v3.0
Project Creator : andysal

[TestMethod]
        public void ValidateUniqueUserName_should_return_False_on_existing_UserName()
        {
            string userName = "andysal74";

            var mock = new Mock<IHomeControllerWorkerServices>();
            mock.Setup(o => o.UserNameIsAlreadyUsed(userName)).Returns(true);

            var ctrl = new HomeController(mock.Object);

            var result = ctrl.ValidateUniqueUserName(userName);
            replacedert.IsFalse((bool)result.Data);
        }

19 View Source File : HomeControllerTest.cs
License : GNU General Public License v3.0
Project Creator : andysal

[TestMethod]
        public void ValidateUniqueUserName_should_return_True_on_non_existing_UserName()
        {
            string userName = "andysal74";

            var mock = new Mock<IHomeControllerWorkerServices>();
            mock.Setup(o => o.UserNameIsAlreadyUsed(userName)).Returns(true);

            var ctrl = new HomeController(mock.Object);

            var result = ctrl.ValidateUniqueUserName(userName + "L");
            replacedert.IsTrue((bool)result.Data);
        }

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 : ContainerServiceProviderTest.cs
License : MIT License
Project Creator : aspnet

[Fact]
        public void GetService_Should_Use_Saved_ServiceProvider_If_UnityContainer_Cannot_Resolve()
        {
            var existingSP = new Mock<IServiceProvider>();
            existingSP.Setup(sp => sp.GetService(typeof(TypeToResolveBase))).Returns(new TypeToResolve());
            var containerSP = new ContainerServiceProvider(existingSP.Object);
            var resolvedObj = containerSP.GetService(typeof(TypeToResolveBase));

            replacedert.NotNull(resolvedObj);
            replacedert.IsType<TypeToResolve>(resolvedObj);
        }

19 View Source File : ContainerServiceProviderTest.cs
License : MIT License
Project Creator : aspnet

[Fact]
        public void GetService_Should_Not_Try_UnityContainer_Again_If_UnityContainer_Failed_To_Resolve_A_Type()
        {
            var container = new Mock<IUnityContainer>();
            var isFirstCall = true;
            var secondCalled = false;
            var typeToResolve = typeof(TypeToResolveBase);

            container.Setup(sp => sp.Resolve(typeToResolve, "", null)).Callback(() =>
            {
                if(isFirstCall)
                {
                    isFirstCall = false;
                    throw new ResolutionFailedException(typeToResolve, "", "", null);
                }
                else
                {
                    secondCalled = true;
                }
            });
            var containerSP = new ContainerServiceProvider(null);
            containerSP.Container = container.Object;
            var resolvedObj = containerSP.GetService(typeToResolve);
            replacedert.NotNull(resolvedObj);
            replacedert.IsType(typeToResolve, resolvedObj);

            resolvedObj = containerSP.GetService(typeToResolve);
            replacedert.NotNull(resolvedObj);
            replacedert.IsType(typeToResolve, resolvedObj);
            replacedert.False(secondCalled);
        }

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

[Fact]
        public void GetLogger_ReturnsDependencyInstance_IfRegistered()
        {
            // Arrange
            Mock<ILogger> instanceMock = new Mock<ILogger>();
            _resolverMock.Setup(r => r.GetService(typeof(ILogger)))
                .Returns(instanceMock.Object)
                .Verifiable();

            // Act
            ILogger actual = _resolverMock.Object.GetLogger();

            // replacedert
            replacedert.Same(instanceMock.Object, actual);
            instanceMock.Verify();
        }

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

[Fact]
        public void GetSettings_ReturnsDependencyInstance_IfRegistered()
        {
            // Arrange
            SettingsDictionary instance = new SettingsDictionary();
            instance["key"] = "value";
            _resolverMock.Setup(r => r.GetService(typeof(SettingsDictionary)))
                .Returns(instance)
                .Verifiable();

            // Act
            SettingsDictionary actual = _resolverMock.Object.GetSettings();

            // replacedert
            replacedert.Same(instance, actual);
            _resolverMock.Verify();
        }

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

[Fact]
        public void GetSettings_ReturnsDefaultInstance_IfEmptyDictionaryRegistered()
        {
            // Arrange
            SettingsDictionary instance = new SettingsDictionary();
            instance.Clear();
            _resolverMock.Setup(r => r.GetService(typeof(SettingsDictionary)))
                .Returns(instance)
                .Verifiable();

            // Act
            SettingsDictionary actual = _resolverMock.Object.GetSettings();

            // replacedert
            replacedert.NotSame(instance, actual);
            _resolverMock.Verify();
        }

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

[Theory]
        [InlineData(true, false, false, false)]
        [InlineData(false, true, false, false)]
        [InlineData(false, false, true, false)]
        [InlineData(false, false, false, true)]
        public async Task Post_ReturnsBadRequest_IfValidationFails(bool failId, bool failSecret, bool failFilters, bool failAddress)
        {
            // Arrange
            var webHook = CreateWebHook();
            if (failId)
            {
                _idValidator.Setup(v => v.ValidateIdAsync(_request, webHook))
                    .Throws<Exception>();
            }
            if (failSecret)
            {
                _regsMock.Setup(v => v.VerifySecretAsync(webHook))
                    .Throws<Exception>();
            }
            if (failFilters)
            {
                _regsMock.Setup(v => v.VerifyFiltersAsync(webHook))
                    .Throws<Exception>();
            }
            if (failAddress)
            {
                _regsMock.Setup(v => v.VerifyAddressAsync(webHook))
                    .Throws<Exception>();
            }

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

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

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

[Theory]
        [InlineData(true, false, false)]
        [InlineData(false, true, false)]
        [InlineData(false, false, true)]
        public async Task Put_ReturnsBadRequest_IfValidationFails(bool failSecret, bool failFilters, bool failAddress)
        {
            // Arrange
            var webHook = CreateWebHook();
            if (failSecret)
            {
                _regsMock.Setup(v => v.VerifySecretAsync(webHook))
                    .Throws<Exception>();
            }
            if (failFilters)
            {
                _regsMock.Setup(v => v.VerifyFiltersAsync(webHook))
                    .Throws<Exception>();
            }
            if (failAddress)
            {
                _regsMock.Setup(v => v.VerifyAddressAsync(webHook))
                    .Throws<Exception>();
            }

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

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

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 : WebHookRegistrationsControllerTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public async Task Put_ReturnsOk_IfValidWebHook()
        {
            // Arrange
            var webHook = CreateWebHook();
            _regsMock.Setup(s => s.UpdateWebHookAsync(_principal, webHook, null))
                .ReturnsAsync(StoreResult.Success);

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

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

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

[Fact]
        public async Task AddPrivateFilters_Calls_RegistrarWithNoFilter()
        {
            // Arrange
            var webHook = new WebHook();
            _registrarMock.Setup(r => r.RegisterAsync(_controllerContext.Request, webHook))
                .Returns(Task.FromResult(true))
                .Verifiable();

            // Act
            await _controller.AddPrivateFilters("12345", webHook);

            // replacedert
            _registrarMock.Verify();
        }

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

[Fact]
        public async Task AddPrivateFilters_Calls_RegistrarWithFilter()
        {
            // Arrange
            var webHook = new WebHook();
            webHook.Filters.Add(FilterName);
            _registrarMock.Setup(r => r.RegisterAsync(_controllerContext.Request, webHook))
                .Returns(Task.FromResult(true))
                .Verifiable();

            // Act
            await _controller.AddPrivateFilters("12345", webHook);

            // replacedert
            _registrarMock.Verify();
        }

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

[Fact]
        public async Task AddPrivateFilters_Throws_IfRegistrarThrows()
        {
            // Arrange
            var ex = new Exception("Catch this!");
            var webHook = new WebHook();
            webHook.Filters.Add(FilterName);
            _registrarMock.Setup(r => r.RegisterAsync(_controllerContext.Request, webHook))
                .Throws(ex);

            // Act
            var rex = await replacedert.ThrowsAsync<HttpResponseException>(() => _controller.AddPrivateFilters("12345", webHook));

            // replacedert
            var error = await rex.Response.Content.ReadAsAsync<HttpError>();
            replacedert.Equal("The 'IWebHookRegistrarProxy' implementation of 'IWebHookRegistrar' caused an exception: Catch this!", error.Message);
        }

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

[Fact]
        public async Task AddPrivateFilters_Throws_HttpException_IfRegistrarThrows()
        {
            // Arrange
            var rex = new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Conflict));
            var webHook = new WebHook();
            webHook.Filters.Add(FilterName);
            _registrarMock.Setup(r => r.RegisterAsync(_controllerContext.Request, webHook))
                .Throws(rex);

            // Act
            var ex = await replacedert.ThrowsAsync<HttpResponseException>(() => _controller.AddPrivateFilters("12345", webHook));

            // replacedert
            replacedert.Same(rex, ex);
        }

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

[Fact]
        public void GetIdValidator_ReturnsDependencyInstance_IfRegistered()
        {
            // Arrange
            Mock<IWebHookIdValidator> instanceMock = new Mock<IWebHookIdValidator>();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookIdValidator)))
                .Returns(instanceMock.Object)
                .Verifiable();

            // Act
            IWebHookIdValidator actual = _resolverMock.Object.GetIdValidator();

            // replacedert
            replacedert.Same(instanceMock.Object, actual);
            instanceMock.Verify();
        }

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

[Fact]
        public void GetRegistrars_ReturnsDependencyInstances_IfRegistered()
        {
            // Arrange
            Mock<IWebHookRegistrar> instanceMock = new Mock<IWebHookRegistrar>();
            List<IWebHookRegistrar> instances = new List<IWebHookRegistrar> { instanceMock.Object };
            _resolverMock.Setup(r => r.GetServices(typeof(IWebHookRegistrar)))
                .Returns(instances)
                .Verifiable();

            // Act
            IEnumerable<IWebHookRegistrar> actual = _resolverMock.Object.GetRegistrars();

            // replacedert
            replacedert.Same(instances, actual);
            instanceMock.Verify();
        }

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 : DependencyResolverExtensionsTests.cs
License : Apache License 2.0
Project Creator : aspnet

[Fact]
        public void GetFilterManager_ReturnsDependencyInstance_IfRegistered()
        {
            // Arrange
            Mock<IWebHookFilterManager> instanceMock = new Mock<IWebHookFilterManager>();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookFilterManager)))
                .Returns(instanceMock.Object)
                .Verifiable();

            // Act
            IWebHookFilterManager actual = _resolverMock.Object.GetFilterManager();

            // replacedert
            replacedert.Same(instanceMock.Object, actual);
            instanceMock.Verify();
        }

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

[Fact]
        public void GetSender_ReturnsDependencyInstance_IfRegistered()
        {
            // Arrange
            Mock<IWebHookSender> instanceMock = new Mock<IWebHookSender>();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookSender)))
                .Returns(instanceMock.Object)
                .Verifiable();

            // Act
            IWebHookSender actual = _resolverMock.Object.GetSender();

            // replacedert
            replacedert.Same(instanceMock.Object, actual);
            instanceMock.Verify();
        }

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

[Fact]
        public void GetManager_ReturnsDependencyInstance_IfRegistered()
        {
            // Arrange
            Mock<IWebHookManager> instanceMock = new Mock<IWebHookManager>();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookManager)))
                .Returns(instanceMock.Object)
                .Verifiable();

            // Act
            IWebHookManager actual = _resolverMock.Object.GetManager();

            // replacedert
            replacedert.Same(instanceMock.Object, actual);
            instanceMock.Verify();
        }

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

[Fact]
        public void GetStore_ReturnsDependencyInstance_IfRegistered()
        {
            // Arrange
            Mock<IWebHookStore> instanceMock = new Mock<IWebHookStore>();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookStore)))
                .Returns(instanceMock.Object)
                .Verifiable();

            // Act
            IWebHookStore actual = _resolverMock.Object.GetStore();

            // replacedert
            replacedert.Same(instanceMock.Object, actual);
            instanceMock.Verify();
        }

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

[Fact]
        public void GetUser_ReturnsDependencyInstance_IfRegistered()
        {
            // Arrange
            Mock<IWebHookUser> instanceMock = new Mock<IWebHookUser>();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(instanceMock.Object)
                .Verifiable();

            // Act
            IWebHookUser actual = _resolverMock.Object.GetUser();

            // replacedert
            replacedert.Same(instanceMock.Object, actual);
            instanceMock.Verify();
        }

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

[Fact]
        public void GetFilterProviders_ReturnsDependencyInstances_IfRegistered()
        {
            // Arrange
            Mock<IWebHookFilterProvider> instanceMock = new Mock<IWebHookFilterProvider>();
            List<IWebHookFilterProvider> instances = new List<IWebHookFilterProvider> { instanceMock.Object };
            _resolverMock.Setup(r => r.GetServices(typeof(IWebHookFilterProvider)))
                .Returns(instances)
                .Verifiable();

            // Act
            IEnumerable<IWebHookFilterProvider> actual = _resolverMock.Object.GetFilterProviders();

            // replacedert
            replacedert.Same(instances, actual);
            instanceMock.Verify();
        }

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

[Fact]
        public async Task NotifyAsync_HandlesNullData()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            // Act
            await _controller.NotifyAsync("a1", data: null);

            // replacedert
            _managerMock.Verify(m => m.NotifyAsync("TestUser", It.Is<IEnumerable<NotificationDictionary>>(n => n.Single().Action == "a1"), null));
            _resolverMock.Verify();
        }

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

[Fact]
        public async Task NotifyAsync_HandlesNullDataAndNullPredicate()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            // Act
            await _controller.NotifyAsync("a1", data: null, predicate: null);

            // replacedert
            _managerMock.Verify(m => m.NotifyAsync("TestUser", It.Is<IEnumerable<NotificationDictionary>>(n => n.Single().Action == "a1"), null));
            _resolverMock.Verify();
        }

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

[Fact]
        public async Task NotifyAsync_HandlesNoNotifications()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            // Act
            int actual = await _controller.NotifyAsync();

            // replacedert
            replacedert.Equal(0, actual);
        }

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

[Fact]
        public async Task NotifyAsync_HandlesNoNotificationsAndNoPredicate()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            // Act
            int actual = await _controller.NotifyAsync(notifications: new NotificationDictionary[0], predicate: null);

            // replacedert
            replacedert.Equal(0, actual);
        }

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

[Fact]
        public async Task NotifyAsync_HandlesEmptyDictionaryData()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            // Act
            await _controller.NotifyAsync("a1", new Dictionary<string, object>());

            // replacedert
            _managerMock.Verify(m => m.NotifyAsync("TestUser", It.Is<IEnumerable<NotificationDictionary>>(n => n.Single().Action == "a1"), null));
            _resolverMock.Verify();
        }

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

[Fact]
        public async Task NotifyAsync_HandlesEmptyDictionaryDataAndNoPredicate()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            // Act
            await _controller.NotifyAsync("a1", new Dictionary<string, object>());

            // replacedert
            _managerMock.Verify(m => m.NotifyAsync("TestUser", It.Is<IEnumerable<NotificationDictionary>>(n => n.Single().Action == "a1"), null));
            _resolverMock.Verify();
        }

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

[Fact]
        public async Task NotifyAsync_HandlesEmptyObjectData()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            // Act
            await _controller.NotifyAsync("a1", new object());

            // replacedert
            _managerMock.Verify(m => m.NotifyAsync("TestUser", It.Is<IEnumerable<NotificationDictionary>>(n => n.Single().Action == "a1"), null));
            _resolverMock.Verify();
        }

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

[Fact]
        public async Task NotifyAsync_HandlesEmptyObjectDataAndNoPredicate()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            // Act
            await _controller.NotifyAsync("a1", new object(), predicate: null);

            // replacedert
            _managerMock.Verify(m => m.NotifyAsync("TestUser", It.Is<IEnumerable<NotificationDictionary>>(n => n.Single().Action == "a1"), null));
            _resolverMock.Verify();
        }

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

[Fact]
        public async Task NotifyAsync_HandlesNonemptyDictionaryData()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            // Act
            await _controller.NotifyAsync("a1", new Dictionary<string, object>() { { "d1", "v1" } });

            // replacedert
            _managerMock.Verify(m => m.NotifyAsync("TestUser", It.Is<IEnumerable<NotificationDictionary>>(n => n.Single().Action == "a1" && (string)n.Single()["d1"] == "v1"), null));
            _resolverMock.Verify();
        }

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

[Fact]
        public async Task NotifyAsync_HandlesNonemptyDictionaryDataAndPredicate()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();
            Func<WebHook, string, bool> predicate = (w, s) => true;

            // Act
            await _controller.NotifyAsync("a1", new Dictionary<string, object>() { { "d1", "v1" } }, predicate);

            // replacedert
            _managerMock.Verify(m => m.NotifyAsync("TestUser", It.Is<IEnumerable<NotificationDictionary>>(n => n.Single().Action == "a1" && (string)n.Single()["d1"] == "v1"), predicate));
            _resolverMock.Verify();
        }

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

[Fact]
        public async Task NotifyAsync_HandlesNonemptyObjectData()
        {
            // Arrange
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(_user)
                .Verifiable();

            // Act
            await _controller.NotifyAsync("a1", new { d1 = "v1" });

            // replacedert
            _managerMock.Verify(m => m.NotifyAsync("TestUser", It.Is<IEnumerable<NotificationDictionary>>(n => n.Single().Action == "a1" && (string)n.Single()["d1"] == "v1"), null));
            _resolverMock.Verify();
        }

See More Examples