Esempio n. 1
0
        public void ExecuteTest(string name, string expected)
        {
            //Arrange

            //Act
            string result = greeting.Greet(name);

            //Assert
            Assert.AreEqual(expected, result);
        }
        public void Greeting_with_single_name_should_greet_with_name()
        {
            var name          = "bob";
            var expectedGreet = $"Hello, {name}.";

            var actualGreet = _greeting.Greet(name);

            actualGreet.Should().Be(actualGreet);
        }
        public void SimpleGreetingWithNoName()
        {
            var output         = Greeting.Greet();
            var expectedResult = "Hello, my friend";

            Assert.AreEqual(expectedResult, output);
        }
        [Test] //
        public void GreetingWithMultipleNamesSplitEscapeIntentionalComma()
        {
            string[] multipleNames  = { "Bob", "\"Charlie, Dianne\"" };
            var      output         = Greeting.Greet(multipleNames);
            var      expectedResult = "Hello, Bob and Charlie, Dianne.";

            Assert.AreEqual(expectedResult, output);
        }
        public void GreetingWithMultipleNamesSplit()
        {
            string[] multipleNames  = { "Bob", "Charlie, Dianne" };
            var      output         = Greeting.Greet(multipleNames);
            var      expectedResult = "Hello, Bob, Charlie, and Dianne.";

            Assert.AreEqual(expectedResult, output);
        }
        public void GreetingWithMultipleMixedNames()
        {
            string[] multipleNames  = { "Amy", "BRIAN", "Charlotte" };
            var      output         = Greeting.Greet(multipleNames);
            var      expectedResult = "Hello, Amy and Charlotte. AND HELLO BRIAN!";

            Assert.AreEqual(expectedResult, output);
        }
        public void GreetingWithMultipleNames()
        {
            string[] multipleNames  = { "Amy", "Brian", "Charlotte" };
            var      output         = Greeting.Greet(multipleNames);
            var      expectedResult = "Hello, Amy, Brian, and Charlotte.";

            Assert.AreEqual(expectedResult, output);
        }
        public void GreetingWithTwoNames()
        {
            string[] twoNames       = { "Jill", "Jane" };
            var      output         = Greeting.Greet(twoNames);
            var      expectedResult = "Hello, Jill and Jane.";

            Assert.AreEqual(expectedResult, output);
        }
        public void ShoutingWhenAllCaps()
        {
            var shoutingName   = "JERRY";
            var output         = Greeting.Greet(shoutingName);
            var expectedResult = "HELLO JERRY!";

            Assert.AreEqual(expectedResult, output);
        }
        public void SimpleGreetingWithOneName()
        {
            var name           = "Bob";
            var output         = Greeting.Greet(name);
            var expectedResult = "Hello, Bob";

            Assert.AreEqual(expectedResult, output);
        }
Esempio n. 11
0
        public void ExecuteTest(string[] name, string expected)
        {
            //Arrange

            //Act
            string result = greeting.Greet(name);

            //Assert
            Console.WriteLine(result);
            Assert.AreEqual(expected, result);
        }
Esempio n. 12
0
        public override async Task <AddGreeting> HandleAsync(AddGreeting addGreeting, CancellationToken cancellationToken = default(CancellationToken))
        {
            var posts = new List <Guid>();

            //We span a Db outside of EF's control, so start an explicit transactional scope
            var tx = await _uow.Database.BeginTransactionAsync(cancellationToken);

            try
            {
                var person = await _uow.People
                             .Where(p => p.Name == addGreeting.Name)
                             .SingleAsync(cancellationToken);

                var greeting = new Greeting(addGreeting.Greeting);

                person.AddGreeting(greeting);

                //Now write the message we want to send to the Db in the same transaction.
                posts.Add(await _postBox.DepositPostAsync(new GreetingMade(greeting.Greet()), cancellationToken: cancellationToken));

                //write the changed entity to the Db
                await _uow.SaveChangesAsync(cancellationToken);

                //write new person and the associated message to the Db
                await tx.CommitAsync(cancellationToken);
            }
            catch (Exception)
            {
                //it went wrong, rollback the entity change and the downstream message
                await tx.RollbackAsync(cancellationToken);

                return(await base.HandleAsync(addGreeting, cancellationToken));
            }

            //Send this message via a transport. We need the ids to send just the messages here, not all outstanding ones.
            //Alternatively, you can let the Sweeper do this, but at the cost of increased latency
            await _postBox.ClearOutboxAsync(posts, cancellationToken : cancellationToken);

            return(await base.HandleAsync(addGreeting, cancellationToken));
        }
Esempio n. 13
0
        public override async Task<AddGreeting> HandleAsync(AddGreeting addGreeting, CancellationToken cancellationToken = default(CancellationToken))
        {
            var posts = new List<Guid>();
            
            //We use the unit of work to grab connection and transaction, because Outbox needs
            //to share them 'behind the scenes'
            
            var tx = await _uow.BeginOrGetTransactionAsync(cancellationToken);
            try
            {
                var searchbyName = Predicates.Field<Person>(p => p.Name, Operator.Eq, addGreeting.Name);
                var people = await _uow.Database.GetListAsync<Person>(searchbyName, transaction: tx);
                var person = people.Single();
                
                var greeting = new Greeting(addGreeting.Greeting, person);
                
                //Now write the message we want to send to the Db in the same transaction.
                posts.Add(await _postBox.DepositPostAsync(new GreetingMade(greeting.Greet()), cancellationToken: cancellationToken));
                
                //write the added child entity to the Db
                await _uow.Database.InsertAsync<Greeting>(greeting, tx);

                //commit both new greeting and outgoing message
                await tx.CommitAsync(cancellationToken);
            }
            catch (Exception e)
            {   
                _logger.LogError(e, "Exception thrown handling Add Greeting request");
                //it went wrong, rollback the entity change and the downstream message
                await tx.RollbackAsync(cancellationToken);
                return await base.HandleAsync(addGreeting, cancellationToken);
            }

            //Send this message via a transport. We need the ids to send just the messages here, not all outstanding ones.
            //Alternatively, you can let the Sweeper do this, but at the cost of increased latency
            await _postBox.ClearOutboxAsync(posts, cancellationToken:cancellationToken);

            return await base.HandleAsync(addGreeting, cancellationToken);
        }
Esempio n. 14
0
        public void Greeting_ShouldGreetWithGivenName()
        {
            var sut = greeting.Greet("Bob");

            Assert.AreEqual(sut, "Hello, Bob.");
        }
Esempio n. 15
0
        public void Requirement_1(string parameter, string expected)
        {
            var result = _sut.Greet(parameter);

            Assert.Equal(expected, result);
        }