示例#1
0
        public void ShouldAssertRaisesAgainstMethod()
        {
            var container = new MockingContainer <Executor>();

            bool raised = false;

            container.Arrange <IExecutor>(x => x.Submit()).Raises(() => container.Get <IExecutor>().Done += null, EventArgs.Empty);

            container.Get <IExecutor>().Done += delegate { raised = true; };

            container.Instance.Submit();

            Assert.True(raised);
        }
        public void Test()
        {
            // Arrange
            using var container = new MockingContainer <MyClassAuto>();

            container.Arrange <INameProvider>(x => x.GetName()).Returns("A Name").MustBeCalled();
            // or
            //var nameProviderMock = Mock.Create<INameProvider>();
            //nameProviderMock.Arrange(x => x.GetName()).Returns("A Name").MustBeCalled();
            //container.Bind<INameProvider>().ToConstant(nameProviderMock);

            // Act
            var sut = container.Instance;

            sut.DoGreeting();

            // Assert
            container.Assert();

            var greetingServiceMock = container.Get <IGreetingService>();

            greetingServiceMock.Assert(x => x.Greet("A Name"));

            //Assert.Equal(1, Mock.GetTimesCalled(() => greetingServiceMock.Greet("A Name")));

            // This throws an exception
            //Assert.Equal(1, Mock.GetTimesCalled(() => container.Get<IGreetingService>().Greet("A Name")));
        }
示例#3
0
        public void ShouldMakeSingletonExplicitlyRequestedServices()
        {
            var container = new MockingContainer <Module>();
            var s1        = container.Get <IService>();
            var s2        = container.Instance.service;

            Assert.Same(s1, s2);
        }
        public void ShouldAssertPropertySetWithMatcher()
        {
            // Arrange
            var container = new MockingContainer <Module>();

            // Act
            container.Get <IService>().Value = 99;

            // Assert
            container.AssertSet <IService>(x => x.Value = Arg.AnyInt);
        }
示例#5
0
        public void ShouldInjectContainers()
        {
            var c           = new MockingContainer <DisposableContainer>();
            var disposables = new List <IDisposable> {
                Mock.Create <IDisposable>(), Mock.Create <IDisposable>()
            };
            var i = c.Get <DisposableContainer>(new ConstructorArgument("disposables", disposables));

            i.Dispose();

            Assert.Equal(0, disposables.Count);
        }
        public void ShouldArrangePropertySetWithMatcher()
        {
            // Arrange
            var container = new MockingContainer <Module>();

            container.ArrangeSet <IService>(x => x.Value = Arg.AnyInt).MustBeCalled();
            var service = container.Get <IService>();

            // Act
            service.Value = 99;

            // Assert
            container.Assert <IService>();
        }
		public void ShouldInjectContainers()
		{
			var c = new MockingContainer<DisposableContainer>();
			var disposables = new List<IDisposable> { Mock.Create<IDisposable>(), Mock.Create<IDisposable>() };
			var i = c.Get<DisposableContainer>(new ConstructorArgument("disposables", disposables));
			i.Dispose();

			Assert.Equal(0, disposables.Count);
		}
		public void ShouldAssertRaisesAgainstMethod()
		{
			var container = new MockingContainer<Executor>();

			bool raised = false;

			container.Arrange<IExecutor>(x => x.Submit()).Raises(() => container.Get<IExecutor>().Done += null, EventArgs.Empty);

			container.Get<IExecutor>().Done += delegate { raised = true; };

			container.Instance.Submit();

			Assert.True(raised);
		}
		public void ShouldMakeSingletonExplicitlyRequestedServices()
		{
			var container = new MockingContainer<Module>();
			var s1 = container.Get<IService>();
			var s2 = container.Instance.service;
			Assert.Same(s1, s2);
		}
示例#10
0
		public void ShouldArrangeRaisesBehaviorOnSecondInstance()
		{
			var amount = 100M;
			var container = new MockingContainer<BankTransation>();

			container.Arrange<IAccount>(x => x.Withdraw(amount),
				Take.First())
					 .Returns(true)
					 .Occurs(1);

			container.Arrange<IAccount>(x => x.Deposit(amount),
				Take.At(1))
					 .Raises(() => container.Get<IAccount>(Take.At(1)).DepositMade += null, amount)
					 .Returns(true)
					 .Occurs(1);

			bool eventRaised = false;
			container.Get<IAccount>(Take.At(1)).DepositMade += d => eventRaised = true;

			container.Instance.TransferFunds(amount);

			Assert.True(eventRaised);
		}