Exemplo n.º 1
0
        protected void AndGivenASetOfSpecificationsForAddresses()
        {
            _specProviderFroAddress = new SpecProvider <Address>();

            _specProviderFroAddress.Add(a =>
            {
                if (a.ContactId == 0)
                {
                    return(new SpecResult("Contact Id has not been assigned."));
                }

                return(SpecResult.Success);
            }, "Key", "Description");
        }
Exemplo n.º 2
0
        protected void AndGivenASetOfSpecificationsForSource()
        {
            _specProvider = new SpecProvider <Dto1>();

            _specProvider.Add(a =>
            {
                if (a.Source.Key == "Key-5")
                {
                    return(new SpecResult("Arbitrary invalid reason."));
                }

                return(SpecResult.Success);
            }, "Key", "Description");

            _specProvider.MergeFrom(m => m.Contact, new SpecProvider <Contact>());
        }
Exemplo n.º 3
0
        protected void GivenASpecProviderWithCustomRules()
        {
            var specProvider = new SpecProvider <TestClass>();

            specProvider.Add(s =>
            {
                // ReSharper disable once ConvertIfStatementToReturnStatement
                if (s.Name == "John")
                {
                    return(new SpecResult("Name can't be John"));
                }

                return(SpecResult.Success);
            }, "NameNotJohn", "Name can't be john for some reason defined by the business");

            _rules = specProvider.GetSpecifications().ToArray();
        }
Exemplo n.º 4
0
        protected void AndGivenAWiredUpContainer()
        {
            _cb = new ContainerBuilder();

            _cb.RegisterGeneric(typeof(SpecProvider <>))
            .As(typeof(IProvideSpecifications <>))
            .As(typeof(SpecProvider <>))
            .SingleInstance();

            _cb.RegisterGeneric(typeof(Processor <,>))
            .As(typeof(Processor <,>));

            _cb.RegisterGeneric(typeof(ProcessorEngine <>))
            .As(typeof(ProcessorEngine <>));

            _cb.RegisterGeneric(typeof(ProcessorConfiguration <,>))
            .As(typeof(ProcessorConfiguration <,>));

            //specialist
            _cb.Register(m =>
            {
                var s = new SpecProvider <Dto1>();

                s.Add(a =>
                {
                    if (a.Source.Key == "Key-5")
                    {
                        return(new SpecResult("Arbitrary invalid reason."));
                    }

                    return(SpecResult.Success);
                }, "Key", "Description");

                s.MergeFrom(mq => mq.Contact, m.Resolve <SpecProvider <Contact> >());
                return(s);
            }).AsSelf().AsImplementedInterfaces();

            _cb.Register(m =>
            {
                var s = new SpecProvider <Address>();

                s.Add(a =>
                {
                    if (a.ContactId == 0)
                    {
                        return(new SpecResult("Contact Id has not been assigned."));
                    }

                    return(SpecResult.Success);
                }, "Key", "Description");
                return(s);
            }).AsSelf().AsImplementedInterfaces();

            _cb.Register(m =>
            {
                var s = new FlowSnapshotRepo <FlowSnapshot>(Environment.CurrentDirectory);
                return(s);
            }).AsSelf().AsImplementedInterfaces();

            _container = _cb.Build();
        }