Ejemplo n.º 1
0
        public void SubFixture_LocateTypeWithInterface_ReturnsInstance()
        {
            var fixture = new SubFixture();

            var instance = fixture.Locate <ImportSomeInterface>();

            Assert.NotNull(instance);
            Assert.Equal(0, instance.SomeValue);
        }
Ejemplo n.º 2
0
        public void SubFixture_SubstituteAndLocateTypeWithInterface_ReturnsInstance()
        {
            var fixture = new SubFixture();

            fixture.Locate <ISomeInterface>().SomeIntMethod().Returns(10);

            var instance = fixture.Locate <ImportSomeInterface>();

            Assert.NotNull(instance);
            Assert.Equal(10, instance.SomeValue);
        }
Ejemplo n.º 3
0
        public void SubFixture_SubstituteDefaultSingletonFalseAndSingleton_ReturnsSingleton()
        {
            var fixture = new SubFixture(defaultSingleton: false);

            fixture.Substitute <ISomeInterface>(s => s.SomeIntMethod().Returns(20), singleton: true);

            var instance = fixture.Substitute <ISomeInterface>(s => s.SomeIntMethod().Returns(10));

            Assert.NotNull(instance);

            Assert.Equal(10, instance.SomeIntMethod());

            Assert.Equal(20, fixture.Substitute <ISomeInterface>(singleton: true).SomeIntMethod());
        }
Ejemplo n.º 4
0
        public void SubFixture_SubstituteDefaultSingletonFalse_ReturnsCorrectImplementations()
        {
            var fixture = new SubFixture(defaultSingleton: false);

            var instance = fixture.Substitute <ISomeInterface>(s => s.SomeIntMethod().Returns(10));

            Assert.NotNull(instance);

            var instance2 = fixture.Substitute <ISomeInterface>(s => s.SomeIntMethod().Returns(15));

            Assert.NotNull(instance2);

            Assert.Equal(0, fixture.Locate <ISomeInterface>().SomeIntMethod());

            Assert.Equal(15, instance2.SomeIntMethod());

            Assert.Equal(10, instance.SomeIntMethod());

            Assert.Equal(0, fixture.Locate <ISomeInterface>().SomeIntMethod());
        }