Exemple #1
0
        private HttpSessionState GetSession()
        {
            Fail.IfFalse(this.IsAvailable(), Violation.Of("HttpContext.Current.Session is not available"));

            return(this.GetContext()
                   .Session);
        }
            internal Weak([NotNull] Type type)
            {
                Fail.IfArgumentNull(type, nameof(type));
                Fail.IfFalse(type.IsEnum, Violation.Of("Type '{0}' is not an enum", type));

                this.type = type;
            }
Exemple #3
0
        /// <inheritdoc />
        public IDatabase Get(Type databaseType)
        {
            Fail.IfArgumentNull(databaseType, nameof(databaseType));
            Fail.IfFalse(typeof(IDatabase).IsAssignableFrom(databaseType), "{0} is not " + nameof(IDatabase), databaseType);

            return this.databases.SingleOrDefault(db => databaseType.IsInstanceOfType(db));
        }
        public int GetMyEntitiesCount()
        {
            Fail.IfFalse(this.myDatabase.CurrentSession.Transaction.IsActive, "Transaction not started");

            return(this.myRepository.GetAll()
                   .Length);
        }
        public int StartTransactionBecauseThereIsAttributeOnInterface()
        {
            Fail.IfFalse(this.myDatabase.CurrentSession.Transaction.IsActive, "Transaction not started");

            return(this.myRepository.GetAll()
                   .Length);
        }
Exemple #6
0
        public void IfFalseSuccess()
        {
            // ARRANGE
            var someTrueValue = true;

            // ACT
            Fail.IfFalse(someTrueValue, Violation.Of("this should be true"));
        }
Exemple #7
0
        public void InvokeAnotherSession()
        {
            Fail.IfFalse(this.sampleDatabase.CurrentSession.Transaction.IsActive, "Transaction not started");

            var task = new Task(session =>
            {
                var currentSession = this.sampleDatabase.CurrentSession;
                Fail.IfEqual(session, currentSession, "session should differ");
            }, this.sampleDatabase.CurrentSession);

            task.Start();
            task.Wait();
        }
Exemple #8
0
        public void IfFalseWithMessage()
        {
            // ARRANGE
            bool someFalseValue = false;

            // ACT
            var exception = Assert.Throws <DesignByContractViolationException>(
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                () => Fail.IfFalse(someFalseValue, Violation.Of("this should be true {0}", 1))
                );

            // ASSERT
            Assert.That(exception.Message, Is.EqualTo("this should be true 1"));
        }
Exemple #9
0
        public void IfFalseWithNArguments()
        {
            // ARRANGE
            bool someFalseValue = false;

            // ACT
            var exception = Assert.Throws <DesignByContractViolationException>(
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                // ReSharper disable once HeapView.BoxingAllocation
                () => Fail.IfFalse(someFalseValue, "this should be true {0} {1} {2} {3}", 1, "wow", "yep", "bad")
                );

            // ASSERT
            Assert.That(exception.Message, Is.EqualTo("this should be true 1 wow yep bad"));
        }
        private static void CreateWord(Category category, bool inverted, string line)
        {
            var translations = line.Split('=');

            Fail.IfFalse(translations.Length == 2, "Something wrong with line '{0}'", line);

            string en = translations[0];
            string pl = translations[1];

            if (inverted)
            {
                pl = translations[0];
                en = translations[1];
            }

            var word = new Word(en, pl, category);

            category.Words.Add(word);
        }
        public void InvokeAnotherSession()
        {
            Fail.IfFalse(this.myDatabase.CurrentSession.Transaction.IsActive, "Transaction not started");

            var task = new Task(session =>
            {
                using (new SessionThreadStaticScope())
                {
                    using (this.myDatabase.OpenSession())
                    {
                        var currentSession = this.myDatabase.CurrentSession;
                        Fail.IfEqual(session, currentSession, "session should differ");
                    }
                }
            },
                                this.myDatabase.CurrentSession);

            task.Start();
            task.Wait();
        }
Exemple #12
0
 private void FailIfThreadStaticContextScopeNotAvailable()
 {
     Fail.IfFalse(this.IsAvailable(), nameof(ThreadStaticContextScope <T>) + " is not available");
 }
Exemple #13
0
        public void CreateDatabaseSchema()
        {
            Fail.IfFalse(this.sampleDatabase.CurrentSession.Transaction.IsActive, "Transaction not started");

            this.dataBaseSchema.CreateFor(this.sampleDatabase);
        }
        private HttpResponse GetResponse()
        {
            Fail.IfFalse(this.IsAvailable(), "HttpContext.Current.Response is not available.");

            return(HttpContext.Current.Response);
        }
Exemple #15
0
        private HttpRequest GetRequest()
        {
            Fail.IfFalse(this.IsAvailable(), Violation.Of("HttpContext.Current.Request is not available."));

            return(HttpContext.Current.Request);
        }