Exemplo n.º 1
0
        public async Task Pipeline()
        {
            var shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal())
                        .Add(new TestGetStation1())
                        .Add(new TestGetStation2());

            var basket = new GetBasket <int, Frog>(22);
            await shaft.SendAsync(basket).ConfigureAwait(false);

            Assert.Equal(22, basket.AscentPayload.Id);
            Assert.Equal("Frank21", basket.AscentPayload.Name);
            Assert.Equal(DateTime.Today, basket.AscentPayload.DateOfBirth);
            Assert.Equal(22, basket.DescentPayload);

            shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal())
                    .Add(new TestGetStation2())
                    .Add(new TestGetStation1());

            basket = new GetBasket <int, Frog>(33);
            await shaft.SendAsync(basket).ConfigureAwait(false);

            Assert.Equal(33, basket.AscentPayload.Id);
            Assert.Equal("Frank12", basket.AscentPayload.Name);
            Assert.Equal(DateTime.Today, basket.AscentPayload.DateOfBirth);
            Assert.Equal(33, basket.DescentPayload);
        }
Exemplo n.º 2
0
        public async Task Simple()
        {
            var shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal(), null);

            var basket = new GetBasket <int, Frog>(18);
            await shaft.SendAsync(basket).ConfigureAwait(false);

            Assert.Equal(typeof(OkNote), basket.Note.GetType());
            Assert.Equal(18, basket.AscentPayload.Id);
            Assert.Equal("Frank", basket.AscentPayload.Name);
            Assert.Equal(DateTime.Today, basket.AscentPayload.DateOfBirth);

            Assert.Equal(18, basket.DescentPayload);
        }
Exemplo n.º 3
0
        public async Task ReturnEarly()
        {
            var shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal())
                        .Add(new TestGetStation1())
                        .Add(new TestGetStation2())
                        .Add(new TestGetStationReturnEarly());

            var basket = new GetBasket <int, Frog>(22);
            await shaft.SendAsync(basket).ConfigureAwait(false);

            Assert.True(basket.Note is ReturnNote);

            Assert.Equal(22, basket.AscentPayload.Id);
            Assert.Equal("Early Frog", basket.AscentPayload.Name);
            Assert.Equal(DateTime.Today.AddDays(-1), basket.AscentPayload.DateOfBirth);
        }
Exemplo n.º 4
0
        public Task <IPostBasket <Types.MatingEvent, string> > SendAsync(IPostBasket <Types.MatingEvent, string> basket)
        {
            var shaft = new Shaft <IPostBasket <Types.MatingEvent, string> >(TraceExporter, TerminalLayer,
                                                                             GetStations <IPostBasket <Types.MatingEvent, string> >());

            // Here, based on some "configuration" were injecting functionality into the shaft.
            // The station that is added will be the lowest station in the shaft (but above the terminal),
            // i.e. it will be below the stations from the security layer which was added in the base AppMine
            // class
            if (Language == Languages.Spanish)
            {
                shaft.Add(new SpanishTranslationStation());
            }
            else if (Language == Languages.French)
            {
                shaft.Add(new FrenchTranslationStation());
            }

            return(shaft.SendAsync(basket));
        }
Exemplo n.º 5
0
        public async Task ExceptionUp()
        {
            var shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal())
                        .Add(new TestGetStation1())
                        .Add(new TestGetStation2())
                        .Add(new TestGetStationExceptionUp());

            var wasException = false;

            try
            {
                var basket = new GetBasket <int, Frog>(22);
                await shaft.SendAsync(basket).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                wasException = true;
                Assert.Equal("Ex on ascent", ex.InnerException.Message);
            }

            Assert.True(wasException);
        }
Exemplo n.º 6
0
        public async Task Trace()
        {
            var shaft = new Shaft <IGetBasket <int, Frog> >(new TestGetTerminal())
                        .Add(new TestGetStation1())
                        .Add(new TestGetStation2());

            var basket = new GetBasket <int, Frog>(22);
            await shaft.SendAsync(basket).ConfigureAwait(false);

            Assert.Equal(5, basket.Visits.Count);

            var visits = basket.Visits.ToArray();

            var visit = visits[0];

            Assert.True(visit.Description == typeof(TestGetStation1).ToString() && visit.Direction == VisitDirections.Down &&
                        visit.Duration > TimeSpan.Zero);

            visit = visits[1];
            Assert.True(visit.Description == typeof(TestGetStation2).ToString() && visit.Direction == VisitDirections.Down &&
                        visit.Duration > TimeSpan.Zero);

            visit = visits[2];
            Assert.True(visit.Description == typeof(TestGetTerminal).ToString() && visit.Direction == VisitDirections.Down &&
                        visit.Duration > TimeSpan.Zero);

            visit = visits[3];
            Assert.True(visit.Description == typeof(TestGetStation2).ToString() && visit.Direction == VisitDirections.Up &&
                        visit.Duration > TimeSpan.Zero);

            visit = visits[4];
            Assert.True(visit.Description == typeof(TestGetStation1).ToString() && visit.Direction == VisitDirections.Up &&
                        visit.Duration > TimeSpan.Zero);

            var waypointTimes = visits.Sum(v => v.Duration?.TotalMilliseconds);

            Assert.True(basket.JourneyDuration.TotalMilliseconds >= waypointTimes);
        }