Example #1
0
        public async void TestExamplePing(
            [Frozen(Matching.ImplementedInterfaces)] PingRepository pingRepo,
            PingModel dummyPing,
            PingController sut)
        {
            SetupExpectedPingInDatabase(dummyPing.Ping);
            // because Gen with test connection is used, a config with the connection string
            // will be injected into the controller making it "live"
            var actual = await sut.Ping(dummyPing).Unwrap <PongModel>();

            Assert.Equal(dummyPing.Ping, actual.Pong);
        }
Example #2
0
        public void Index()
        {
            // Arrange
            PingController controller = new PingController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Home Page", result.ViewBag.Title);
        }
Example #3
0
        public async void CanGetPing(
            [Frozen] Mock <IReceiveAsync <PingModel, PongModel> > pingrepo,
            PingModel ping,
            PongModel pong,
            PingController sut)
        {
            pingrepo.Setup(x => x.GetDataAsync(ping)).ReturnsAsync(pong);
            var result = await sut.Ping(ping).Unwrap();

            var actual = await result.Unwrap <PongModel>();

            Assert.Equal(pong, actual);
        }
Example #4
0
        public async void CanGetPingFail(
            [Frozen] Mock <IReceiveAsync <PingModel, PongModel> > pingrepo,
            PingModel dummyPing,
            Exception expected,
            PingController sut)
        {
            pingrepo.Setup(x => x.GetDataAsync(It.IsAny <PingModel>())).ThrowsAsync(expected);
            var result = await sut.Ping(dummyPing).Unwrap();

            Assert.False(result.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
            var actual = await result.Unwrap <HttpError>();

            Assert.Equal(expected.Message, actual.Message);
        }