Exemplo n.º 1
0
        public void AddFunctionMethod_Adds_Valid_Service_Correctly()
        {
            // Arrange
            ServiceBuilder.AddFunction <string, string>(
                arg => "",
                (provider, key, arg) => Task.FromResult(""));
            var services = new ServiceCollection();

            // Act
            ServiceBuilder.GetBuild()(services);

            // Assert
            Assert.Equal(8, services.Count);                                         // Includes MemoryCache and all options instances.
            Assert.Equal(typeof(ICache <IMemory>), services[6].ServiceType);         // ICache service added before ICached
            Assert.Equal(typeof(ICached <string, string>), services[7].ServiceType); // ICached service added last.
        }
Exemplo n.º 2
0
        public void AddFunctionMethod_Does_Not_Clear_PreExisting_Services()
        {
            // Arrange
            ServiceBuilder.AddFunction <string, string>(
                arg => "",
                (provider, key, arg) => Task.FromResult(""));
            var services = new ServiceCollection();

            services.AddSingleton <object, object>(provider => "123");

            // Act
            ServiceBuilder.GetBuild()(services);

            // Assert
            Assert.Equal("123", (string)services.BuildServiceProvider().GetService <object>());
        }