public void ArrivalAsyncTest()
        {
            var portQuery = Mock.Of <ISingleQueryPortByIntCode>();

            Mock.Get(portQuery).Setup(s => s.UseIntCode("port code")).Returns(portQuery).Verifiable();
            Mock.Get(portQuery).Setup(s => s.ExecuteAsync())
            .Returns(Task.FromResult(new Port()
            {
                Id       = "port id",
                IntlCode = "port code",
                Name     = "port name"
            }));

            var ship    = new Ship();
            var shipRef = new TestEntityRef <Ship>("ship id", ship);

            var shipQuery = Mock.Of <ISingleQueryShipByRegCode>(MockBehavior.Strict);

            ship.RegisterShip(new RegisterShipEvent(
                                  DateTime.Now,
                                  "event id",
                                  shipRef,
                                  new Port()
            {
                Id = "start port id", IntlCode = "start port", Name = "start port name"
            },
                                  "ship name",
                                  "ship code"
                                  ));
            Mock.Get(shipQuery).Setup(s => s.UseRegCode("ship code")).Returns(shipQuery).Verifiable();
            Mock.Get(shipQuery).Setup(s => s.ExecuteAsync())
            .Returns(Task.FromResult(ship));

            var sp = TestBed.Create <TrackingService>(MockBehavior.Strict, (sc) => {
                sc.AddSingleton <ISingleQueryPortByIntCode>(portQuery);
                sc.AddSingleton <ISingleQueryShipByRegCode>(shipQuery);
            });

            Mock.Get(sp.GetRequiredService <IQueueService>())
            .Setup(s => s.AddEvent <DomainEvent>(It.IsAny <ArriveEvent>()))
            .Callback((DomainEvent de) =>
            {
                Assert.NotNull(de);

                var ae = de as ArriveEvent;
                Assert.NotNull(de);

                Assert.Equal(shipRef, ae.Ship);
                Assert.Equal("port id", ae.Port.Id);
                Assert.Equal("port code", ae.Port.IntlCode);
            })
            .Returns(Task.CompletedTask);

            Mock.Get(sp.GetRequiredService <IReferenceService <Ship> >())
            .Setup(s => s.GetRef(shipQuery)).Returns(shipRef);

            var srv = sp.GetService <TrackingService>();

            srv.ArrivalAsync("event id", "ship code", "port code").GetAwaiter().GetResult();
        }
        public void ProcessEvents()
        {
            var sp = TestBed.Create <QueueService>(MockBehavior.Loose);

            var srv = sp.GetService <QueueService>();

            var @e1 = new MyDomainEvent("1");
            var @e2 = new MyDomainEvent("2");

            Task.Run(async() =>
            {
                await srv.AddEvent(@e1);
                await Task.Delay(100);
                await srv.AddEvent(@e2);
            }).Wait();

            Assert.True(@e1.Processed);
            Assert.Equal("1", @e1.Id);

            Assert.True(@e2.Processed);
            Assert.Equal("2", @e2.Id);
        }
示例#3
0
 public static void ClassInitialize(TestContext context)
 {
     testBed = TestBed.Create <IdenticonTests>(context);
 }
示例#4
0
        public void Test()
        {
            using (var testBed = TestBed.Create <RendererTests>(TestContext))
            {
                var bitmap = new Bitmap(100, 100);

                // Diamond background, should be clipped to viewport
                bitmap.FillPolygon(Color.FromArgb(30, 0, 0, 255), new PointF[]
                {
                    new PointF(10, 10),
                    new PointF(10, 90),
                    new PointF(90, 90),
                    new PointF(90, 10),
                    new PointF(10, 10)
                });

                // Entirely contained rectangle
                bitmap.FillPolygon(Color.FromArgb(230, 40, 40, 40), new PointF[]
                {
                    new PointF(50, -15),
                    new PointF(115, 50),
                    new PointF(50, 115),
                    new PointF(-15, 50)
                });

                // Center figures with holes
                bitmap.FillPath(Color.Yellow, GetDiamond(20, 30, 10));
                bitmap.FillPath(Color.FromArgb(128, 0, 0, 255), GetDiamond(40, 30, 10));

                // The following shapes should not be rendered.
                bitmap.FillPolygon(Color.Red, new PointF[]
                {
                    new PointF(-10, -15),
                    new PointF(-5, -10),
                    new PointF(0, 110),
                    new PointF(-15, 115)
                });

                bitmap.FillPolygon(Color.Red, new PointF[]
                {
                    new PointF(115, -15),
                    new PointF(120, -10),
                    new PointF(120, 110),
                    new PointF(115, 115)
                });

                var surrounding = new Drawing.Path();
                surrounding.AddPolygon(new PointF[]
                {
                    new PointF(-20, -20),
                    new PointF(-20, 120),
                    new PointF(120, 120),
                    new PointF(120, -20)
                });

                // Hole
                surrounding.AddPolygon(new PointF[]
                {
                    new PointF(-10, -10),
                    new PointF(110, -10),
                    new PointF(110, 110),
                    new PointF(-10, 110),
                });

                // Black with antialiasing.
                // Used to ensure there are no rounding errors.
                bitmap.FillPolygon(Color.Black, new PointF[] {
                    new PointF(5, 5),
                    new PointF(15, 5),
                    new PointF(25, 25),
                    new PointF(15, 25)
                });
                bitmap.FillPolygon(Color.Black, new PointF[] {
                    new PointF(15, 5),
                    new PointF(25, 5),
                    new PointF(15, 25),
                    new PointF(5, 25)
                });

                // White with antialiasing.
                // Used to ensure there are no rounding errors.
                bitmap.FillPolygon(Color.White, new PointF[] {
                    new PointF(5, 75),
                    new PointF(15, 75),
                    new PointF(25, 95),
                    new PointF(15, 95)
                });
                bitmap.FillPolygon(Color.White, new PointF[] {
                    new PointF(15, 75),
                    new PointF(25, 75),
                    new PointF(15, 95),
                    new PointF(5, 95)
                });

                using (var stream = new MemoryStream())
                {
                    bitmap.SaveAsPng(stream);
                    stream.Position = 0;
                    testBed.AssertEqual(stream, "render.png");
                }
            }
        }