public async Task WhenSearching_ShouldDispatchMessage() { // Arrange using var stash = StashMoq.Create(); var mockMediator = stash.Mock <IMediator>(); mockMediator .Setup(x => x .Send(It.IsAny <GetCatalogItems>(), It.IsAny <CancellationToken>())) .ReturnsAsync(ServiceFixture.ExpectedResponse); var controller = stash .GetWithParamOverrides <CatalogItemsController>(mockMediator) .BypassStub(stash); // Act var result = await controller.Search(); // Assert var okResult = result as OkObjectResult; okResult.Should().NotBeNull(); var responseValue = okResult !.Value as List <CatalogItemViewModel>; responseValue.Should().NotBeNull(); var responseValueItem = responseValue !.Single(); responseValueItem.Id.Should().Be(ServiceFixture.ExpectedResponseItem1.Id); responseValueItem.Name.Should().Be(ServiceFixture.ExpectedResponseItem1.Name); responseValueItem.Price.Should().Be(ServiceFixture.ExpectedResponseItem1.Price); responseValueItem.PictureUri.Should().Be(ServiceFixture.ExpectedResponseItem1.PictureUri); }
public GetCatalogItemTests() { var stash = StashMoq.Create(); _mockRepository = stash.Mock <ICatalogItemRepository>(); _sut = stash.GetWithParamOverrides <GetCatalogItemHandler>(_mockRepository); }
public void StashMoqTests_GetTest_ConstructorSelection_WithAny_NonMockabe() { using (var mock = StashMoq.Create()) { Assert.Throws <NonMockableTypeException>(() => mock.GetWithConstructorArgs <TestObj>(StashArg.Any <IDep>(), StashArg.Any <IDep2>(), StashArg.Any <string>())); } }
public void StashMoqTests_GetTest_Strict_Fail() { using (var mock = StashMoq.Create()) { mock.Mock <IDep>(MockBehavior.Strict).Setup(x => x.Test()); var m = mock.Get <TestObj>(); Assert.Throws <MockException>(() => m.Test()); } }
public void StashMoqTests_GetTest_Loose() { using (var mock = StashMoq.Create()) { mock.Mock <IDep>().Setup(x => x.Test()).Verifiable(); var m = mock.Get <TestObj>(); m.Test(); m.Test1(); } }
public void StashMoqTests_Mock_WithArg() { using (var mock = StashMoq.Create()) { var arg = new DepArg(); var m = mock.Mock <DepWithArg>(args: arg); Assert.Same(arg, m.Object.Dep); } }
public AddCatalogItemHandlerTests() { var stash = StashMoq.Create(); _mockRepository = stash.Mock <ICatalogItemRepository>(); _mockCatalogBrandRepository = stash.Mock <IAsyncRepository <CatalogBrand> >(); _mockCatalogTypeRepository = stash.Mock <IAsyncRepository <CatalogType> >(); _sut = stash .GetWithParamOverrides <AddCatalogItemHandler>(_mockRepository, _mockCatalogBrandRepository, _mockCatalogTypeRepository); }
public TestFixture() { this.Stash = StashMoq.Create(); this.server = new TestServer(WebHost .CreateDefaultBuilder() .UseEnvironment("Testing") .UseStartup <TestStartup>() .UseStashbox(this.Stash.Container)); this.httpClient = this.server.CreateClient(); }
public void StashMoqTests_GetTest_Strict() { using (var mock = StashMoq.Create()) { mock.Mock <IDep>(MockBehavior.Strict).Setup(x => x.Test()); mock.Mock <IDep>().Setup(x => x.Test2()); var m = mock.Get <TestObj>(); m.Test(); m.Test1(); } }
public void StashMoqTests_GetTest_GlobalStrict_LocalLoose() { using (var mock = StashMoq.Create(MockBehavior.Strict)) { mock.Mock <IDep>(MockBehavior.Loose).Setup(x => x.Test()); mock.Mock <IDep2>().Setup(x => x.Test1()).Returns(new object()); var m = mock.Get <TestObj>(); m.Test(); m.Test1(); } }
public void StashMoqTests_GetTest_ConstructorSelection_WithOverride_NonGeneric() { using (var mock = StashMoq.Create()) { var m = new Mock <IDep>(); var test = mock.GetWithParamOverrides <TestObj>(m.Object); Assert.Same(m.Object, test.Dep); Assert.NotNull(test.Dep2); } }
public void StashMoqTests_GetTest_ConstructorSelection_WithAny() { using (var mock = StashMoq.Create()) { var m = new Mock <IDep>(); var test = mock.GetWithConstructorArgs <TestObj>(m.Object, StashArg.Any <IDep2>()); Assert.Same(m.Object, test.Dep); Assert.NotNull(test.Dep2); } }
public void Get() { using var stash = StashMoq.Create(); var controller = stash.GetWithParamOverrides <ExampleController>().BypassStub(stash); //Call the tested method var result = controller.Get(); //Check the result var okResult = result as OkResult; okResult.Should().NotBeNull(); }
public void StashMoqTests_SameMock() { using (var mock = StashMoq.Create()) { var m1 = mock.Mock <IDep>(); var m2 = mock.Mock <IDep>(); var m3 = mock.Mock <IDep2>(); var test = mock.Get <TestObj>(); Assert.Same(m1, m2); Assert.Same(m1.Object, test.Dep); Assert.Same(m3.Object, test.Dep2); } }
public async Task GivenGetTopTenEstateAgents() { var resultOverview = GetResultOverview(); using var stash = StashMoq.Create(verifyAll: true); SetupEnvironmentGetEstateAgents(stash, resultOverview); var service = stash.Get <FundaService>(); var result = await service.TopTenEstateAgents(CancellationToken.None); result.IsSuccess.Should().BeTrue(); result.Value.Values.Should().HaveCount(resultOverview.Huizen.Count); }