Exemple #1
0
        /// <summary>
        /// Creates a pooled object from the specified pool.
        /// </summary>
        public Pooled([NotNull] Pool <TPooled> pool)
        {
            Fail.IfArgumentNull(pool, nameof(pool));

            this.pool  = pool;
            this.Value = pool.Constructor()
                         .OrFail(nameof(pool.Constructor));
        }
        /// <inheritdoc />
        public string MapPath(string path)
        {
            Fail.IfArgumentNull(path, nameof(path));

            return(this.GetContext()
                   .Server
                   .MapPath(path));
        }
        /// <inheritdoc />
        public void Store(T value)
        {
            Fail.IfArgumentNull(value, nameof(value));

            string key = this.GetKey();

            this.httpContextItems.Set(key, value);
        }
        public static void ConfigureContextStorages([NotNull] Action <ContextStorageConfigurator> configure)
        {
            Fail.IfArgumentNull(configure, nameof(configure));
            var configurator = new ContextStorageConfigurator();

            configure(configurator);
            preferredContextStorages = configurator.GetStorageTypes();
        }
            public SingleTransacion([NotNull] IDatabase database, [NotNull] ISession session)
            {
                Fail.IfArgumentNull(database, nameof(database));
                Fail.IfArgumentNull(session, nameof(session));

                this.Database = database;
                this.Session  = session;
            }
Exemple #6
0
        /// <inheritdoc />
        public bool HasComponent(Type type)
        {
            Fail.IfArgumentNull(type, nameof(type));

            return(this.windsorContainer
                   .Kernel
                   .HasComponent(type));
        }
Exemple #7
0
        public static void ApproveForScenario(this Xml xml, string scenario)
        {
            Fail.IfArgumentNull(scenario, nameof(scenario));

            using (ApprovalResults.ForScenario(scenario))
            {
                xml.Approve();
            }
        }
        /// <summary>
        /// Adds a node with nodeKey
        /// Does not complain if the node is already present
        /// </summary>
        /// <param name="nodeKey"></param>
        public void Node([NotNull] T nodeKey)
        {
            Fail.IfArgumentNull(nodeKey, nameof(nodeKey));

            if (!this.nodes.ContainsKey(nodeKey))
            {
                this.nodes.Add(nodeKey, new NodeInfo());
            }
        }
Exemple #9
0
        /// <summary>
        /// Returns the object to the pool.
        /// </summary>
        public void Free([NotNull] Pooled <TPooled> pooled)
        {
            Fail.IfArgumentNull(pooled, nameof(pooled));

            lock (this.syncRoot)
            {
                this.items.Push(pooled);
            }
        }
Exemple #10
0
        public void StoreSession([NotNull] IDatabase database, [NotNull] ISession session)
        {
            Fail.IfArgumentNull(database, nameof(database));
            Fail.IfArgumentNull(session, nameof(session));

            string key = database.GetKey();

            this.sessions.Add(key, new Couple(database, session));
        }
        /// <inheritdoc />
        public void RegisterComponentsFrom(WindsorContainer windsorContainer, Library library)
        {
            Fail.IfArgumentNull(windsorContainer, nameof(windsorContainer));
            Fail.IfArgumentNull(library, nameof(library));

            var controllerInstaller = new MvcControllerInstaller(library);

            windsorContainer.Install(controllerInstaller);
        }
        /// <inheritdoc />
        public IStatelessSession GetStatelessSession(IDatabase database)
        {
            Fail.IfArgumentNull(database, nameof(database));

            SessionsContainer container = this.GetSessionsContainer();
            var session = container.GetStatelessSession(database);

            return(session);
        }
            public string GetEnumDisplayName([NotNull] Enum @enum)
            {
                Fail.IfArgumentNull(@enum, nameof(@enum));

                var field            = this.GetFieldInfo(@enum);
                var displayAttribute = field.GetCustomAttribute <DisplayAttribute>();

                return(displayAttribute?.Name);
            }
        /// <inheritdoc />
        public void StoreSession(IDatabase database, ISession session)
        {
            Fail.IfArgumentNull(database, nameof(database));
            Fail.IfArgumentNull(session, nameof(session));

            SessionsContainer container = this.GetSessionsContainer();

            container.StoreSession(database, session);
        }
Exemple #15
0
        public void IfArgumentNull([CanBeNull] object argumentValue)
        {
            // ACT
            var exception = Assert.Throws <DesignByContractViolationException>(
                () => Fail.IfArgumentNull(argumentValue, nameof(argumentValue))
                );

            // ASSERT
            Assert.That(exception.Message, Is.EqualTo("Argument 'argumentValue' is null."));
        }
        /// <inheritdoc />
        public void Intercept([NotNull] IInvocation invocation)
        {
            Fail.IfArgumentNull(invocation, nameof(invocation));

            using (var transactions = this.StartTransactions(invocation))
            {
                invocation.Proceed();
                transactions.Commit();
            }
        }
            public string GetEnumName([NotNull] Enum @enum)
            {
                Fail.IfArgumentNull(@enum, nameof(@enum));

                var field = this.GetFieldInfo(@enum);
                var enumMemberAttribute = field.GetCustomAttribute <EnumMemberAttribute>();
                var name = enumMemberAttribute?.Value ?? @enum.ToString();

                return(name);
            }
