Inheritance: PredicateFields
        /// <summary>
        /// This test shows how to setup the imposter in the contains predicate example
        /// at http://www.mbtest.org/docs/api/predicates.
        /// </summary>
        //[TestMethod]
        public void ContainsPredicateExample()
        {
            var imposter = _client.CreateTcpImposter(4547, "ContainsPredicateExample", TcpMode.Binary);

            // First stub
            var predicateFields = new TcpPredicateFields
            {
                Data = "AgM="
            };

            imposter.AddStub().On(new ContainsPredicate<TcpPredicateFields>(predicateFields))
                .ReturnsData("Zmlyc3QgcmVzcG9uc2U=");

            // Second stub
            predicateFields = new TcpPredicateFields
            {
                Data = "Bwg="
            };

            imposter.AddStub().On(new ContainsPredicate<TcpPredicateFields>(predicateFields))
                .ReturnsData("c2Vjb25kIHJlc3BvbnNl");

            // Third stub
            predicateFields = new TcpPredicateFields
            {
                Data = "Bwg="
            };

            imposter.AddStub().On(new ContainsPredicate<TcpPredicateFields>(predicateFields))
                .ReturnsData("dGhpcmQgcmVzcG9uc2U=");

            _client.Submit(imposter);
        }
Exemple #2
0
        /// <summary>
        /// Adds a predicate to the stub that will match when the request data equals the specified data.
        /// </summary>
        /// <param name="path">The data to match on</param>
        /// <returns>The stub that the predicate was added to</returns>
        public TcpStub OnDataEquals(string data)
        {
            var fields = new TcpPredicateFields
            {
                Data = data
            };

            var predicate = new EqualsPredicate<TcpPredicateFields>(fields);

            return On(predicate);
        }
Exemple #3
0
        public void On_AddsPredicate_SetsFields()
        {
            var expectedFields = new TcpPredicateFields
            {
                Data = "TestData",
                RequestFrom = "socket"
            };

            var stub = new TcpStub();
            stub.On(new EqualsPredicate<TcpPredicateFields>(expectedFields));

            var predicate = stub.Predicates.First() as EqualsPredicate<TcpPredicateFields>;
            Assert.IsNotNull(predicate);
            Assert.AreEqual(expectedFields, predicate.Fields);
        }
        /// <summary>
        /// This test shows how to setup the imposter in the startsWith predicate example
        /// at http://www.mbtest.org/docs/api/predicates.
        /// </summary>
        //[TestMethod]
        public void StartsWithPredicateExample()
        {
            var imposter = _client.CreateTcpImposter(4548, "StartsWithPredicateExample", TcpMode.Text);

            // First stub
            var predicateFields = new TcpPredicateFields
            {
                Data = "first"
            };

            imposter.AddStub().On(new StartsWithPredicate<TcpPredicateFields>(predicateFields))
                .ReturnsData("first response");

            // Second stub
            predicateFields = new TcpPredicateFields
            {
                Data = "second"
            };

            imposter.AddStub().On(new StartsWithPredicate<TcpPredicateFields>(predicateFields))
                .ReturnsData("second response");

            // Third stub
            predicateFields = new TcpPredicateFields
            {
                Data = "second"
            };

            imposter.AddStub().On(new StartsWithPredicate<TcpPredicateFields>(predicateFields))
                .ReturnsData("third response");

            _client.Submit(imposter);
        }
        /// <summary>
        /// This test shows how to setup the imposter in the matches predicate example
        /// at http://www.mbtest.org/docs/api/predicates.
        /// </summary>
        //[TestMethod]
        public void MatchesPredicateExample()
        {
            var imposter = _client.CreateTcpImposter(4550, "MatchesPredicateExample", TcpMode.Text);

            // First stub
            var predicateFields = new TcpPredicateFields
            {
                Data = "^first\\Wsecond"
            };

            imposter.AddStub().On(new MatchesPredicate<TcpPredicateFields>(predicateFields, true, null, null))
                .ReturnsData("first response");

            // Second stub
            predicateFields = new TcpPredicateFields
            {
                Data = "second\\s+request"
            };

            imposter.AddStub().On(new MatchesPredicate<TcpPredicateFields>(predicateFields))
                .ReturnsData("second response");

            // Third stub
            predicateFields = new TcpPredicateFields
            {
                Data = "second\\s+request"
            };

            imposter.AddStub().On(new MatchesPredicate<TcpPredicateFields>(predicateFields))
                .ReturnsData("third response");

            _client.Submit(imposter);
        }