Exemplo n.º 1
0
        public void ShouldResolveConventionsUsingTheServiceProvider()
        {
            var properties = new ServiceProviderDictionary();

            AutoFake.Provide <IServiceProvider>(properties);
            var scanner = AutoFake.Resolve <Scanner>();

            properties.Add(typeof(IConventionScanner), scanner);
            var fakeService = A.Fake <IService>();

            properties.Add(typeof(IService), fakeService);

            scanner.AppendConvention <F>();

            var result = scanner.BuildProvider().Get <IServiceConvention, ServiceConventionDelegate>();

            var item = result.First().Convention;

            item.Should().BeOfType <F>();
            ((F)item !).Scanner.Should().NotBeNull();
            ((F)item !).Scanner.Should().BeSameAs(scanner);
            ((F)item !).Service.Should().BeSameAs(fakeService);
        }
Exemplo n.º 2
0
        public void ShouldResolveConventionsUsingTheServiceProvider_And_Fail_IfTypeIsNotProvided()
        {
            var properties = new ServiceProviderDictionary();

            AutoFake.Provide <IServiceProvider>(properties);
            var scanner = AutoFake.Resolve <Scanner>();

            properties.Add(typeof(IConventionScanner), scanner);

            scanner.AppendConvention <F>();

            Action a = () => scanner.BuildProvider().Get <IServiceConvention, ServiceConventionDelegate>();

            a.Should().Throw <InvalidOperationException>();
        }