Exemple #18
0
        public ISession GetSession([NotNull] IDatabase database)
        {
            Fail.IfArgumentNull(database, nameof(database));

            string key = database.GetKey();
            Couple couple;

            this.sessions.TryGetValue(key, out couple);
            return(couple?.Session);
        }
            public string GetPropertyDisplayName <TProperty>([NotNull] Expression <Func <TClass, TProperty> > propertyExpression)
            {
                Fail.IfArgumentNull(propertyExpression, nameof(propertyExpression));

                PropertyInfo propertyInfo        = this.GetPropertyInfo(propertyExpression);
                var          displayAttribute    = propertyInfo.GetCustomAttribute <DisplayAttribute>();
                string       propertyDisplayName = displayAttribute?.GetName();

                return(propertyDisplayName);
            }
Exemple #20
0
            public override bool ShouldMap([NotNull] Type type)
            {
                Fail.IfArgumentNull(type, nameof(type));

                if (this.entities.Contains(type))
                {
                    return(true);
                }

                return(false);
            }
            public void Override([NotNull] AutoMapping <WordGroup> mapping)
            {
                Fail.IfArgumentNull(mapping, nameof(mapping));

                mapping.Schema(SampleDatabase.SchemaName);

                mapping.Map(u => u.Name)
                .Length(Map.NameLength);

                mapping.HasManyBidirectional(g => g.Words, w => w.Group);
            }
            public FieldInfo GetFieldInfo([NotNull] Enum @enum)
            {
                Fail.IfArgumentNull(@enum, nameof(@enum));

                string name = Enum.GetName(this.type, @enum);

                Fail.IfNull(name, Violation.Of("Enum value {0} not found in enum {1}", @enum, this.type));
                FieldInfo field = this.type.GetField(name);

                return(field.OrFail(nameof(field)));
            }
        public static string Left([NotNull] this string text, int length)
        {
            Fail.IfArgumentNull(text, nameof(text));

            if (text.Length <= length)
            {
                return(text);
            }

            return(text.Substring(0, length));
        }
Exemple #24
0
        public void Apply([NotNull] IManyToManyCollectionInstance instance)
        {
            Fail.IfArgumentNull(instance, "instance");

            instance.Cascade.SaveUpdate();

            string fk = "Fk_" + instance.EntityType.Name + "_" + instance.Member.Name;

            instance.Key.ForeignKey(fk + "_1");
            instance.Relationship.ForeignKey(fk + "_2");
        }
        public void StoreSession([NotNull] IDatabase database, [NotNull] IStatelessSession session)
        {
            Fail.IfArgumentNull(database, nameof(database));
            Fail.IfArgumentNull(session, nameof(session));

            this.CleanUpClosedStatelesSessions();

            string key = database.GetKey();

            this.statelesSessions.Add(key, session);
        }
        public IStatelessSession GetStatelessSession([NotNull] IDatabase database)
        {
            Fail.IfArgumentNull(database, nameof(database));

            this.CleanUpClosedStatelesSessions();

            string            key = database.GetKey();
            IStatelessSession session;

            this.statelesSessions.TryGetValue(key, out session);
            return(session);
        }
            /// <inheritdoc />
            public void Override([NotNull] AutoMapping <Word> mapping)
            {
                Fail.IfArgumentNull(mapping, nameof(mapping));

                mapping.Schema(SampleDatabase.SchemaName);

                mapping.Map(w => w.Polish)
                .Length(Map.PolishLength);

                mapping.Map(w => w.English)
                .Length(Map.EnglishLength);
            }
Exemple #28
0
        public static string GetIndexName <TEntity>([NotNull] Expression <Func <TEntity, object> > property)
        {
            Fail.IfArgumentNull(property, nameof(property));

            ClassSpecifics.Concrete <TEntity> entityType = ClassSpecifics.Of <TEntity>();
            string entityName   = entityType.GetClassName();
            var    propertyName = entityType.GetPropertyName(property);

            var indexName = $"IX_{entityName}_{propertyName}";

            return(indexName);
        }
Exemple #29
0
        public ActionResult CategoryCreate([NotNull] NewCategoryModel model)
        {
            Fail.IfArgumentNull(model, nameof(model));
            Fail.IfArgumentEmpty(model.BookId, nameof(model.BookId));
            Fail.IfArgumentWhiteSpace(model.Name, nameof(model.Name));

            var book     = BookStore.GetBookById(model.BookId);
            var category = book.CreateCategory(model.Name);

            book.Save();

            return(RedirectToCategoryEditor(category));
        }
Exemple #30
0
        public ActionResult CategoryUpdate([NotNull] EditCategoryModel model)
        {
            Fail.IfArgumentNull(model, nameof(model));
            Fail.IfArgumentEmpty(model.Id, nameof(model.Id));
            Fail.IfArgumentWhiteSpace(model.Name, nameof(model.Name));

            var category = BookStore.GetCategory(model.Id);

            category.Rename(model.Name);
            category.Book.Save();

            return(RedirectToCategoryEditor(category));
        }