Beispiel #1
0
        public void TestAutoMapperDi()
        {
            var mapper = DiServiceBuilder.GetService <IMapper>();
            var result = mapper.Map <string>("Жопа");

            Assert.IsFalse(string.IsNullOrEmpty(result));
        }
Beispiel #2
0
        public void TestServiceBuilder()
        {
            var testService = DiServiceBuilder.GetService <TestService>();
            var result      = testService.Invoke();

            Assert.IsTrue(result == "This is string");
        }
        public void Setup()
        {
            // Of course we should test these first but I'm too lazy.
            IConfigurationSource   source   = new DiConfigurationSource(@"Server=MYLLY; User Id=ConfigReader; Password=ConfigReader;", "TEST");
            IConfigurationProvider provider = source.Build(null);

            provider.Load();

            // Mock these objects.
            var collection = new Mock <ServiceCollectionWrapper>();

            // XXX : This is a mess. Unmess this sometime.
            // We load configuration provided by our DiConfigurationProvider (using DiConfigurationSource as source)
            // and return configurations to caller.
            var diConfiguration = new Mock <IConfigurationSection>();

            diConfiguration.Setup(f => f.GetChildren())
            .Returns(() =>
            {
                return(provider.GetChildKeys(Enumerable.Empty <string>(), "DiConfiguration").Distinct().Select(parentKey =>
                {
                    var mock = new Mock <IConfigurationSection>();
                    mock.Setup(f => f.Key).Returns(parentKey);
                    mock.Setup(f => f.GetChildren())
                    .Returns(() => provider.GetChildKeys(Enumerable.Empty <string>(), "DiConfiguration:" + parentKey).Distinct().Select(childKey =>
                    {
                        var mock = new Mock <IConfigurationSection>();
                        mock.Setup(f => f.GetSection(It.IsNotNull <string>())).Returns((string section) =>
                        {
                            var mock = new Mock <IConfigurationSection>();
                            mock.Setup(f => f.Value).Returns(() => provider.TryGet($"DiConfiguration:{parentKey}:{childKey}:{section}", out string value) ? value : "");
                            return mock.Object;
                        });
                        return mock.Object;
                    }));
                    return mock.Object;
                }));
            });

            // Main/head configuration. Returns only DI configuration mockup.
            var configuration = new Mock <IConfiguration>();

            configuration.Setup(f => f.GetSection(It.IsAny <string>()))
            .Returns(diConfiguration.Object);

            // Builds DI services and fetches the one and only service we actually need to run the tests.
            // DiServiceBuilder should be tested also before calling it.
            DiServiceBuilder.AddDiServices(collection.Object, configuration.Object);
            carSalesman = collection.Object.GetService(typeof(ICarSalesman)) as ICarSalesman;
        }
Beispiel #4
0
 public AddressService_Test()
 {
     _addressService = DiServiceBuilder.GetService <AddressService>();;
     _context        = DiServiceBuilder.GetService <OdContext>();;
 }
Beispiel #5
0
 public FilterTest()
 {
     _context = DiServiceBuilder.GetService <OdContext>();
 }
 public DaDataService_Test()
 {
     _daDataService = DiServiceBuilder.GetService <DaDataService>();
 }