private static Mock <T> AddMock <T>(ArrangeBuilder arrangeBuilder, Action <Mock <T> > mock) where T : class
        {
            var mockObject = new Mock <T>();

            mock.Invoke(mockObject);

            arrangeBuilder.AddDependency((c) => c.Register <T>((context) => mockObject.Object));

            return(mockObject);
        }
Пример #2
0
        private static void AddDependency <TInterface>(ArrangeBuilder arrangeBuilder, Type implementation)
            where TInterface : class
        {
            arrangeBuilder.AddDependency((containerBuilder) => containerBuilder.Register((context) =>
            {
                var constructors = implementation.GetConstructors();
                var parameters   = constructors.SelectMany(x => x.GetParameters()).Distinct();
                var args         = new List <object>();

                foreach (var parameter in parameters)
                {
                    args.Add(context.ResolveOptional(parameter.ParameterType) ?? MockHelper.CreateMock(parameter.ParameterType));
                }

                return(Activator.CreateInstance(implementation, args.ToArray()) as TInterface);
            }).As <TInterface>());
        }
Пример #3
0
 private static void AddDependency(ArrangeBuilder arrangeBuilder, Action <ContainerBuilder> dependency)
 {
     arrangeBuilder.AddDependency(dependency);
 }