コード例 #1
0
ファイル: FakeItEasyTests.cs プロジェクト: jrjohn/Grace
        public void ConfigureArrangeTest()
        {
            FakeContainer container = new FakeContainer();

            container.Configure(c => c.Fake<IBasicService>().
                Arrange(x => A.CallTo(() => x.TestMethod()).Returns(5)).
                AndSingleton());

            ImportConstructorService importConstructorService =
                container.Locate<ImportConstructorService>();

            Assert.Equal(5, importConstructorService.TestMethod());

            A.CallTo(() => container.Locate<IBasicService>(null, null, null).TestMethod()).MustHaveHappened(Repeated.Exactly.Once);
        }
コード例 #2
0
ファイル: FakeItEasyTests.cs プロジェクト: jrjohn/Grace
        public void ConfigureAssertTest()
        {
            FakeContainer container = new FakeContainer();

            container.Configure(c => c.Fake<IBasicService>().
                Arrange(x => A.CallTo(() => x.TestMethod()).Returns(5)).
                Assert(x => A.CallTo(() => x.TestMethod()).MustHaveHappened(Repeated.Exactly.Twice)));

            ImportConstructorService importConstructorService =
                container.Locate<ImportConstructorService>();

            Assert.Equal(5, importConstructorService.TestMethod());

            try
            {
                container.Assert();

                throw new Exception("This should have thrown an exception from the assert");
            }
            catch (ExpectationException)
            {
                // we are expecting this
            }
        }